创建安全 Websocket 连接时,客户端网络套接字在建立安全 TLS 连接之前已断开连接错误

Sha*_*Ali 7 ssl https websocket node.js

我正在尝试创建一个安全的 websocket 客户端和服务器。

服务器代码:

var options = { 
    key: clientKey, 
    cert: clientCert, 
    ca: caCert,
    passphrase: 'test',
    requestCert: true
}; 

var httpsServer = https.createServer(options);

var WebSocketServer = WebSocket.Server;
var wss = new WebSocketServer({
        verifyClient: (info) => {
            console.log('Request from client :'+ info.req.rawHeaders);
            console.log('Request from client auth :'+ info.req.client.authorized);
            success = !!info.req.client.authorized;
            return success;
        },
        server: httpsServer
});
Run Code Online (Sandbox Code Playgroud)

客户端代码:

const ws = new WebSocket('wss://localhost:8989/',
          'com.hp.cdm.service.ioFilter.version.1.type.filterStream', {
            cert: fs.readFileSync(path.normalize(serverCertPath)),
            key: fs.readFileSync(path.normalize(serverKeyPath)),
            ca: fs.readFileSync(path.normalize(caCert)),
            passphrase: 'test',
            rejectUnauthorized: false,
          });
Run Code Online (Sandbox Code Playgroud)

当我尝试从客户端到服务器建立连接时,出现以下错误:

{ Error: Client network socket disconnected before secure TLS connection was established
at TLSSocket.onConnectEnd (_tls_wrap.js:1086:19)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
path: undefined,
host: 'localhost',
port: '8989',
localAddress: undefined }
Run Code Online (Sandbox Code Playgroud)

我在做什么错误?是否存在 TLS 版本不匹配的情况?或者一些证书错误?