-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Crypto add opensslerror stack #15518
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
Changes from 1 commit
f2c9e49
dc2165a
5c24f07
d1296cf
2b177cb
bbaea8b
a5a2f64
2ad7440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,7 +193,7 @@ detailing the point in the code at which the `Error` was instantiated, and may | |
| provide a text description of the error. | ||
|
|
||
| For crypto only, `Error` objects will include the OpenSSL error stack in a | ||
| separate property called `openSSLErrorStack` if it is available when the error is thrown. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. long line here? |
||
| separate property called `opensslErrorStack` if it is available when the error is thrown. | ||
|
|
||
| All errors generated by Node.js, including all System and JavaScript errors, | ||
| will either be instances of, or inherit from, the `Error` class. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,7 +278,7 @@ void ThrowCryptoError(Environment* env, | |
| Local<Array> error_stack = Array::New(env->isolate()); | ||
| int top = es->top; | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, we wont add the property to the exception every time. |
||
| // Build the error_stack array to be added to openSSLErrorStack property. | ||
| // Build the error_stack array to be added to opensslErrorStack property. | ||
| for (unsigned int i = 0; es->bottom != es->top;) { | ||
| unsigned long err_buf = es->err_buffer[es->top]; // NOLINT(runtime/int) | ||
| // Only add error string if there is valid err_buffer. | ||
|
|
@@ -303,9 +303,9 @@ void ThrowCryptoError(Environment* env, | |
| // Restore top. | ||
| es->top = top; | ||
|
|
||
| // Add the openSSLErrorStack property to the exception object. | ||
| // Add the opensslErrorStack property to the exception object. | ||
| // The new property will look like the following: | ||
| // openSSLErrorStack: [ | ||
| // opensslErrorStack: [ | ||
| // 'error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib', | ||
| // 'error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 err' | ||
| // ] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,10 +47,10 @@ assert.throws(function() { | |
| const notcontext = { setOptions: context.setOptions, setKey: context.setKey }; | ||
| tls.createSecureContext({ secureOptions: 1 }, notcontext); | ||
| }, (err) => { | ||
| // Throws TypeError, so there is no openSSLErrorStack property. | ||
| // Throws TypeError, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^TypeError: Illegal invocation$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
@@ -63,32 +63,32 @@ assert.doesNotThrow(function() { | |
| assert.throws(function() { | ||
| tls.createSecureContext({ pfx: certPfx }); | ||
| }, (err) => { | ||
| // Throws general Error, so there is no openSSLErrorStack property. | ||
| // Throws general Error, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^Error: mac verify failure$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| assert.throws(function() { | ||
| tls.createSecureContext({ pfx: certPfx, passphrase: 'test' }); | ||
| }, (err) => { | ||
| // Throws general Error, so there is no openSSLErrorStack property. | ||
| // Throws general Error, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^Error: mac verify failure$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| assert.throws(function() { | ||
| tls.createSecureContext({ pfx: 'sample', passphrase: 'test' }); | ||
| }, (err) => { | ||
| // Throws general Error, so there is no openSSLErrorStack property. | ||
| // Throws general Error, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^Error: not enough data$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
@@ -169,10 +169,10 @@ assert.throws(function() { | |
| }, (err) => { | ||
| const errorMessage = | ||
| common.hasFipsCrypto ? /not supported in FIPS mode/ : /Bad input string/; | ||
| // Throws general Error, so there is no openSSLErrorStack property. | ||
| // Throws general Error, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| errorMessage.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
@@ -182,43 +182,43 @@ assert.throws(function() { | |
| }, (err) => { | ||
| const errorMessage = | ||
| common.hasFipsCrypto ? /not supported in FIPS mode/ : /Bad input string/; | ||
| // Throws general Error, so there is no openSSLErrorStack property. | ||
| // Throws general Error, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| errorMessage.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| assert.throws(function() { | ||
| crypto.createHash('sha1').update('0', 'hex'); | ||
| }, (err) => { | ||
| // Throws TypeError, so there is no openSSLErrorStack property. | ||
| // Throws TypeError, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^TypeError: Bad input string$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| assert.throws(function() { | ||
| crypto.createSign('SHA1').update('0', 'hex'); | ||
| }, (err) => { | ||
| // Throws TypeError, so there is no openSSLErrorStack property. | ||
| // Throws TypeError, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^TypeError: Bad input string$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| assert.throws(function() { | ||
| crypto.createVerify('SHA1').update('0', 'hex'); | ||
| }, (err) => { | ||
| // Throws TypeError, so there is no openSSLErrorStack property. | ||
| // Throws TypeError, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^TypeError: Bad input string$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
@@ -237,7 +237,7 @@ assert.throws(function() { | |
| }, (err) => { | ||
| if ((err instanceof Error) && | ||
| /digest too big for rsa key$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update test since the openSSLErrorStack is not always added |
||
| } | ||
| }); | ||
|
|
@@ -257,13 +257,13 @@ assert.throws(function() { | |
| // this would inject errors onto OpenSSL's error stack | ||
| crypto.createSign('sha1').sign(sha1_privateKey); | ||
| }, (err) => { | ||
| // Throws crypto error, so there is an openSSLErrorStack property. | ||
| // Throws crypto error, so there is an opensslErrorStack property. | ||
| // The openSSL stack should have content. | ||
| if ((err instanceof Error) && | ||
| /asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag/.test(err) && | ||
| err.openSSLErrorStack !== undefined && | ||
| Array.isArray(err.openSSLErrorStack) && | ||
| err.openSSLErrorStack.length > 0) { | ||
| err.opensslErrorStack !== undefined && | ||
| Array.isArray(err.opensslErrorStack) && | ||
| err.opensslErrorStack.length > 0) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
@@ -274,10 +274,10 @@ console.log(crypto.randomBytes(16)); | |
| assert.throws(function() { | ||
| tls.createSecureContext({ crl: 'not a CRL' }); | ||
| }, (err) => { | ||
| // Throws general error, so there is no openSSLErrorStack property. | ||
| // Throws general error, so there is no opensslErrorStack property. | ||
| if ((err instanceof Error) && | ||
| /^Error: Failed to parse CRL$/.test(err) && | ||
| err.openSSLErrorStack === undefined) { | ||
| err.opensslErrorStack === undefined) { | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has the latest review comment fixes.
@bnoordhuis, i believe i've addressed all of your comments. Thanks for the review.