Created
June 28, 2012 14:22
-
-
Save benjie/3011659 to your computer and use it in GitHub Desktop.
Commented Certificate Chain Code
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
# Require the https/fs modules | |
# Akin to Apache's configuration directive: | |
# LoadModule ssl_module libexec/libssl.so | |
# (Apache's FS module is built in, I think) | |
https = require 'https' | |
fs = require 'fs' | |
# List the certificate chain files | |
# (with Apache you might put these 4 files into 1 file, called your certificate chain) | |
files = [ | |
"EssentialSSLCA_2.crt" | |
"ComodoUTNSGCCA.crt" | |
"UTNAddTrustSGCCA.crt" | |
"AddTrustExternalCARoot.crt" | |
] | |
# Read these files (just like Apache does internally) | |
ca = (fs.readFileSync "/path/to/#{file}" for file in files) | |
# Specify the SSL configuration | |
# These are the equivalent of Apache's configuration directives: | |
# SSLCACertificateFile / SSLCertificateChainFile | |
# SSLCertificateKeyFile | |
# SSLCertificateFile | |
httpsOptions = | |
ca: ca | |
key: "/path/to/server.key" | |
cert: "/path/to/mydomain.crt" | |
# This is the thing that processes requests, i.e. this is the core of Apache. | |
requestHandler = (req, res) -> | |
res.writeHead 501 | |
res.end() | |
# This creates a new instance of the HTTPS server, and then listens on localhost:443 | |
# Akin to Apache's configuration directive: | |
# Listen 127.0.0.1:443 | |
httpsServer = https.createServer httpsOptions, requestHandler | |
httpsServer.listen 443, "localhost" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment