Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
Get TLS session keys with NodeJS

I have a server and client application written in NodeJS that communicate to each other via TLS, with self-signed certificates. Certificates are not validated with a CA; instead, the user has access to both interfaces at once and will manually verify the authenticity of the server and client using a verification code calculated on both applications using the TLS server write key and client write key.

Are these keys stored even after the handshake is completed? How can I access these keys from a NodeJS TLS socket on the client side? I'm using the native https library.

Server code:

const options = {
    key: fs.readFileSync('./server.key'),
    cert: fs.readFileSync('./server.crt'),
    enableTrace: true,
    requestCert: true,
    rejectUnauthorized: false,
};
const server = https.createServer(options, app);
this.initWithServer(server);
server.on('secureConnection', (soc) => {
    console.log(server.getTicketKeys());
});

Client code:

const requestOptions = {
    hostname: HOST,
    port: PORT,
    path: '/',
    method: 'GET',
    rejectUnauthorized: false,
    requestCert: true,
    key: fs.readFileSync('./client.key'),
    cert: fs.readFileSync('./client.crt'),
};
requestOptions.agent = new https.Agent(requestOptions);
const req = https.request(requestOptions, (res) => {
    res.setEncoding('utf8');
    let data = '';
    res.on('data', (resBody) => {
        data += resBody;
    });
    res.on('end', () => {
        const body = JSON.parse(data);
    });
});
req.end();

req.on('socket', (socket) => {
    socket.on('secureConnect', () => {
        const peerCertificate = socket.getPeerCertificate(true);
        console.log(peerCertificate.pubkey);
        const localCertificate = socket.getCertificate(true);
        console.log(localCertificate.pubkey);
        console.log(socket.getSession())
    });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!