| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 50ebd5f commit 60039a2
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ const { | |||
| 32 | 32 | setEngine: _setEngine, | |
| 33 | 33 | secureHeapUsed: _secureHeapUsed, | |
| 34 | 34 | getCachedAliases, | |
| 35 | + getOpenSSLSecLevelCrypto: getOpenSSLSecLevel, | ||
| 35 | 36 | } = internalBinding('crypto'); | |
| 36 | 37 | ||
| 37 | 38 | const { getOptionValue } = require('internal/options'); | |
@@ -631,4 +632,5 @@ module.exports = { | |||
| 631 | 632 | secureHeapUsed, | |
| 632 | 633 | getCachedHashId, | |
| 633 | 634 | getHashCache, | |
| 635 | + getOpenSSLSecLevel, | ||
| 634 | 636 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,8 @@ using ncrypto::BIOPointer; | |||
| 31 | 31 | using ncrypto::CryptoErrorList; | |
| 32 | 32 | using ncrypto::EnginePointer; | |
| 33 | 33 | using ncrypto::EVPKeyCtxPointer; | |
| 34 | + using ncrypto::SSLCtxPointer; | ||
| 35 | + using ncrypto::SSLPointer; | ||
| 34 | 36 | using v8::ArrayBuffer; | |
| 35 | 37 | using v8::BackingStore; | |
| 36 | 38 | using v8::BigInt; | |
@@ -201,6 +203,27 @@ void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 201 | 203 | args.GetReturnValue().Set(ncrypto::testFipsEnabled() ? 1 : 0); | |
| 202 | 204 | } | |
| 203 | 205 | ||
| 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 | + | ||
| 204 | 227 | void CryptoErrorStore::Capture() { | |
| 205 | 228 | errors_.clear(); | |
| 206 | 229 | while (const uint32_t err = ERR_get_error()) { | |
@@ -699,6 +722,9 @@ void Initialize(Environment* env, Local<Object> target) { | |||
| 699 | 722 | ||
| 700 | 723 | SetMethod(context, target, "secureBuffer", SecureBuffer); | |
| 701 | 724 | SetMethod(context, target, "secureHeapUsed", SecureHeapUsed); | |
| 725 | + | ||
| 726 | + SetMethodNoSideEffect( | ||
| 727 | + context, target, "getOpenSSLSecLevelCrypto", GetOpenSSLSecLevelCrypto); | ||
| 702 | 728 | } | |
| 703 | 729 | void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |
| 704 | 730 | #ifndef OPENSSL_NO_ENGINE | |
@@ -710,6 +736,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 710 | 736 | registry->Register(TestFipsCrypto); | |
| 711 | 737 | registry->Register(SecureBuffer); | |
| 712 | 738 | registry->Register(SecureHeapUsed); | |
| 739 | + registry->Register(GetOpenSSLSecLevelCrypto); | ||
| 713 | 740 | } | |
| 714 | 741 | ||
| 715 | 742 | } // namespace Util | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + if (!common.hasCrypto) | ||
| 6 | + common.skip('missing crypto'); | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + | ||
| 10 | + // OpenSSL has a set of security levels which affect what algorithms | ||
| 11 | + // are available by default. Different OpenSSL veresions have different | ||
| 12 | + // default security levels and we use this value to adjust what a test | ||
| 13 | + // expects based on the security level. You can read more in | ||
| 14 | + // https://docs.openssl.org/1.1.1/man3/SSL_CTX_set_security_level/#default-callback-behaviour | ||
| 15 | + // This test simply validates that we can get some value for the secLevel | ||
| 16 | + // when needed by tests. | ||
| 17 | + const secLevel = require('internal/crypto/util').getOpenSSLSecLevel(); | ||
| 18 | + assert.ok(secLevel >= 0 && secLevel <= 5); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // Flags: --no-warnings | ||
| 1 | + // Flags: --no-warnings --expose-internals | ||
| 2 | 2 | // Copyright Joyent, Inc. and other Node contributors. | |
| 3 | 3 | // | |
| 4 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a | |
@@ -27,10 +27,16 @@ if (!common.hasCrypto) { | |||
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | 29 | const { | |
| 30 | - hasOpenSSL, | ||
| 31 | 30 | opensslCli, | |
| 32 | 31 | } = require('../common/crypto'); | |
| 33 | 32 | ||
| 33 | + // OpenSSL has a set of security levels which affect what algorithms | ||
| 34 | + // are available by default. Different OpenSSL veresions have different | ||
| 35 | + // default security levels and we use this value to adjust what a test | ||
| 36 | + // expects based on the security level. You can read more in | ||
| 37 | + // https://docs.openssl.org/1.1.1/man3/SSL_CTX_set_security_level/#default-callback-behaviour | ||
| 38 | + const secLevel = require('internal/crypto/util').getOpenSSLSecLevel(); | ||
| 39 | + | ||
| 34 | 40 | if (!opensslCli) { | |
| 35 | 41 | common.skip('missing openssl-cli'); | |
| 36 | 42 | } | |
@@ -50,7 +56,7 @@ const dheCipher = 'DHE-RSA-AES128-SHA256'; | |||
| 50 | 56 | const ecdheCipher = 'ECDHE-RSA-AES128-SHA256'; | |
| 51 | 57 | const ciphers = `${dheCipher}:${ecdheCipher}`; | |
| 52 | 58 | ||
| 53 | - if (!hasOpenSSL(3, 2)) { | ||
| 59 | + if (secLevel < 2) { | ||
| 54 | 60 | // Test will emit a warning because the DH parameter size is < 2048 bits | |
| 55 | 61 | // when the test is run on versions lower than OpenSSL32 | |
| 56 | 62 | common.expectWarning('SecurityWarning', | |
@@ -114,7 +120,9 @@ function testCustomParam(keylen, expectedCipher) { | |||
| 114 | 120 | }, /DH parameter is less than 1024 bits/); | |
| 115 | 121 | ||
| 116 | 122 | // Custom DHE parameters are supported (but discouraged). | |
| 117 | - if (!hasOpenSSL(3, 2)) { | ||
| 123 | + // 1024 is disallowed at security level 2 and above so use 3072 instead | ||
| 124 | + // for higher security levels | ||
| 125 | + if (secLevel < 2) { | ||
| 118 | 126 | await testCustomParam(1024, dheCipher); | |
| 119 | 127 | } else { | |
| 120 | 128 | await testCustomParam(3072, dheCipher); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments