Last active
August 29, 2015 13:57
-
-
Save D1plo1d/9655724 to your computer and use it in GitHub Desktop.
SelfSignedHttpsAgent
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
tls = require "tls" | |
https = require "https" | |
http = require "http" | |
net = require "net" | |
_ = require "lodash" | |
# This HTTPS Agent allows us to verify a server's self-signed cert before | |
# accepting the connection via a "cert" event that is emitted when the cert | |
# is received. | |
module.exports = class SelfSignedHttpsAgent extends https.Agent | |
constructor: (options = {}) -> | |
super(_.merge options, rejectUnauthorized: false) | |
# Preventing super from overriding functions | |
@createConnection = SelfSignedHttpsAgent.prototype.createConnection | |
@getName = SelfSignedHttpsAgent.prototype.getName | |
createConnection: (port, host, options) -> | |
cleartextStream = tls.connect(port, host, options) | |
# console.log cleartextStream.socket | |
cb = _.partial @_validatePeerCertificate, cleartextStream | |
cleartextStream.on("secureConnect", cb) | |
getName: -> | |
"#{agentProto.getName}:tegh" | |
_validatePeerCertificate: (cleartextStream) -> | |
cert = cleartextStream.getPeerCertificate() | |
@emit("cert", cert) | |
console.log "cert!" | |
# console.log cert | |
# throw "wut" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment