-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (40 loc) · 1.27 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express')
const app = express()
const stringifyObject = require('stringify-object')
const https = require('https')
const fs = require('fs')
const port = 443
const crypto = require("crypto");
const writeObject = (res, object) => {
strObject = stringifyObject(object, {
indent: ' ',
singleQuotes: false
})
console.debug(strObject)
res.write('<pre>' + strObject + '</pre>')
}
app.get("/", (req, res) => {
const id = crypto.randomBytes(16).toString("hex");
console.debug('--- start ' + id + ' ---')
res.setHeader('Content-Type', 'text/html')
res.write('debug-https')
writeObject(res, req.httpVersion)
writeObject(res, req.method)
writeObject(res, req.url)
writeObject(res, req.rawHeaders)
peerCertificate = req.socket.getPeerCertificate()
if (Object.keys(peerCertificate).length > 0) {
peerCertificate.raw = 'removed'
peerCertificate.pubkey = 'removed'
writeObject(res, peerCertificate)
}
res.end()
console.debug('--- end ' + id + ' ---')
})
server = https.createServer({
key: fs.readFileSync(process.env.KEYFILE),
cert: fs.readFileSync(process.env.CERTFILE),
requestCert: true, // Request client certificate
rejectUnauthorized: false // Ingore if no client certificate is present
}, app)
server.listen(port)