Created
June 29, 2012 20:22
-
-
Save jfromaniello/3020420 to your computer and use it in GitHub Desktop.
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 https = require('https'), | |
path = require("path"), | |
fs = require("fs"), | |
crypto = require("crypto"); | |
function getCredentialsContext(cer){ | |
var r = crypto.createCredentials({ | |
key: fs.readFileSync(path.join(__dirname, 'certs', cer + '.nopass.key')), | |
cert: fs.readFileSync(path.join(__dirname, 'certs', cer + '.crt')) | |
}).context; | |
r.name = cer; | |
return r; | |
} | |
var certs = { | |
"foobarbaz.com": getCredentialsContext("cer1"), | |
"default": getCredentialsContext("cer2") | |
}; | |
var options = { | |
SNICallback: function(hostname){ | |
var cert = certs[hostname] || certs["default"]; | |
console.log("using:", cert.name, "for:", hostname); | |
return cert; | |
} | |
}; | |
https.createServer(options, function (req, res) { | |
res.writeHead(200); | |
res.end("hello world\n"); | |
}).listen(8002); | |
console.log("listening on 8002"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment