Last active
March 3, 2018 18:19
-
-
Save legege/8087063 to your computer and use it in GitHub Desktop.
Primus.io: How to do two-way SSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var Primus = require('primus'); | |
var Socket = Primus.createSocket({ transformer: 'websockets' }); | |
var socket = new Socket('https://localhost:8443', { transport: { | |
key: fs.readFileSync('client.key'), | |
cert: fs.readFileSync('client.crt'), | |
rejectUnauthorized: false | |
} }); | |
socket.on('open', function() { | |
console.log('Cool, it works!'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var https = require('https'); | |
var express = require('express'); | |
var Primus = require('primus'); | |
var port = 8443; | |
var options = { | |
key: fs.readFileSync('localhost.key'), | |
cert: fs.readFileSync('localhost.crt'), | |
ca: fs.readFileSync('cacert.crt'), | |
crl: fs.readFileSync('ca.crl'), | |
requestCert: true, | |
rejectUnauthorized: true | |
}; | |
// HTTP Server | |
var app = express(); | |
var server = https.createServer(options, app); | |
var primus = new Primus(server, { transformer: 'websockets' }); | |
server.listen(port, function() { | |
console.log('Express now listening on port %d', port); | |
}); | |
primus.on('connection', function(spark) { | |
console.log('Primus: spark %s', spark.id, spark.remote.connection.getPeerCertificate().subject.CN); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment