Skip to content

getPeerCertificate() only works once on the same host #3940

Closed
@f0zi

Description

@f0zi

Requesting from the same host twice using https will only return the certificate on the first connection.

var req = https.request(url);
req.once('socket', function(socket) {
    socket.once('secureConnect', function() {
        var cert = socket.getPeerCertificate(); // detailed or not does not seem to matter
        // cert is ok the first time, empty the second time.
    });
});

I would expect to get back the cert every time even if the connection is reused.

I'm caching it now but it's a bad workaround as other code could be using https.request to connect to the same host without using the cache which means that my code will never see the cert.

Also caching the cert means I'm relying on the assumption that the fact that I did not get a cert this time means the cert in my cache still applies and is valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpsIssues or PRs related to the https subsystem.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions