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

crypto, errors: Add CryptoError to internal/errors, update crypto.setEngine #16529

Closed
wants to merge 5 commits into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Oct 26, 2017

The way that throwCryptoError() is currently defined within src/node_crypto.cc makes it rather difficult to refactor those errors to use internal/errors. This provides an alternative and an example of it being used.

There are three commits:

  • One that adds a new additional callback check for common.expectsError() that provides the ability to perform additional checks on an error

  • One that adds a new errors.CryptoError to internal/errors

  • One that finishing migrating the crypto.setEngine() method to use errors.CryptoError, illustrating how the revised mechanism for getting the opensslErrorStack and message properties would work. The same pattern would be used for all instances of throwCryptoError()

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

crypto, errors

@jasnell jasnell added crypto Issues and PRs related to the crypto subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. semver-major PRs that contain breaking changes and should be released in the next major version. labels Oct 26, 2017
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Oct 26, 2017
@jasnell
Copy link
Member Author

jasnell commented Oct 26, 2017

Ping @nodejs/tsc

@jasnell jasnell changed the title Internal errors crypto error crypto, errors: Add CryptoError to internal/errors, update crypto.setEngine Oct 26, 2017
@jasnell
Copy link
Member Author

jasnell commented Oct 26, 2017

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@jasnell
Copy link
Member Author

jasnell commented Oct 27, 2017

Test is failing on windows... fixing now

@jasnell
Copy link
Member Author

jasnell commented Oct 27, 2017

assert(err.info, 'does not have info property');
assert(Array.isArray(err.opensslErrorStack),
'opensslErrorStack must be an array');
assert(typeof err.info.code, 'number');
Copy link
Member

Choose a reason for hiding this comment

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

assert.strictEqual(), and the line below

@jasnell
Copy link
Member Author

jasnell commented Oct 30, 2017

I'd like this to land after #16567

Allows setting an `additional` callback to perform additional
checks on the given error object
A new internal/errors type that provides access to the
`opensslErrorStack`, code, and message.
Update the `crypto.setEngine()` method to use the new
internal/errors `CryptoError` mechanism rather than
using `throwCryptoError()`
@jasnell jasnell force-pushed the internal-errors-crypto-error branch from c654fda to 5fce91e Compare October 30, 2017 00:25
@@ -309,9 +288,65 @@ void ThrowCryptoError(Environment* env,
// 'error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib',
// 'error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 err'
// ]
exception->Set(env->context(), env->openssl_error_stack(), error_stack)
context->Set(env->context(), env->openssl_error_stack(), error_stack)
Copy link
Member

Choose a reason for hiding this comment

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

Would be easier to understand if the context argument here is named exception or error, I thought this is a v8::Context at first

Copy link
Member

Choose a reason for hiding this comment

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

Also the one in CaptureCryptoStatus

Copy link
Member Author

Choose a reason for hiding this comment

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

Once #16567 lands I'll be refactoring this one a bit. Will make that change then.

@jasnell jasnell added the wip Issues and PRs that are still a work in progress. label Oct 30, 2017
@targos
Copy link
Member

targos commented Jan 15, 2018

@jasnell #16567 landed. Would you like to update this?

@jasnell
Copy link
Member Author

jasnell commented Jan 15, 2018

@targos ... yes, I'll get this updated this week.

@BridgeAR
Copy link
Member

@jasnell there is not much time left this week ;-)

@jasnell
Copy link
Member Author

jasnell commented Jan 19, 2018

Heh. True. Will still try to get to it.

@BridgeAR
Copy link
Member

Ping @jasnell

@jasnell
Copy link
Member Author

jasnell commented Jan 31, 2018

Yep, haven't forgotten. :-)

@BridgeAR
Copy link
Member

BridgeAR commented Feb 7, 2018

@jasnell ping again ;-)

@jasnell jasnell closed this Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. semver-major PRs that contain breaking changes and should be released in the next major version. wip Issues and PRs that are still a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants