1 #include "crypto/crypto_bio.h" 2 #include "gtest/gtest.h" 3 #include "node_options.h" 4 #include "node_test_fixture.h" 5 #include "openssl/err.h" 6 7 using v8::Local; 8 using v8::String; 9 10 /* 11 * This test verifies that an object created by LoadBIO supports BIO_tell 12 * and BIO_seek, otherwise PEM_read_bio_PrivateKey fails on some keys 13 * (if OpenSSL needs to rewind pointer between pem_read_bio_key() 14 * and pem_read_bio_key_legacy() inside PEM_read_bio_PrivateKey). 15 */ 16 class NodeCryptoEnv : public EnvironmentTestFixture {}; 17 TEST_F(NodeCryptoEnv,LoadBIO)18TEST_F(NodeCryptoEnv, LoadBIO) { 19 v8::HandleScope handle_scope(isolate_); 20 Argv argv; 21 Env env{handle_scope, argv}; 22 // just put a random string into BIO 23 Local<String> key = String::NewFromUtf8(isolate_, "abcdef").ToLocalChecked(); 24 node::crypto::BIOPointer bio(node::crypto::LoadBIO(*env, key)); 25 #if OPENSSL_VERSION_NUMBER >= 0x30000000L 26 BIO_seek(bio.get(), 2); 27 ASSERT_EQ(BIO_tell(bio.get()), 2); 28 #endif 29 ASSERT_EQ(ERR_peek_error(), 0UL) << "There should not have left " 30 "any errors on the OpenSSL error stack\n"; 31 } 32