-
-
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f2c9e49
crypto: better crypto error messages
gla5001 dc2165a
Review updates and tests
gla5001 5c24f07
Additional review updates.
gla5001 d1296cf
Review update. Use the overload of Set()
gla5001 2b177cb
Nit fix: changing local variable to snake_case
gla5001 bbaea8b
PR review updates
gla5001 a5a2f64
changing openSSLErrorStack property name to opensslErrorStack
gla5001 2ad7440
fixing long doc line
gla5001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
crypto: better crypto error messages
Feature request to add openSSL error stack to the exception object thrown from crypto. New exception property only added to object if the error stack has not cleared out prior to calling ThrowCryptoError. Refs: #5444
- Loading branch information
commit f2c9e4957473f4a0033698b366aa1993fa3095f5
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,13 +255,53 @@ void ThrowCryptoError(Environment* env, | |
| unsigned long err, // NOLINT(runtime/int) | ||
| const char* default_message = nullptr) { | ||
| HandleScope scope(env->isolate()); | ||
| Local<String> message; | ||
|
|
||
| if (err != 0 || default_message == nullptr) { | ||
| char errmsg[128] = { 0 }; | ||
| ERR_error_string_n(err, errmsg, sizeof(errmsg)); | ||
| env->ThrowError(errmsg); | ||
| message = String::NewFromUtf8(env->isolate(), errmsg, | ||
| v8::NewStringType::kInternalized) | ||
| .ToLocalChecked(); | ||
| } else { | ||
| env->ThrowError(default_message); | ||
| message = String::NewFromUtf8(env->isolate(), default_message, | ||
| v8::NewStringType::kInternalized) | ||
| .ToLocalChecked(); | ||
| } | ||
|
|
||
| Local<Value> exception_v = Exception::Error(message); | ||
| CHECK(!exception_v.IsEmpty()); | ||
| // add the openSSLErrorStack property | ||
| Local<Object> exception = exception_v.As<Object>(); | ||
| Local<String> key = String::NewFromUtf8(env->isolate(), "openSSLErrorStack", | ||
| v8::NewStringType::kInternalized) | ||
| .ToLocalChecked(); | ||
| Local<Array> errorStack = Array::New(env->isolate()); | ||
|
|
||
| // get the error state | ||
| // will only add to errorStack if state has not been cleared out | ||
| ERR_STATE *es; | ||
| es = ERR_get_state(); | ||
|
|
||
| // add content to the openssl error stack | ||
| unsigned int i = 0; | ||
| while (es->bottom != es->top | ||
| && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) { | ||
| unsigned long err_buf = es->err_buffer[es->top]; // NOLINT(runtime/int) | ||
| // only add if there is valid err_buffer | ||
| if (err_buf) { | ||
| char tmpStr[128] = { 0 }; | ||
| ERR_error_string_n(err_buf, tmpStr, sizeof(tmpStr)); | ||
| errorStack->Set(i, String::NewFromUtf8(env->isolate(), tmpStr, | ||
| v8::NewStringType::kInternalized) | ||
| .ToLocalChecked()); | ||
| } | ||
| i++; | ||
| es->top -= 1; | ||
| } | ||
|
|
||
| exception->Set(env->context(), key, errorStack).FromJust(); | ||
| env->isolate()->ThrowException(exception); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -4278,7 +4318,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem, | |
| if (!initialised_) | ||
| return kSignNotInitialised; | ||
|
|
||
| ClearErrorOnReturn clear_error_on_return; | ||
| // ClearErrorOnReturn clear_error_on_return; | ||
|
|
||
| EVP_PKEY* pkey = nullptr; | ||
| BIO* bp = nullptr; | ||
|
|
@@ -4289,6 +4329,8 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem, | |
| int r = 0; | ||
| EVP_PKEY_CTX* pkctx = nullptr; | ||
|
|
||
| ERR_set_mark(); | ||
|
|
||
| bp = BIO_new_mem_buf(const_cast<char*>(key_pem), key_pem_len); | ||
|
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. this is not needed |
||
| if (bp == nullptr) | ||
| goto exit; | ||
|
|
@@ -4368,6 +4410,8 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem, | |
| void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) { | ||
| Environment* env = Environment::GetCurrent(args); | ||
|
|
||
| ClearErrorOnReturn clear_error_on_return; | ||
|
|
||
| Verify* verify; | ||
| ASSIGN_OR_RETURN_UNWRAP(&verify, args.Holder()); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
handle the ring buffer with modular arithmetic