Created
April 20, 2017 22:36
-
-
Save murgatroid99/a6f4b3f85c5a8d1acdbdceedc3263df7 to your computer and use it in GitHub Desktop.
Proposed node-pre-gyp plugin for checking ALPN compatibility in Node
This file contains 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
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