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

test: add secp224k1 check in crypto-dh-stateless #31715

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Feb 10, 2020

This commit adds a check to test-crypto-dh-statless to avoid an error if
the curve secp224k1 is not present. This could occur if node was
configured with shared-openssl.

The use case for this was building on RHEL 8.1 which only has the
following curves:

$ openssl ecparam -list_curves
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Feb 10, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@danbev danbev changed the title test: add shared_openssl check crypto-dh-stateless test: add secp224k1 check in crypto-dh-stateless Feb 12, 2020
Copy link
Member

@tniessen tniessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but wouldn't it be easier to switch to a different curve that's available on all systems?

@tniessen tniessen added the crypto Issues and PRs related to the crypto subsystem. label Feb 12, 2020
@danbev
Copy link
Contributor Author

danbev commented Feb 13, 2020

LGTM, but wouldn't it be easier to switch to a different curve that's available on all systems?

I did not think about changing the curve as I thought that was something that was being tested specifically. I don't think we can know which curves will be available on all systems and they might change over time. Even ones that exist now might be removed later. I'm not saying either way is better and I'm happy as long as the test does not fail for us.

Kind of related to this is that I'm going to open an issue in the build working group suggesting we add UBI 8.1 (Universal Base Image which is based on RHEL) build to the CI system which would dynamically link to the system OpenSSL. This would allow us to test FIPS which is not done at the moment but also find issues like this one early. I'll link this issue to it.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 13, 2020
@nodejs-github-bot
Copy link
Collaborator

@tniessen
Copy link
Member

I did not think about changing the curve as I thought that was something that was being tested specifically.

The test should work as long as both curves are valid EC curves, but they must be distinct.

I don't think we can know which curves will be available on all systems and they might change over time. Even ones that exist now might be removed later.

Exactly, that's my problem: If secp224k1 is removed on one or more platforms, we don't have test coverage on those anymore, and we wouldn't know, because the test is skipped silently. But we also cannot cannot just pick any curve from crypto.getCurves(), because some might be aliases for secp256k1.

From what I can tell, OpenSSL supports at least secp224r1, secp384r1, and secp521r1, even in FIPS mode (openssl/openssl#9081). The easiest fix might be to just use secp224r1, which will likely be available everywhere, and if it isn't, we can revisit this. But if we don't want to risk limiting the test to one specific curve, something like this should also work:

const not256k1 = crypto.getCurves().find(c => /^sec.*(224|384|512)/.test(c));
assert.throws(() => {
  test(crypto.generateKeyPairSync('ec', { namedCurve: 'secp256k1' }),
       crypto.generateKeyPairSync('ec', { namedCurve: not256k1 }));
}, {
  name: 'Error',
  code: 'ERR_OSSL_EVP_DIFFERENT_PARAMETERS'
});

2 line change instead of 20 lines :)

I think it's fair to assume that any OpenSSL implementation will support at least one sec* curve that isn't 256 bits. We don't need to check if not256k1 === undefined because generateKeyPairSync will throw an error in that case.

I'm also okay with the change as it is, just not a big favor of silently skipping the check :)

@danbev
Copy link
Contributor Author

danbev commented Feb 20, 2020

@tniessen Thanks for the suggestion, I'll give that a try today.

This commit adds a check to test-crypto-dh-statless to avoid an error if
the curve secp224k1 is not present. This could occur if node was
configured with shared-openssl.

The use case for this was building on RHEL 8.1 which only has the
following curves:
$ openssl ecparam -list_curves
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field
@danbev danbev force-pushed the shared_openssl_check-test-crypto-dh-stateless branch from 9fa3759 to 47ef627 Compare February 21, 2020 06:28
@nodejs-github-bot
Copy link
Collaborator

@tniessen
Copy link
Member

Thank you!

danbev added a commit that referenced this pull request Feb 25, 2020
This commit adds a check to test-crypto-dh-statless to avoid an error if
the curve secp224k1 is not present. This could occur if node was
configured with shared-openssl.

The use case for this was building on RHEL 8.1 which only has the
following curves:
$ openssl ecparam -list_curves
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field

PR-URL: #31715
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@danbev
Copy link
Contributor Author

danbev commented Feb 25, 2020

Landed in 9403250.

@danbev danbev closed this Feb 25, 2020
@danbev danbev deleted the shared_openssl_check-test-crypto-dh-stateless branch February 25, 2020 05:21
codebytere pushed a commit that referenced this pull request Feb 27, 2020
This commit adds a check to test-crypto-dh-statless to avoid an error if
the curve secp224k1 is not present. This could occur if node was
configured with shared-openssl.

The use case for this was building on RHEL 8.1 which only has the
following curves:
$ openssl ecparam -list_curves
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field

PR-URL: #31715
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@codebytere codebytere mentioned this pull request Feb 29, 2020
@codebytere
Copy link
Member

codebytere commented Mar 16, 2020

Blocked on #31178, which can likely land in the next minor (this next upcoming one is a patch)

@targos targos removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-blocked-v12.x labels Apr 25, 2020
targos pushed a commit to targos/node that referenced this pull request Apr 25, 2020
This commit adds a check to test-crypto-dh-statless to avoid an error if
the curve secp224k1 is not present. This could occur if node was
configured with shared-openssl.

The use case for this was building on RHEL 8.1 which only has the
following curves:
$ openssl ecparam -list_curves
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field

PR-URL: nodejs#31715
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit that referenced this pull request Apr 28, 2020
This commit adds a check to test-crypto-dh-statless to avoid an error if
the curve secp224k1 is not present. This could occur if node was
configured with shared-openssl.

The use case for this was building on RHEL 8.1 which only has the
following curves:
$ openssl ecparam -list_curves
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field

PR-URL: #31715
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants