eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.14k stars 468 forks source link

Hostname resolution does not work in Firefox #118

Closed danielmeer closed 6 years ago

danielmeer commented 6 years ago

Hi,

I try to connect with websockets to my broker (mosquitto). This works in Chrome (and in Edge), but in Firefox I get following error:

Firefox can’t establish a connection to the server at ws://<hostname>:<pi>/ws.

Then, the onFailure callback gets called with this parameter: Object { invocationContext: undefined, errorCode: 7, errorMessage: "AMQJS0007E Socket error:undefined." }

However, it works in all 3 browsers if I change to hostname to the IP address of the broker!

This wasn't a problem for me until now, I could just use everywhere the IP address. But now I changed from ws to wss. And it is only possible to make a connection over TLS if the address/hostname is the same as in the certificate. Does anyone know why Firefox behaves differently than the rest?

jpwsutton commented 6 years ago

Hi,

What version of Firefox is this happening in? It could be a bug in that particular version, but if you let me know what it is, I'll try it myself to see if I can re-create it.

danielmeer commented 6 years ago

I use Firefox 54.0 on Linux. However, the same error occurs on Windows 10 with Firefox 55.0.3.

danielmeer commented 6 years ago

I found the problem, at least partially. It's not in the library.

On my website I use WebSockets over TLS. Deeper in the network inspection window of Firefox I found the error: "MOZILLA_PKIX_ERROR_REQUIRED_TLS_FEATURE_MISSING".

The problem is caused by a feature called "OCSP stapling", which is enabled in Firefox but not in Chrome. I don't know if the mosquitto broker supports this feature, so I disabled it in the configuration of Let's encrypt (my certificate issuer) and renewed my certificates. Here is a link with the instructions (I don't use the service). This solved the problem with WSS!

On another port I have configured WebSockets without TLS. There I get the error: "SSL_ERROR_RX_RECORD_TOO_LONG".

This is strange because I don't use SSL/TLS on this port. It may be a configuration issue of the Apache server, which is needed for certificate renewal. The Apache server listens on port 80 (http) and 443 (https). And requests on http get rewritten to https. Unfortunately, I don't have much experience in configuring the Apache server and WebSockets (WS) connect to port 9001.

danielmeer commented 6 years ago

Just as a follow-up. The second error got solved by clearing the browser cache.

This issue can be closed. Sorry for the noise.

Nogostradamus commented 6 years ago

I have the same issue with Chrome:

Mac: Version 67.0.3396.87 (Official Build) (64-bit) = ERROR Linux Ubuntu: Version 66.0.3359.139 (Official Build) (64-bit) = ERROR Windows 10: Version 67.0.3396.87 (Official Build) (64-bit) = FINE

Both Firefox and Safari works fine. Only chrome failed.