const tls = require(
'tls'
),
fs = require(
'fs'
),
PORT = 1337,
HOST =
'127.0.0.1'
;
const options = {
key: fs.readFileSync(
'private-key.pem'
),
cert: fs.readFileSync(
'public-cert.pem'
),
rejectUnauthorized:
false
};
const server = tls.createServer(options,
function
(socket) {
socket.on(
'data'
,
function
(data) {
console.log(
'\nReceived: %s '
,
data.toString().replace(/(\n)/gm,
""
));
});
server.close();
});
const value1 = server.getTicketKeys();
console.log(
"old Session key : "
)
console.log(value1)
const buf = Buffer.from([
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,]);
server.setTicketKeys(buf)
const value1 = server.getTicketKeys();
console.log(
"new Session key : "
)
console.log(value1)
server.on(
'close'
, () => {
console.log(
"Server closed successfully"
);
})
server.listen(PORT, HOST,
function
() {
console.log(
"I'm listening at %s, "
+
"on port %s"
, HOST, PORT);
});
const client = tls.connect(PORT,
HOST, options,
function
() {
const value = client.address();
client.write(
"Bound address : "
+ value)
client.end();
});