Skip to content

Instantly share code, notes, and snippets.

View stevenharradine's full-sized avatar

Steven Harradine stevenharradine

View GitHub Profile
@stevenharradine
stevenharradine / node-tls-detect.js
Last active September 11, 2015 14:01 — forked from tg-x/node-tls-detect.js
TLS detection for node.js
/*
* Autodetect if SSL/TLS is used by having a look at the first incoming bytes
* This technique is from http://webview.jabberd.org/cgi-bin/viewvc.cgi/trunk/jadc2s/clients.cc?view=markup
*
* used heuristic:
* - an incoming connection using SSLv3/TLSv1 records should start with 0x16
* - an incoming connection using SSLv2 records should start with the record size
* and as the first record should not be very big we can expect 0x80 or 0x00 (the MSB is a flag)
* - everything else is considered to be unencrypted
*/