-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Something wrong with TLS connection in 5.1.{0, 1} #1505
Comments
Can you try running the following code? This is basically what ws does under the hood: const crypto = require('crypto');
const https = require('https');
const tls = require('tls');
const request = https.get({
headers: {
'Sec-WebSocket-Key': crypto.randomBytes(16).toString('base64'),
'Sec-WebSocket-Version': 13,
'Connection': 'Upgrade',
'Upgrade': 'websocket'
},
createConnection: tls.connect,
hostname: 'replace',
path: '/replace',
port: 'replace'
});
request.on('upgrade', function () {
console.log('It works.');
}); |
Also do not use 5.x. It is affected by this bug #1493 and the fix has not been backported. |
Thank you for the answer. I've tried to run the suggested code before, to understand how it works under hood (I looked thought WS source code) In WS "open" event I'm trying to send auth credential to the server. The credentials depend on access and secret key, and some signature in So in previous versions of WS after credentials sent - I'm got success auth message from server, and in 5.1.0 and above I got something like "Verification failure". I should better show you code example to reproduce – https://github.com/mokcrimea/ws-example-5-1.0 |
Can reproduce and using an agent fixes the issue: const { globalAgent } = require('https');
const ws = new WebSocket('wss://api.huobi.pro/ws/v1', { agent: globalAgent }); but I'm not sure why, I need to investigate. |
It's a bug with how the
There are two more workaround in addition to the one suggested above. The first is setting the undocumented new WebSocket('wss://api.huobi.pro/ws/v1', { defaultPort: 443 });
new WebSocket('wss://api.huobi.pro/ws/v1', {
headers: { Host: 'api.huobi.pro' }
}); |
Prevent the default port from being added to the `Host` header when no `Agent` is used. Fixes #1505
Prevent the default port from being added to the `Host` header when no `Agent` is used. Fixes #1505
Thanks a lot, This bug happen to me. server response 403 when I use 6.1.3 to connect at some machine. When I upgrade to 6.2.0, bug gone. Bug I'm very curious about why host can not include default port. And why most of machine can't reproduce this bug even host include port. |
Hello, Is there a way to provide a certificat to the ws client ? I'm using SSL/TLS with an authentification by certificat. I'm able to make it work via browser, but I'm not sure how I could do that when the connection comes from a ws client only ( not via a broswer+ws ). Thanks. |
@fas3r see https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options, you can use those options in the WebSocket constructor. |
@taoabc I guess it depends on how the Host header is handled on the server. The port is optional so it is not wrong to specify it. |
issue.
Description
Reproducible in:
Steps to reproduce:
Hello.
Trying to reproduce WS connection with some server (uncontrolled by me) and after few hours of researching I found, that this - 15bdb5f commit breaks something. I really do not know what is going wrong, just because do not have access to server.
Some details:
In 5.0.0 (or without commit mentioned above) when I send stringified JSON payload, that contains auth information - servers answers that's everything ok.
But in version with this commit - servers answers that's something went wrong (unfortunately without any details).
Tried change node versions - nothing helps.
Do you know anything about that ?
The text was updated successfully, but these errors were encountered: