Skip to content

Instantly share code, notes, and snippets.

@murgatroid99
Created April 20, 2017 22:36
Show Gist options
  • Save murgatroid99/a6f4b3f85c5a8d1acdbdceedc3263df7 to your computer and use it in GitHub Desktop.
Save murgatroid99/a6f4b3f85c5a8d1acdbdceedc3263df7 to your computer and use it in GitHub Desktop.
Proposed node-pre-gyp plugin for checking ALPN compatibility in Node
exports.checkVersion = function(callback) {
var TEST_KEY = "-----Insert TLS private key-----";
var TEST_CERT = "------Insert TLS certificate-----";
var tls = require('tls');
var server = tls.createServer({key: TEST_KEY, cert:TEST_CERT, ALPNProtocols: ['h2']});
server.listen(0, 'localhost', function() {
var port = server.address().port;
var connect_options = {host: 'localhost',
port: port,
rejectUnauthorized: false,
ALPNProtocols: ['h2']};
var tlsSocket = tls.connect(connect_options, function() {
if (tlsSocket.alpnProtocol === 'h2') {
callback({tls: 'alpn'});
} else {
callback({tls: 'npn'});
}
tlsSocket.end();
server.close();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment