How to setup secure tunnel to allow a client to communicate to a websocket? - ssl

I need to allow client to connect to a websocket on server 10.0.4.160. The 10.0.4.160 server does not have SSL installed on it but it have a websocket that is running on port 8080.
I need to setup a secure tunnel to allow the client to connect to the websocket.
I installed the stunnel on my windows Server 2008 R2, And changed my stunnel.conf file to look loke this
[websockets]
accept = 8443
connect = 8080
verify = 2
CAfile = ca-certs.pem
client = yes
I am expecting to connect to the server on port 8433 and the stunnel will allow the connection to connect to port 8080
This is the code that I use in the client's console "Of course, the console is on a PC that is on my internal network"
var conn = new WebSocket('wss://10.0.4.160:8443');
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
console.log(e.data);
};
While on the server I open up a command line and I execute this
telnet localhost 8080
I get a command line and when I fire the code above from a console I see this in the server's command line
But few seconds later I get this error in the console
WebSocket connection to 'wss://10.0.4.160:8443/' failed: Error in connection establishment: net::ERR_TIMED_OUT
If I try to send a command using conn.sent('Hello') I get this error
VM289:2 Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
at Error (native)
at <anonymous>:2:6
at Object.InjectedScript._evaluateOn (<anonymous>:905:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)
at Object.InjectedScript.evaluate (<anonymous>:694:21)
Additionally, I tried to turn on debugging in strunnel by adding debug = 7
This is what I got in the stunnel console. I don't understand what is wrong as the logs show that the client is connected but I can't send messages from the client to the server
2015.08.16 16:40:06 LOG7[36]: Service [websockets] started
2015.08.16 16:40:06 LOG5[36]: Service [websockets] accepted connection from 10.0.4.195:21963
2015.08.16 16:40:06 LOG6[36]: s_connect: connecting 127.0.0.1:8080
2015.08.16 16:40:06 LOG7[36]: s_connect: s_poll_wait 127.0.0.1:8080: waiting 10 seconds
2015.08.16 16:40:06 LOG5[36]: s_connect: connected 127.0.0.1:8080
2015.08.16 16:40:06 LOG5[36]: Service [websockets] connected remote server from 127.0.0.1:50891
2015.08.16 16:40:06 LOG7[36]: Remote socket (FD=668) initialized
2015.08.16 16:40:06 LOG6[36]: SNI: sending servername: localhost
2015.08.16 16:40:06 LOG7[36]: SSL state (connect): before/connect initialization
2015.08.16 16:40:06 LOG7[36]: SSL state (connect): SSLv2/v3 write client hello A
What am I doing wrong here?
How come the connection keeps failing?

Related

I cannot connect to RabbitMQ at port 5672

I'm new to RabbitMQ and docker. I'm running a Springboot app and I have a docker container that is running the management console on 15672. I'm able to get to that in my browser just fine, but I cannot connect to RabbitMQ when I start the application using this in my yml file:
rabbitmq:
username: test
password: test
host: localhost
port: 5672
test is a user I created with admin permissions same as guest.
When I change the user/password to guest, it tries over and over to connect to 5672 and finally times out. test/test just fails fast with this error:
Rabbit health check failed
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61) ~[spring-rabbit-2.2.6.RELEASE.jar:2.2.6.RELEASE]
Any advice for a newbie would be greatly appreciated.
I'm expecting to connect to RabbitMQ using test/test on port 5672. But I must have something configured incorrectly.

Start a WS connection on a server that's being accessed by SSH port forwarding

I have an EC2 Instance(A) and a RaspberryPi(B). I want to access a HTML page in B.
Here are the steps I did:
Created a simple index.html in B that connects to a WebSocket running on 5443 also in B
Served it with SimpleHTTPServer on port 1337
Created a port forwarding. When I access A:9000 it should redirect to B:1337. Used: ssh -f -N -R 9000:127.0.0.1:1337 A
With that I'm able to access my index.html page, however it fails when trying to connect to the WebSocket server with
WebSocket connection to 'ws://localhost:5553/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
When I use VNC to connect to B, and access the browser in localhost:1337 I'm able to see the page AND the WebSocket connection succeeds.
I'm not sure why it fails when I try to access it through the EC2 instance. Does anyone have any clues on what might be the problem? thanks
**All ports are open in my EC2 instance
Even though I was port forwarding, localhost:5553 wasn't the raspberry pi IP, was the EC2. I created a new port forwarding from 9001 in A to 5443 in B to tunnel the Websocket connection and it worked.

Rabbitmq not connecting from Paho js client

Here is my paho javascript client code
client = new Paho.MQTT.Client(host, Number(port), clientId);
client.onMessageArrived = onMessageArrived;
client.onMessageDelivered = onMessageDelivered;
client.onConnectionLost = onConnectionLost;
here port 8083 works with other broker but not with Rabbitmq. In the documentation I could not found any correct port number.
Running sudo rabbitmqctl status gives
[{rabbitmq_management,"RabbitMQ Management Console","3.6.2"},
{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.6.2"},
{webmachine,"webmachine","1.10.3"},
{mochiweb,"MochiMedia Web Server","2.13.1"},
{rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.6.2"},
{listeners,[{clustering,25672,"::"},{amqp,5672,"::"},{mqtt,1883,"::"}]},
So I tried with port 1883 also. I was following https://github.com/rabbitmq/rabbitmq-web-mqtt-examples/blob/master/priv/echo.html
I getting this error:
WebSocket connection to 'ws://localhost:1883/mqtt' failed: Connection closed before receiving a handshake response
As thrashed out in the comments:
Rabbitmq requires the following plugin to support MQTT over websockets (http://github.com/rabbitmq/rabbitmq-web-mqtt)

TCP: Client sends [RST, ACK] immediately after sending [ACK] to Server

I've got nginx 1.9.7 compiled against OpenSSL 1.0.2e running on Ubuntu 14.04.3 LTS (3.13.0-71-generic x86_64). I can connect to it with a browser no problem at all, and get a secure connection.
I also have a client who is running some Windows Server and is trying to connect to using WCF. They report they aren't able to connect to my service.
My nginx error log shows:
2015/12/09 17:38:27 [info] 10750#0: *6494 recv() failed (104: Connection reset by peer) while SSL handshaking, client: {REDACTED}, server: 0.0.0.0:443
Digging deeper, a Wireshark dump shows this pattern:
Client -> Server [SYN]
Client <- Server [SYN, ACK]
Client -> Server [ACK]
Client -> Server [RST, ACK] (connection closes)
Sniffing a successful request shows:
Client -> Server [SYN]
Client <- Server [SYN, ACK]
Client -> Server [ACK]
Client -> Server [PSH, ACK] (sends SSL Client Hello)
I'm not really a TCP guy, so I'm a little out of my depth in understanding what could be happening here. Any advice would be appreciated.
Turns out that the problem was the client's firewall :(
Edited to add detail: the client's firewall had been configured to block the domain and was therefore dropping the TCP connection as soon as it was established. Once the block was cleared, the issue went away.

EasyNetQ fails to publish to RabbitMQ - PersistentChannel timed out

I am trying to connect to RabbitMQ with EasyNetQ.
RabbitMQ is on remote VM.
_rabbitBus = RabbitHutch.CreateBus(
string.Format("host={0};virtualhost={1}",
_hostSettings.Host, _hostSettings.VHost),
x => x.Register<IEasyNetQLogger>(l => _logger));
_rabbitBus.Subscribe<Message>(_topic, ReceiveMessage, m => m.WithTopic(_topic));
I get a TimeoutException The operation requested on PersistentChannel timed out..
Remote VM is replying to pings, ports 5672 and 15672 are opened (checked with nmap).
RabbitMQ management can be accessed from my host.
Also, if RabbitMQ is run on my local machine, it works fine.
I've tried connecting to RabbitMQ installed on my computer from other pc's in LAN, and it also works.
I've come to an assumption, that it's related to the fact it's on a virtual machine, and maybe there's something wrong in connection. But again, Rabbit's web management works fine.
Also tested on EasyNetQ Test application - works on localhost, but not on remote.
Output as following:
DEBUG: Trying to connect
ERROR: Failed to connect to Broker: '192.168.0.13', Port: 5672 VHost: '/'.
ExceptionMessage: 'None of the specified endpoints were reachable'
ERROR: Failed to connected to any Broker. Retrying in 5000 ms
EasyNetQ v0.28.4.242
As Mike suggested i had this and then checked the permissions. "guest" user can only connect via localhost (see RabbitMQ Access Control.) Try adding a user with permissions using the management interface and then connect as below
var _bus = RabbitHutch.CreateBus(string.Format("host={0};virtualhost={1};username={2};password={3}",
_hostSettings.Host, _hostSettings.VHost, _hostSettings.UserName, _hostSettings.Password));
Did you check your credentials. The default username and password is 'guest' and 'guest'. The error message is not very helpful. You get 'None of the specified endpoints were reachable' if there's an authentication error as well