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

General improvements to HTTPS API #1255

Merged
merged 39 commits into from May 27, 2020
Merged

General improvements to HTTPS API #1255

merged 39 commits into from May 27, 2020

Conversation

Giotino
Copy link
Collaborator

@Giotino Giotino commented May 12, 2020

Checklist

  • I have read the documentation.
  • I have included a pull request description of my changes.
  • I have included some tests.
  • If it's a new feature, I have included documentation updates.

Fixes #1254

checkServerIdentity signature:

(hostname: string, certificate: PeerCertificate) => Error | undefined

According to DefinitelyTyped certificate is PeerCertificate, but after testing I discovered that certificate has the property issuerCertificate that's mean it's DetailedPeerCertificate

I can't find any documentation about using this property with https.Request on Node.JS, I think this is a side effect of the implementation of https.Request. But, on the Node.JS documentation there's an example using it "Example pinning on certificate fingerprint, or the public key (similar to pin-sha256)"

Node.JS even have a test about it:
https://github.com/nodejs/node/blob/8b4af64f50c5e41ce0155716f294c24ccdecad03/test/parallel/test-https-client-checkServerIdentity.js

@Giotino
Copy link
Collaborator Author

Giotino commented May 12, 2020

With this PR I also wanted to add the documentation described in #1191

@Giotino
Copy link
Collaborator Author

Giotino commented May 12, 2020

2 out of the 3 current HTTPS test are broken, the first 2 make plain HTTP requests.

You should have used got.secure instead of got

@szmarczak
Copy link
Collaborator

szmarczak commented May 12, 2020

2 out of the 3 current HTTPS test are broken, the first 2 make plain HTTP requests.

You should have used got.secure instead of got

Could you fix that please? 🙏

@Giotino
Copy link
Collaborator Author

Giotino commented May 12, 2020

2 out of the 3 current HTTPS test are broken, the first 2 make plain HTTP requests.
You should have used got.secure instead of got

Could you fix that please? 🙏

Yeah, I'm working on it

@Giotino
Copy link
Collaborator Author

Giotino commented May 12, 2020

I was working on a test for checkServerIdentity and i discovered that it's not called when connecting to 127.0.0.1 (and other localhost addresses)...

const tls = require('tls');

tls.connect({
  host: '127.0.0.1',
  port: 49637,
  checkServerIdentity: (hostname, certificate) => {
    // This is never called for localhost addresses
  }
})

Of course there's no documentation by Node.JS, there's only a comment in an example:

// Necessary only if the server's cert isn't for "localhost".
checkServerIdentity: () => { return null; },

I've to keep in mind this when writing the documentation, also the test need to be performed using an external service, we can use https://badssl.com/

@szmarczak
Copy link
Collaborator

Maybe there's a servername option missing? Try setting it to localhost.

@szmarczak
Copy link
Collaborator

Or maybe try setting host to localhost instead of 127.0.0.1...

@Giotino
Copy link
Collaborator Author

Giotino commented May 12, 2020

Maybe there's a servername option missing? Try setting it to localhost.
Or maybe try setting host to localhost instead of 127.0.0.1...

I've tried all of them, same result

@Giotino
Copy link
Collaborator Author

Giotino commented May 12, 2020

I made a mistake, it seems that checkServerIdentity is only called if the certificate is valid. That's why localhost was not working (I was testing without the test CA). I'm going to add some tests.

Added some HTTPS tests
Changed `PeerCertificate` to `DetailedPeerCertificate`
@Giotino Giotino changed the title Add checkServerIdentity to Options General improvements to HTTPS May 13, 2020
@Giotino
Copy link
Collaborator Author

Giotino commented May 13, 2020

While Options extends SecureContextOptions these features are not documented.

For example key, cert and ca useful for using a client certificate, or other params to tweak the TLS options.

My idea would be to add an HTTPS section to the documentation.

@szmarczak szmarczak changed the title General improvements to HTTPS General improvements to HTTPS API May 13, 2020
@szmarczak
Copy link
Collaborator

I agree.

@Giotino
Copy link
Collaborator Author

Giotino commented May 13, 2020

This is a first draft of the HTTPS documentation, there're some other parameter. The params that I've included there are the most used.

Since key, cert and passphrase are always used together I grouped the examples in a single block.

readme.md Outdated Show resolved Hide resolved
Co-authored-by: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Show resolved Hide resolved
Giotino and others added 3 commits May 13, 2020 16:14
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@Giotino
Copy link
Collaborator Author

Giotino commented May 13, 2020

@sindresorhus If you want to have different names (from the tls module) for the properties related to HTTPS I think that Options should stop extending SecureContextOptions and start defining its HTTPS properties and then translate them before the request.
I'm working on a commit with an example of that.

Giotino and others added 2 commits May 16, 2020 13:07
Co-authored-by: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
@Giotino
Copy link
Collaborator Author

Giotino commented May 16, 2020

"Deprecation Warning" tests must be serial or else they'll steal each other process events.

Co-authored-by: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
test/https.ts Outdated Show resolved Hide resolved
test/https.ts Outdated Show resolved Hide resolved
test/https.ts Outdated Show resolved Hide resolved
test/https.ts Outdated Show resolved Hide resolved
test/https.ts Outdated Show resolved Hide resolved
Giotino and others added 8 commits May 21, 2020 09:31
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@Giotino Giotino requested a review from sindresorhus May 26, 2020 17:32
@sindresorhus
Copy link
Owner

There are a few more unresolved inline comments.

Giotino and others added 6 commits May 27, 2020 17:25
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@Giotino
Copy link
Collaborator Author

Giotino commented May 27, 2020

There are a few more unresolved inline comments.

Sorry, I missed them, I was watching only the "Conversation" tab on Github.

@sindresorhus sindresorhus merged commit 697de37 into sindresorhus:master May 27, 2020
@sindresorhus
Copy link
Owner

This looks great now. Thanks for your hard work on this 🙌

@Giotino Giotino deleted the checkServerIdentity branch May 27, 2020 20:05
szmarczak added a commit to jaulz/got that referenced this pull request Jul 6, 2020
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document checkServerIdentity option
3 participants