-
-
Notifications
You must be signed in to change notification settings - Fork 35k
src: split CryptoPemCallback into two functions #12827
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
5 commits
Select commit
Hold shift + click to select a range
ec352c1
src: split CryptoPemCallback into two functions
danbev 281402f
add additional newline for consistency
danbev e7da72f
fix bug when len = 1
danbev 3a59be8
restore support for null passphase
danbev 9c8e991
update NoPasswordCallback comment
danbev 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
restore support for null passphase
- Loading branch information
commit 3a59be895e18fa524b67bb985a723f16b774bbc3
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 |
|---|---|---|
|
|
@@ -229,12 +229,15 @@ static void crypto_lock_cb(int mode, int n, const char* file, int line) { | |
|
|
||
|
|
||
| static int PasswordCallback(char *buf, int size, int rwflag, void *u) { | ||
| CHECK_NE(u, nullptr); | ||
| size_t buflen = static_cast<size_t>(size); | ||
| size_t len = strlen(static_cast<const char*>(u)); | ||
| len = len > buflen ? buflen : len; | ||
| memcpy(buf, u, len); | ||
| return len; | ||
| if (u) { | ||
| size_t buflen = static_cast<size_t>(size); | ||
| size_t len = strlen(static_cast<const char*>(u)); | ||
| len = len > buflen ? buflen : len; | ||
| memcpy(buf, u, len); | ||
| return len; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -473,10 +476,9 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) { | |
| return env->ThrowError("Only private key and pass phrase are expected"); | ||
| } | ||
|
|
||
| bool has_password = len == 2; | ||
| if (has_password) { | ||
| if (len == 2) { | ||
| if (args[1]->IsUndefined() || args[1]->IsNull()) | ||
| has_password = false; | ||
| len = 1; | ||
| else | ||
| THROW_AND_RETURN_IF_NOT_STRING(args[1], "Pass phrase"); | ||
| } | ||
|
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. What if
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. Oh yes, sorry. Let me fix that. Thanks |
||
|
|
@@ -485,13 +487,12 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) { | |
| if (!bio) | ||
| return; | ||
|
|
||
| auto callback = has_password ? PasswordCallback : NoPasswordCallback; | ||
| auto passphrase = has_password ? | ||
| *node::Utf8Value{env->isolate(), args[1]} : nullptr; | ||
| node::Utf8Value passphrase(env->isolate(), args[1]); | ||
|
|
||
| EVP_PKEY* key = PEM_read_bio_PrivateKey(bio, | ||
| nullptr, | ||
| callback, | ||
| passphrase); | ||
| PasswordCallback, | ||
| len == 1 ? nullptr : *passphrase); | ||
|
|
||
| if (!key) { | ||
| BIO_free_all(bio); | ||
|
|
||
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.
Please add one more newline here, please.
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.
I'll fix that.