Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda