@@ -31,6 +31,8 @@ using ncrypto::BIOPointer;
3131using ncrypto::CryptoErrorList;
3232using ncrypto::EnginePointer;
3333using ncrypto::EVPKeyCtxPointer;
34+ using ncrypto::SSLCtxPointer;
35+ using ncrypto::SSLPointer;
3436using v8::ArrayBuffer;
3537using v8::BackingStore;
3638using v8::BigInt;
@@ -201,6 +203,27 @@ void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args) {
201203 args.GetReturnValue ().Set (ncrypto::testFipsEnabled () ? 1 : 0 );
202204}
203205
206+ void GetOpenSSLSecLevelCrypto (const FunctionCallbackInfo<Value>& args) {
207+ // for BoringSSL assume the same as the default
208+ int sec_level = OPENSSL_TLS_SECURITY_LEVEL ;
209+ #ifndef OPENSSL_IS_BORINGSSL
210+ Environment* env = Environment::GetCurrent (args);
211+
212+ auto ctx = SSLCtxPointer::New ();
213+ if (!ctx) {
214+ return ThrowCryptoError (env, ERR_get_error (), " SSL_CTX_new" );
215+ }
216+
217+ auto ssl = SSLPointer::New (ctx);
218+ if (!ssl) {
219+ return ThrowCryptoError (env, ERR_get_error (), " SSL_new" );
220+ }
221+
222+ sec_level = SSL_get_security_level (ssl);
223+ #endif // OPENSSL_IS_BORINGSSL
224+ args.GetReturnValue ().Set (sec_level);
225+ }
226+
204227void CryptoErrorStore::Capture () {
205228 errors_.clear ();
206229 while (const uint32_t err = ERR_get_error ()) {
@@ -699,6 +722,9 @@ void Initialize(Environment* env, Local<Object> target) {
699722
700723 SetMethod (context, target, " secureBuffer" , SecureBuffer);
701724 SetMethod (context, target, " secureHeapUsed" , SecureHeapUsed);
725+
726+ SetMethodNoSideEffect (
727+ context, target, " getOpenSSLSecLevelCrypto" , GetOpenSSLSecLevelCrypto);
702728}
703729void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
704730#ifndef OPENSSL_NO_ENGINE
@@ -710,6 +736,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
710736 registry->Register (TestFipsCrypto);
711737 registry->Register (SecureBuffer);
712738 registry->Register (SecureHeapUsed);
739+ registry->Register (GetOpenSSLSecLevelCrypto);
713740}
714741
715742} // namespace Util
0 commit comments