OCSPResponse Event is not triggered with tls.connect even though requestOCSP is set

52 Views Asked by At

By referring to the Nodejs TLS document https://nodejs.org/api/tls.html#event-ocspresponse to get the OCSP status of a certification , we should expect OCSPResponse event when requestOCSP is set to true

I'm encountering an issue where the OCSPResponse event never gets triggered using the provided codes. I'm unsure what might be missing. Appreciate your assistance. Thank you

const tls = require('tls'),
    PORT = 443,
    HOST = 'google.com'

const options = {
    rejectUnauthorized: true,
    secureProtocol: 'TLSv1_2_method',
    servername: HOST,
    secure: true,
   // enableTrace: true,
    requestOCSP: true,
};

const client = tls.connect(PORT, HOST, options, function () {
    if (client.authorized) {
        console.log("Connection authorized by a Certificate Authority.");
    } 
    let certificate = client.getPeerCertificate(true);
    console.log("---------------")
    client.on("OCSPResponse", function(data) {
        console.log(data.toString())
    });
    client.on("data", function (data) {
        console.log('Received: %s',data.toString().replace(/(\n)/gm, ""));
    });
    client.end(() => {
        console.log("Client closed successfully");
    });
});

I tried different node version, but it did not help.

0

There are 0 best solutions below