-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
45 lines (37 loc) · 1005 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var http = require('http');
var tls = require('tls');
var crypto = require('crypto');
var fs = require('fs');
var key = fs.readFileSync('./server.key');
var cert = fs.readFileSync('./server.crt');
// make a request
var options = {
port: 80,
host: 'jeansebtr.upgrade.jit.su',
headers: {
'Connection': 'Upgrade',
'Upgrade': 'websocket'
}
};
var req = http.request(options);
req.end();
req.on('upgrade', function(res, socket, upgradeHead) {
console.log('got upgraded!');
var pair = tls.createSecurePair(crypto.createCredentials({
key: key,
cert: cert
}), false, false);
// ...
socket.pipe(pair.encrypted);
pair.encrypted.pipe(socket);
pair.cleartext.pipe(process.stdout);
process.stdin.pipe(pair.cleartext);
process.stdin.resume();
pair.on('secure', function() {
console.log('-> Dude that works!');
});
});
req.on('error', function(err) {
console.error('WTF:', err);
console.error(err.stack);
});