forked from nodejs/node
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: use openssl's own memory BIOs in crypto_context.cc
NodeBIO's memory buffer structure does not support BIO_C_FILE_SEEK and B IO_C_FILE_TELL. This prevents OpenSSL PEM_read_bio_PrivateKey from readi ng some private keys. So I switched to OpenSSL'w own protected memory bu ffers. Fixes: nodejs#47008 PR-URL: nodejs#47160 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
1 parent
ed0b62c
commit 7617772
Showing
3 changed files
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "crypto/crypto_bio.h" | ||
#include "gtest/gtest.h" | ||
#include "node_options.h" | ||
#include "node_test_fixture.h" | ||
#include "openssl/err.h" | ||
|
||
using v8::Local; | ||
using v8::String; | ||
|
||
/* | ||
* This test verifies that an object created by LoadBIO supports BIO_tell | ||
* and BIO_seek, otherwise PEM_read_bio_PrivateKey fails on some keys | ||
* (if OpenSSL needs to rewind pointer between pem_read_bio_key() | ||
* and pem_read_bio_key_legacy() inside PEM_read_bio_PrivateKey). | ||
*/ | ||
class NodeCryptoEnv : public EnvironmentTestFixture {}; | ||
|
||
TEST_F(NodeCryptoEnv, LoadBIO) { | ||
v8::HandleScope handle_scope(isolate_); | ||
Argv argv; | ||
Env env{handle_scope, argv}; | ||
// just put a random string into BIO | ||
Local<String> key = String::NewFromUtf8(isolate_, "abcdef").ToLocalChecked(); | ||
node::crypto::BIOPointer bio(node::crypto::LoadBIO(*env, key)); | ||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L | ||
BIO_seek(bio.get(), 2); | ||
ASSERT_EQ(BIO_tell(bio.get()), 2); | ||
#endif | ||
ASSERT_EQ(ERR_peek_error(), 0UL) << "There should not have left " | ||
"any errors on the OpenSSL error stack\n"; | ||
} |