|
2 | 2 |
|
3 | 3 | > _Part of [HTTP Toolkit](https://httptoolkit.tech): powerful tools for building, testing & debugging HTTP(S)_
|
4 | 4 |
|
5 |
| -A pure-JS module to read TLS fingerprints from an incoming socket connection. Using this, you can recognize certain TLS clients - e.g. specific browser, cURL, or even the specific versions of a specific programming language a client is using - regardless of the content of the request they send. |
| 5 | +A tiny pure-JS module to read TLS fingerprints from an incoming socket connection. |
| 6 | + |
| 7 | +Using this, you can recognize certain TLS clients - e.g. specific browser, cURL, or even the specific versions of a specific programming language a client is using - regardless of the content of the request they send. |
| 8 | + |
| 9 | +## Docs |
| 10 | + |
| 11 | +The easiest way to use this is with the exported `enableFingerprinting` helper, which can be applied to any `tls.TLSServer` instance, including `https.Server` instances, like so: |
| 12 | + |
| 13 | +```javascript |
| 14 | +const https = require('https'); |
| 15 | +const { enableFingerprinting } = require('read-tls-fingerprint'); |
| 16 | + |
| 17 | +const server = new https.Server({ /* your TLS options etc */ }); |
| 18 | + |
| 19 | +enableFingerprinting(server); |
| 20 | + |
| 21 | +server.on('request', (request, response) => { |
| 22 | + // In your normal request handler, check `tlsFingerprint` on the request's socket: |
| 23 | + console.log('Received request with fingerprint:', request.socket.tlsFingerprint); |
| 24 | +}); |
| 25 | +``` |
| 26 | + |
| 27 | +The `tlsFingerprint` property contains two fields: |
| 28 | + |
| 29 | +* `ja3` - The JA3 hash for the incoming request, e.g. `cd08e31494f9531f560d64c695473da9` |
| 30 | +* `data` - The raw data components used to calculate the hash, as an array: |
| 31 | + 1. The TLS version number as a Uint16 (771 for TLS 1.2+) |
| 32 | + 2. An array of cipher ids (excluding GREASE) |
| 33 | + 3. An array of extension ids (excluding GREASE) |
| 34 | + 4. An array of supported group ids (excluding GREASE) |
| 35 | + 5. An array of supported elliptic curve ids |
| 36 | + |
| 37 | +It is also possible to calculate TLS fingerprints manually. The module exports a few methods for this: |
| 38 | + |
| 39 | +* `getTlsFingerprintData(stream)` - Reads from a stream of incoming TLS client data, returning a promise for the raw fingerprint data, and unshifting the data back into the stream when it's done. Nothing else should attempt to read from the stream until the returned promise resolves (i.e. don't start TLS negotiation until this completes). |
| 40 | +* `getTlsFingerprintAsJa3` - Reads from a stream like `getTlsFingerprintData` but returns a promise for the JA3 hash, instead of raw data. |
| 41 | +* `calculateJa3FromFingerprintData(data)` - Takes raw TLS fingerprint data, and returns the corresponding JA3 hash. |
0 commit comments