Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

281
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda