tunnelmate 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -2
- package/dist/bin/tunnelme.js +182 -0
- package/dist/src/certStore.js +199 -0
- package/dist/src/client.js +123 -0
- package/dist/src/config.js +66 -0
- package/dist/src/firewall.js +41 -0
- package/dist/src/network.js +154 -0
- package/dist/src/server.js +258 -0
- package/dist/src/types.js +2 -0
- package/dist/src/util.js +103 -0
- package/package.json +18 -4
- package/bin/tunnelme.js +0 -108
- package/src/certStore.js +0 -185
- package/src/client.js +0 -107
- package/src/config.js +0 -37
- package/src/server.js +0 -240
- package/src/util.js +0 -71
package/src/util.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const crypto = require('crypto');
|
|
4
|
-
|
|
5
|
-
function log(...args) {
|
|
6
|
-
console.log(new Date().toISOString(), ...args);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Formats an Error for logging, unwrapping AggregateError (whose own .message is often empty). */
|
|
10
|
-
function describeError(err) {
|
|
11
|
-
if (!err) return String(err);
|
|
12
|
-
if (Array.isArray(err.errors) && err.errors.length > 0) {
|
|
13
|
-
return err.errors.map((e) => e.message || String(e)).join('; ');
|
|
14
|
-
}
|
|
15
|
-
return err.message || err.code || String(err);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Constant-time string comparison, safe for comparing against a network-supplied secret. */
|
|
19
|
-
function secureCompare(a, b) {
|
|
20
|
-
const ha = crypto.createHash('sha256').update(String(a)).digest();
|
|
21
|
-
const hb = crypto.createHash('sha256').update(String(b)).digest();
|
|
22
|
-
return crypto.timingSafeEqual(ha, hb);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Bidirectionally pipes two duplex streams and destroys both if either errors or closes. */
|
|
26
|
-
function pipeBidirectional(a, b) {
|
|
27
|
-
a.pipe(b);
|
|
28
|
-
b.pipe(a);
|
|
29
|
-
|
|
30
|
-
let cleaned = false;
|
|
31
|
-
const cleanup = () => {
|
|
32
|
-
if (cleaned) return;
|
|
33
|
-
cleaned = true;
|
|
34
|
-
a.destroy();
|
|
35
|
-
b.destroy();
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
a.on('error', cleanup);
|
|
39
|
-
b.on('error', cleanup);
|
|
40
|
-
a.on('close', cleanup);
|
|
41
|
-
b.on('close', cleanup);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const REQUEST_LINE_RE = /^([A-Z]+) (\S+) HTTP\/\d\.\d$/;
|
|
45
|
-
const MAX_LEFTOVER_BYTES = 8192;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Passively taps a socket carrying raw HTTP bytes and logs each request line
|
|
49
|
-
* it spots (method + path), without consuming or altering the stream --
|
|
50
|
-
* safe to use alongside a .pipe() of the same socket. Best-effort: after a
|
|
51
|
-
* protocol upgrade (e.g. WebSocket) traffic is no longer HTTP and simply
|
|
52
|
-
* won't match, so logging naturally goes quiet for that connection.
|
|
53
|
-
*/
|
|
54
|
-
function logRequestLines(socket, label) {
|
|
55
|
-
let leftover = '';
|
|
56
|
-
socket.on('data', (chunk) => {
|
|
57
|
-
leftover += chunk.toString('latin1');
|
|
58
|
-
let idx;
|
|
59
|
-
while ((idx = leftover.indexOf('\r\n')) !== -1) {
|
|
60
|
-
const line = leftover.slice(0, idx);
|
|
61
|
-
leftover = leftover.slice(idx + 2);
|
|
62
|
-
const match = REQUEST_LINE_RE.exec(line);
|
|
63
|
-
if (match) log(`${label} ${match[1]} ${match[2]}`);
|
|
64
|
-
}
|
|
65
|
-
if (leftover.length > MAX_LEFTOVER_BYTES) {
|
|
66
|
-
leftover = leftover.slice(-1024);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = { log, secureCompare, pipeBidirectional, describeError, logRequestLines };
|