I created a PHP websocket using Ratchet. This Websocket is running on port 8080
of my internal server 10.0.4.160
.
I am trying to connect to it from a website that have SSL enabled "aka using https protocol."
When attempting to connect to the websocket form a FireFox browser, I get security issues from the browser because I am mixing between secured/non-secured connection. This is the error that I see in the javascript's console.
SecurityError: The operation is insecure.
To fix the security issue I created a stunnel proxy which allows me to accept the connection on 10.0.4.160:58443
and connect it to port 127.0.0.1:8080
. This secure tunnel should allow me to keep my connection to the websocket secured and bypass the browser's security check.
However, every time I attempt to connect to the websocket I get an error
WebSocket connection to 'wss://10.0.4.160:58443/' failed: Error in connection establishment: net::ERR_TIMED_OUT
This is the jQuery script that is used to connect to the websocket
<script>
$(function(){
if ("WebSocket" in window)
{
var conn = new WebSocket('wss://10.0.4.160:58443');
conn.onopen = function(e) {
console.log("Connection established!");
showMessage('Connected', 0);
};
conn.onmessage = function(e) {
console.log(e.data);
showMessage(e.data, 1);
};
conn.onclose = function(e) {
console.log(e.code);
console.log(e.reason);
};
conn.onerror = function(e) {
console.log(e);
};
} else {
console.log('Your browser does not support Websocket!');
}
function showMessage(msg, append){
if(append){
$('#status').append('<br>' + msg);
return;
}
$('#status').text(msg);
}
});
</script>
Here is my current stunnel configuration
[websockets]
client = yes
accept = 58443
connect = 8080
verify = 2
CAfile = ca-certs.pem
debug = 7
OCSPaia = yes
How can I connect to the websocket from my browser? Thank you