| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0e87576 commit 137ff67
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2252,14 +2252,11 @@ DHPointer::CheckPublicKeyResult DHPointer::checkPublicKey( | |||
| 2252 | 2252 | if (DH_check_pub_key(dh_.get(), pub_key.get(), &codes) != 1) { | |
| 2253 | 2253 | return DHPointer::CheckPublicKeyResult::CHECK_FAILED; | |
| 2254 | 2254 | } | |
| 2255 | - #ifndef OPENSSL_IS_BORINGSSL | ||
| 2256 | - // Boringssl does not define DH_CHECK_PUBKEY_TOO_SMALL or TOO_LARGE | ||
| 2257 | 2255 | if (codes & DH_CHECK_PUBKEY_TOO_SMALL) { | |
| 2258 | 2256 | return DHPointer::CheckPublicKeyResult::TOO_SMALL; | |
| 2259 | 2257 | } else if (codes & DH_CHECK_PUBKEY_TOO_LARGE) { | |
| 2260 | 2258 | return DHPointer::CheckPublicKeyResult::TOO_LARGE; | |
| 2261 | 2259 | } | |
| 2262 | - #endif | ||
| 2263 | 2260 | if (codes != 0) { | |
| 2264 | 2261 | return DHPointer::CheckPublicKeyResult::INVALID; | |
| 2265 | 2262 | } | |
@@ -4309,6 +4306,13 @@ std::optional<std::string_view> SSLPointer::getNegotiatedGroup() const { | |||
| 4309 | 4306 | const char* group = SSL_get0_group_name(get()); | |
| 4310 | 4307 | if (group == nullptr) return std::nullopt; | |
| 4311 | 4308 | return group; | |
| 4309 | + #elif defined(OPENSSL_IS_BORINGSSL) | ||
| 4310 | + if (!ssl_) return std::nullopt; | ||
| 4311 | + const int nid = SSL_get_negotiated_group(get()); | ||
| 4312 | + if (nid == NID_undef) return std::nullopt; | ||
| 4313 | + const char* group = OBJ_nid2sn(nid); | ||
| 4314 | + if (group == nullptr) return std::nullopt; | ||
| 4315 | + return group; | ||
| 4312 | 4316 | #else | |
| 4313 | 4317 | return std::nullopt; | |
| 4314 | 4318 | #endif | |
@@ -4333,19 +4337,17 @@ std::optional<std::string_view> SSLPointer::getCipherVersion() const { | |||
| 4333 | 4337 | } | |
| 4334 | 4338 | ||
| 4335 | 4339 | std::optional<int> SSLPointer::getSecurityLevel() { | |
| 4336 | - #ifndef OPENSSL_IS_BORINGSSL | ||
| 4337 | 4340 | auto ctx = SSLCtxPointer::New(); | |
| 4338 | 4341 | if (!ctx) return std::nullopt; | |
| 4339 | 4342 | ||
| 4343 | + #ifdef OPENSSL_IS_BORINGSSL | ||
| 4344 | + return SSL_CTX_get_security_level(ctx.get()); | ||
| 4345 | + #else | ||
| 4340 | 4346 | auto ssl = SSLPointer::New(ctx); | |
| 4341 | 4347 | if (!ssl) return std::nullopt; | |
| 4342 | 4348 | ||
| 4343 | 4349 | return SSL_get_security_level(ssl); | |
| 4344 | - #else | ||
| 4345 | - // OPENSSL_TLS_SECURITY_LEVEL is not defined in BoringSSL | ||
| 4346 | - // so assume it is the default OPENSSL_TLS_SECURITY_LEVEL value. | ||
| 4347 | - return 1; | ||
| 4348 | - #endif // OPENSSL_IS_BORINGSSL | ||
| 4350 | + #endif | ||
| 4349 | 4351 | } | |
| 4350 | 4352 | ||
| 4351 | 4353 | SSLCtxPointer::SSLCtxPointer(SSL_CTX* ctx) : ctx_(ctx) {} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1231,9 +1231,9 @@ class DHPointer final { | |||
| 1231 | 1231 | UNABLE_TO_CHECK_GENERATOR = 0x04, | |
| 1232 | 1232 | NOT_SUITABLE_GENERATOR = 0x08, | |
| 1233 | 1233 | Q_NOT_PRIME = 0x10, | |
| 1234 | - #ifndef OPENSSL_IS_BORINGSSL | ||
| 1235 | - // Boringssl does not define the DH_CHECK_INVALID_[Q or J]_VALUE | ||
| 1236 | 1234 | INVALID_Q = 0x20, | |
| 1235 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 1236 | + // BoringSSL does not define DH_CHECK_INVALID_J_VALUE. | ||
| 1237 | 1237 | INVALID_J = 0x40, | |
| 1238 | 1238 | MODULUS_TOO_SMALL = 0x80, | |
| 1239 | 1239 | MODULUS_TOO_LARGE = 0x100, | |
@@ -1244,14 +1244,9 @@ class DHPointer final { | |||
| 1244 | 1244 | ||
| 1245 | 1245 | enum class CheckPublicKeyResult { | |
| 1246 | 1246 | NONE, | |
| 1247 | - #ifndef OPENSSL_IS_BORINGSSL | ||
| 1248 | - // Boringssl does not define DH_R_CHECK_PUBKEY_TOO_SMALL or TOO_LARGE | ||
| 1249 | - TOO_SMALL = DH_R_CHECK_PUBKEY_TOO_SMALL, | ||
| 1250 | - TOO_LARGE = DH_R_CHECK_PUBKEY_TOO_LARGE, | ||
| 1251 | - INVALID = DH_R_CHECK_PUBKEY_INVALID, | ||
| 1252 | - #else | ||
| 1253 | - INVALID = DH_R_INVALID_PUBKEY, | ||
| 1254 | - #endif | ||
| 1247 | + TOO_SMALL, | ||
| 1248 | + TOO_LARGE, | ||
| 1249 | + INVALID, | ||
| 1255 | 1250 | CHECK_FAILED = 512, | |
| 1256 | 1251 | }; | |
| 1257 | 1252 | // Check to see if the given public key is suitable for this DH instance. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,12 +319,10 @@ void ComputeSecret(const FunctionCallbackInfo<Value>& args) { | |||
| 319 | 319 | case DHPointer::CheckPublicKeyResult::CHECK_FAILED: | |
| 320 | 320 | return THROW_ERR_CRYPTO_INVALID_KEYTYPE(env, | |
| 321 | 321 | "Unspecified validation error"); | |
| 322 | - #ifndef OPENSSL_IS_BORINGSSL | ||
| 323 | 322 | case DHPointer::CheckPublicKeyResult::TOO_SMALL: | |
| 324 | 323 | return THROW_ERR_CRYPTO_INVALID_KEYLEN(env, "Supplied key is too small"); | |
| 325 | 324 | case DHPointer::CheckPublicKeyResult::TOO_LARGE: | |
| 326 | 325 | return THROW_ERR_CRYPTO_INVALID_KEYLEN(env, "Supplied key is too large"); | |
| 327 | - #endif | ||
| 328 | 326 | case DHPointer::CheckPublicKeyResult::INVALID: | |
| 329 | 327 | return THROW_ERR_CRYPTO_INVALID_KEYTYPE(env, "Supplied key is invalid"); | |
| 330 | 328 | case DHPointer::CheckPublicKeyResult::NONE: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,18 +137,6 @@ Maybe<void> RsaKeyGenTraits::AdditionalConfig( | |||
| 137 | 137 | params->params.modulus_bits = args[*offset + 1].As<Uint32>()->Value(); | |
| 138 | 138 | params->params.exponent = args[*offset + 2].As<Uint32>()->Value(); | |
| 139 | 139 | ||
| 140 | - #ifdef OPENSSL_IS_BORINGSSL | ||
| 141 | - // BoringSSL hangs indefinitely generating an RSA key with e=1, and for | ||
| 142 | - // other invalid exponents (e=0, even values) reports the misleading error | ||
| 143 | - // RSA_R_TOO_MANY_ITERATIONS only after running the full keygen loop. Reject | ||
| 144 | - // those up-front with a clear error. The constraint here (odd integer >= 3) | ||
| 145 | - // matches BoringSSL's own rsa_check_public_key validation. | ||
| 146 | - if (params->params.exponent < 3 || (params->params.exponent & 1) == 0) { | ||
| 147 | - THROW_ERR_OUT_OF_RANGE(env, "publicExponent is invalid"); | ||
| 148 | - return Nothing<void>(); | ||
| 149 | - } | ||
| 150 | - #endif | ||
| 151 | - | ||
| 152 | 140 | *offset += 3; | |
| 153 | 141 | ||
| 154 | 142 | if (params->params.variant == kKeyVariantRSA_PSS) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,12 +137,9 @@ function testRenegotiationUnsupported() { | |||
| 137 | 137 | } | |
| 138 | 138 | ||
| 139 | 139 | /** | |
| 140 | - * OpenSSL exposes the negotiated ephemeral key type, name, and size for TLS | ||
| 141 | - * clients. With BoringSSL the same ECDHE TLS 1.2 handshake succeeds, but | ||
| 142 | - * getEphemeralKeyInfo() returns null on the server side and an object whose | ||
| 143 | - * fields are undefined on the client side. | ||
| 140 | + * BoringSSL exposes the negotiated TLS group but not the ephemeral key size. | ||
| 144 | 141 | */ | |
| 145 | - function testEphemeralKeyInfoUnsupported() { | ||
| 142 | + function testEphemeralKeyInfo() { | ||
| 146 | 143 | const server = tls.createServer({ | |
| 147 | 144 | key: fixtures.readKey('agent2-key.pem'), | |
| 148 | 145 | cert: fixtures.readKey('agent2-cert.pem'), | |
@@ -161,8 +158,8 @@ function testEphemeralKeyInfoUnsupported() { | |||
| 161 | 158 | maxVersion: 'TLSv1.2', | |
| 162 | 159 | }, common.mustCall(() => { | |
| 163 | 160 | assert.deepStrictEqual(client.getEphemeralKeyInfo(), { | |
| 164 | - type: undefined, | ||
| 165 | - name: undefined, | ||
| 161 | + type: 'TLSGroup', | ||
| 162 | + name: 'prime256v1', | ||
| 166 | 163 | size: undefined, | |
| 167 | 164 | }); | |
| 168 | 165 | server.close(); | |
@@ -337,7 +334,7 @@ module.exports = { | |||
| 337 | 334 | assertMultiKeyUnsupported, | |
| 338 | 335 | assertNoCipherMatch, | |
| 339 | 336 | assertOpenSSLSecurityLevelsUnsupported, | |
| 340 | - testEphemeralKeyInfoUnsupported, | ||
| 337 | + testEphemeralKeyInfo, | ||
| 341 | 338 | testLegacyProtocolUnsupported, | |
| 342 | 339 | testMultiPfxSelectionDifference, | |
| 343 | 340 | testPskTls13Unsupported, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,33 +35,33 @@ if (!process.features.openssl_is_boringssl) { | |||
| 35 | 35 | assert.strictEqual( | |
| 36 | 36 | crypto.createDiffieHellman(notSafePrime, Buffer.from([2])).verifyError, | |
| 37 | 37 | DH_CHECK_P_NOT_SAFE_PRIME); | |
| 38 | - | ||
| 39 | - const group = crypto.getDiffieHellman('modp14'); | ||
| 40 | - const alice = crypto.createDiffieHellman( | ||
| 41 | - group.getPrime(), group.getGenerator()); | ||
| 42 | - alice.generateKeys(); | ||
| 43 | - const groupPrime = BigInt(`0x${group.getPrime('hex')}`); | ||
| 44 | - assert.throws( | ||
| 45 | - () => alice.computeSecret(Buffer.from([1])), | ||
| 46 | - { | ||
| 47 | - code: 'ERR_CRYPTO_INVALID_KEYLEN', | ||
| 48 | - message: 'Supplied key is too small' | ||
| 49 | - }); | ||
| 50 | - assert.throws( | ||
| 51 | - () => alice.computeSecret(group.getPrime()), | ||
| 52 | - { | ||
| 53 | - code: 'ERR_CRYPTO_INVALID_KEYLEN', | ||
| 54 | - message: 'Supplied key is too large' | ||
| 55 | - }); | ||
| 56 | - assert.throws( | ||
| 57 | - () => alice.computeSecret( | ||
| 58 | - Buffer.from((groupPrime - 1n).toString(16), 'hex')), | ||
| 59 | - { | ||
| 60 | - code: 'ERR_CRYPTO_INVALID_KEYLEN', | ||
| 61 | - message: 'Supplied key is too large' | ||
| 62 | - }); | ||
| 63 | 38 | } | |
| 64 | 39 | ||
| 40 | + const group = crypto.getDiffieHellman('modp14'); | ||
| 41 | + const alice = crypto.createDiffieHellman( | ||
| 42 | + group.getPrime(), group.getGenerator()); | ||
| 43 | + alice.generateKeys(); | ||
| 44 | + const groupPrime = BigInt(`0x${group.getPrime('hex')}`); | ||
| 45 | + assert.throws( | ||
| 46 | + () => alice.computeSecret(Buffer.from([1])), | ||
| 47 | + { | ||
| 48 | + code: 'ERR_CRYPTO_INVALID_KEYLEN', | ||
| 49 | + message: 'Supplied key is too small' | ||
| 50 | + }); | ||
| 51 | + assert.throws( | ||
| 52 | + () => alice.computeSecret(group.getPrime()), | ||
| 53 | + { | ||
| 54 | + code: 'ERR_CRYPTO_INVALID_KEYLEN', | ||
| 55 | + message: 'Supplied key is too large' | ||
| 56 | + }); | ||
| 57 | + assert.throws( | ||
| 58 | + () => alice.computeSecret( | ||
| 59 | + Buffer.from((groupPrime - 1n).toString(16), 'hex')), | ||
| 60 | + { | ||
| 61 | + code: 'ERR_CRYPTO_INVALID_KEYLEN', | ||
| 62 | + message: 'Supplied key is too large' | ||
| 63 | + }); | ||
| 64 | + | ||
| 65 | 65 | // Confirm DH_check() results are exposed for optional examination. | |
| 66 | 66 | const bad_dh = process.features.openssl_is_boringssl ? | |
| 67 | 67 | crypto.createDiffieHellman('abcd', 'hex', 0) : | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,9 +93,7 @@ const { | |||
| 93 | 93 | { | |
| 94 | 94 | assert.throws(() => { | |
| 95 | 95 | dh3.computeSecret(''); | |
| 96 | - }, { message: process.features.openssl_is_boringssl ? | ||
| 97 | - 'Supplied key is invalid' : | ||
| 98 | - 'Supplied key is too small' }); | ||
| 96 | + }, { message: 'Supplied key is too small' }); | ||
| 99 | 97 | } | |
| 100 | 98 | } | |
| 101 | 99 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -376,25 +376,20 @@ const isBoringSSL = process.features.openssl_is_boringssl; | |||
| 376 | 376 | } | |
| 377 | 377 | ||
| 378 | 378 | // Test invalid exponents. (caught by OpenSSL) | |
| 379 | + let invalidExponentError = /bad e value/; | ||
| 380 | + if (isBoringSSL) { | ||
| 381 | + invalidExponentError = /BAD_E_VALUE/; | ||
| 382 | + } else if (hasOpenSSL3) { | ||
| 383 | + invalidExponentError = /exponent/; | ||
| 384 | + } | ||
| 379 | 385 | for (const publicExponent of [1, 1 + 0x10001]) { | |
| 380 | - if (isBoringSSL) { | ||
| 381 | - assert.throws(() => generateKeyPair('rsa', { | ||
| 382 | - modulusLength: 4096, | ||
| 383 | - publicExponent | ||
| 384 | - }, common.mustNotCall()), { | ||
| 385 | - name: 'RangeError', | ||
| 386 | - code: 'ERR_OUT_OF_RANGE', | ||
| 387 | - message: 'publicExponent is invalid', | ||
| 388 | - }); | ||
| 389 | - } else { | ||
| 390 | - generateKeyPair('rsa', { | ||
| 391 | - modulusLength: 4096, | ||
| 392 | - publicExponent | ||
| 393 | - }, common.mustCall((err) => { | ||
| 394 | - assert.strictEqual(err.name, 'Error'); | ||
| 395 | - assert.match(err.message, hasOpenSSL3 ? /exponent/ : /bad e value/); | ||
| 396 | - })); | ||
| 397 | - } | ||
| 386 | + generateKeyPair('rsa', { | ||
| 387 | + modulusLength: 4096, | ||
| 388 | + publicExponent | ||
| 389 | + }, common.mustCall((err) => { | ||
| 390 | + assert.strictEqual(err.name, 'Error'); | ||
| 391 | + assert.match(err.message, invalidExponentError); | ||
| 392 | + })); | ||
| 398 | 393 | } | |
| 399 | 394 | } | |
| 400 | 395 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,4 +15,8 @@ const assert = require('assert'); | |||
| 15 | 15 | // This test simply validates that we can get some value for the secLevel | |
| 16 | 16 | // when needed by tests. | |
| 17 | 17 | const secLevel = require('internal/crypto/util').getOpenSSLSecLevel(); | |
| 18 | - assert.ok(secLevel >= 0 && secLevel <= 5); | ||
| 18 | + if (process.features.openssl_is_boringssl) { | ||
| 19 | + assert.strictEqual(secLevel, 0); | ||
| 20 | + } else { | ||
| 21 | + assert.ok(secLevel >= 0 && secLevel <= 5); | ||
| 22 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ if (!common.hasCrypto) | |||
| 4 | 4 | common.skip('missing crypto'); | |
| 5 | 5 | ||
| 6 | 6 | if (process.features.openssl_is_boringssl) { | |
| 7 | - require('../common/boringssl').testEphemeralKeyInfoUnsupported(); | ||
| 7 | + require('../common/boringssl').testEphemeralKeyInfo(); | ||
| 8 | 8 | return; | |
| 9 | 9 | } | |
| 10 | 10 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments