Skip to content

Instantly share code, notes, and snippets.

@tg-x
tg-x / node-tls-detect.js
Created February 20, 2011 02:48
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
*/