Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.getPeerCertificate() on https.request() #7672

Closed
mykiimike opened this issue Jul 12, 2016 · 6 comments
Closed

.getPeerCertificate() on https.request() #7672

mykiimike opened this issue Jul 12, 2016 · 6 comments
Labels
doc Issues and PRs related to the documentations. https Issues or PRs related to the https subsystem. tls Issues and PRs related to the tls subsystem.

Comments

@mykiimike
Copy link

mykiimike commented Jul 12, 2016

Hi

.getPeerCertificate() does not returned fingerprint after first https.request(). It seems to be a problem with https.agent. If i set agent to false during https.request(opts) then i got correctly the fingerprint at each time.

Here is an example:

const https = require("https");

function request() {
    var options = {
        hostname: 'www.google.com',
        port: 443,
        path: "/",
        method: 'GET',
        // turning this to True makes fingerprint works again (agent's connections are closed);
        //agent: false, 
        rejectUnauthorized: false
    };

    var req = https.request(options, (res) => {
        res.fingerprint = res.connection.getPeerCertificate().fingerprint;
        var data = '';
        res.on('data', (d) => {
            data += d;
        });
        res.on('end', () => {
            console.log("got data", res.fingerprint);
            setTimeout(request, 1000);
        });

    }).on('error', (e) => {
        console.error(e);
    });
    req.end();
}

request();
@Fishrock123 Fishrock123 added the https Issues or PRs related to the https subsystem. label Jul 12, 2016
@mykiimike
Copy link
Author

Maybe other tlsSocket fields are affected.

@bnoordhuis bnoordhuis added the tls Issues and PRs related to the tls subsystem. label Jul 12, 2016
@bnoordhuis
Copy link
Member

That is an unfortunate side effect of TLS session resumption. In your example, the first connection does a full TLS handshake but subsequent connections do an abridged version based on the previously established TLS session (which persists across connections.)

It's good for performance reasons (it cuts the number of TCP round-trips in half) but it loses the TLS connection metadata.

The reason it works as you expect it to with { agent: false } is that it creates a new session for every connection.

@mykiimike
Copy link
Author

mykiimike commented Jul 12, 2016

Thanks,

It depends the way you want to provide the application's subsystem. It doesn't really matter to me but the question is: is it a normal behaviour for a normal guy I would say :)
Actually the agent is something transparent (almost opaque) for the famous normal guy, no?

Cheers
Michael

@bnoordhuis bnoordhuis added the doc Issues and PRs related to the documentations. label Jul 12, 2016
@bnoordhuis
Copy link
Member

cc @nodejs/documentation - the documentation for getPeerCertificate() and the HTTPS agent should clarify that resumed sessions lack the peer's certificate info.

@mykiimike You're welcome to submit a PR too, of course. :-)

@mykiimike
Copy link
Author

I will try to find some free time to do it 👍

@Trott
Copy link
Member

Trott commented Jul 8, 2017

A PR would be welcome.

This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. https Issues or PRs related to the https subsystem. tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants