Answer the question
In order to leave comments, you need to log in
Error connecting WS client to server via HTTPS?
In general, a node throws this error when a client connects to a server:
Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE
at SecurePair. (tls.js:1283:32)
at SecurePair.EventEmitter.emit (events.js:92:17)
at SecurePair.maybeInitFinished (tls.js:896:10)
at CleartextStream.read [as _read] (tls.js: 430:15)
at CleartextStream.Readable.read (_stream_readable.js:294:10)
at EncryptedStream.write [as _write] (tls.js:344:25)
at doWrite (_stream_writable.js:211:10)
at writeOrBuffer ( _stream_writable.js:201:5)
at EncryptedStream.Writable.write (_stream_writable.js:172:11)
at write (_stream_readable.js:547:24)
os: win7
node: 0.10.2
On the 8th node, everything works without problems, but there is no way to switch to the 8th node. free certificates issued by comodo.
Here are the listings, if necessary (more precisely, these are just examples from the documentation, I just indicated the path to the root certificates)
Server:
(function(){<br>
<br>
"use strict";<br>
<br>
var fs = require('fs');<br>
<br>
// you'll probably load configuration from config<br>
var cfg = {<br>
ssl: true,<br>
port: 8080,<br>
ssl_key: 'crt/server1.key',<br>
ssl_cert: 'crt/server1.crt'<br>
};<br>
<br>
var httpServ = require('https') <br>
var cas = [fs.readFileSync('crt/COMODOHigh-AssuranceSecureServerCA.crt'), <br>
fs.readFileSync('crt/AddTrustExternalCARoot.crt')]<br>
httpServ.globalAgent.options.ca = cas;<br>
console.log(httpServ.globalAgent.options)<br>
var WebSocketServer = require('ws').Server;<br>
<br>
var app = null;<br>
<br>
// dummy request processing<br>
var processRequest = function( req, res ) {<br>
<br>
res.writeHead(200);<br>
res.end("All glory to WebSockets!\n");<br>
};<br>
<br>
if ( cfg.ssl ) {<br>
<br>
app = httpServ.createServer({<br>
<br>
// providing server with SSL key/cert<br>
key: fs.readFileSync( cfg.ssl_key ),<br>
cert: fs.readFileSync( cfg.ssl_cert ),<br>
requestCert: true,<br>
rejectUnauthorized: false<br>
<br>
}, processRequest ).listen( cfg.port );<br>
<br>
} else {<br>
<br>
app = httpServ.createServer( processRequest ).listen( cfg.port );<br>
}<br>
<br>
// passing or reference to web server so WS would knew port and SSL capabilities<br>
var wss = new WebSocketServer( { server: app } );<br>
<br>
wss.on( 'connection', function ( wsConnect ) {<br>
<br>
wsConnect.on( 'message', function ( message ) {<br>
<br>
console.log( message );<br>
<br>
});<br>
<br>
});<br>
<br>
}());<br>
var WebSocket = require('ws');<br>
var ws = new WebSocket('wss://localhost:8080');<br>
ws.on('open', function() {<br>
ws.send('something');<br>
});<br>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question