-
Notifications
You must be signed in to change notification settings - Fork 14
/
tls-server.js
32 lines (27 loc) · 949 Bytes
/
tls-server.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
#!/usr/bin/env node
'use strict';
const tls = require('tls');
const fs = require('fs');
const port = 8000;
const options = {
key: fs.readFileSync('certs/server/server.key'),
cert: fs.readFileSync('certs/server/server.crt'),
ca: fs.readFileSync('certs/ca/ca.crt'), // authority chain for the clients
requestCert: true, // ask for a client cert
//rejectUnauthorized: false, // act on unauthorized clients at the app level
};
const server = tls.createServer(options, (socket) => {
socket.write('welcome!\n');
socket.setEncoding('utf8');
socket.pipe(socket);
})
.on('connection', () => {
console.log('insecure connection');
})
.on('secureConnection', (socket) => {
// c.authorized will be true if the client cert presented validates with our CA
console.log('secure connection; client authorized: ', socket.authorized);
})
.listen(port, () => {
console.log('server listening on port ' + port + '\n');
});