-
-
Save rphillips/cec93f314e9418e63ffb to your computer and use it in GitHub Desktop.
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.connect = function(options, callback) | |
local defaults, hostname, context, conn, cleartext, tlsChain, tls | |
local port, onConnect | |
-- Setup options | |
defaults = { | |
ciphers = DEFAULT_CIPHERS, | |
rejectUnauthorized = false, | |
-- TODO checkServerIdentity | |
} | |
options = extend(defaults, options or {}) | |
hostname = options.servername or options.host or | |
(options.socket and options.socket._host) | |
port = options.port | |
cleartext = Emitter:new() | |
tls = tlsCodec(options) | |
tlsChain = chain(tls.decoder, codec.wrapEmitter(cleartext), tls.encoder) | |
function onConnect() | |
local read, write = wrapStream(conn._handle) | |
tls.emitter:on('secureConnect', callback) | |
tlsChain(read, write) | |
end | |
conn = net.create(port, hostname, onConnect) | |
cleartext._socket = conn | |
cleartext._tls = tls | |
return cleartext | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment