サーバ側

var https = require(‘https’);

var fs = require(‘fs’);
var ssl_server_crt = ‘/etc/pki/CA/certs/せrヴぇr-ca.crt’;
var ssl_server_key = ‘/etc/pki/CA/private/せrヴぇr.key’;
var ssl_ca_crt = ‘/etc/pki/CA/cacert.pem’;
var port = 443;

var options = {
key: fs.readFileSync(ssl_server_key),
cert: fs.readFileSync(ssl_server_crt),
ca: [fs.readFileSync(ssl_ca_crt)],
requestCert: true,
rejectUnauthorized : true,
};

var servers = https.createServer(options, function (req,res) {
fs.createReadStream(“index.html”).pipe(res);
}).listen(port);

var wss = new WebSocketServer({server:servers});

 

クライアント側

var fs = require(‘fs’);
var https = require(‘https’);
var WebSocket = require(‘ws’);

var ssl_client_crt = ‘/etc/pki/CA/client/certs/client.crt’;
var ssl_client_key = ‘/etc/pki/CA/client/private/client.key’;
var ssl_ca_crt = ‘/etc/pki/CA/cacert.pem’;
var ssl_client_pfx = ‘/etc/pki/CA/client/private/client.pfx’;

var options = {
ca : fs.readFileSync(ssl_ca_crt),
agent: false,

// key&certの指定
key : fs.readFileSync(ssl_client_key),
cert : fs.readFileSync(ssl_client_crt),
passphrase : ‘xxxxx’,

// 又は、pfxの指定
// passphrase : ‘xxxx’,
// pfx : fs.readFileSync(ssl_client_pfx),
};

var ws = new WebSocket(‘wss://xxxxx:443/’, null, options);