GeezerVison is showing github.com — crypto: return a clearer error when loading an unsupported pkcs12 · nodejs/node@a5984e4
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/crypto/crypto_context.cc +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1110,6 +1110,16 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) { |
1110 | 1110 | if (!ret) { |
1111 | 1111 | // TODO(@jasnell): Should this use ThrowCryptoError? |
1112 | 1112 | unsigned long err = ERR_get_error(); // NOLINT(runtime/int) |
| 1113 | + |
| 1114 | +#if OPENSSL_VERSION_MAJOR >= 3 |
| 1115 | + if (ERR_GET_REASON(err) == ERR_R_UNSUPPORTED) { |
| 1116 | + // OpenSSL's "unsupported" error without any context is very |
| 1117 | + // common and not very helpful, so we override it: |
| 1118 | + return THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION( |
| 1119 | + env, "Unsupported PKCS12 PFX data"); |
| 1120 | + } |
| 1121 | +#endif |
| 1122 | + |
1113 | 1123 | const char* str = ERR_reason_error_string(err); |
1114 | 1124 | str = str != nullptr ? str : "Unknown error"; |
1115 | 1125 |
|
|
Collapse file
Copy file name to clipboard Collapse file
Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +if (!common.hasCrypto) |
| 4 | + common.skip('missing crypto'); |
| 5 | +if (!common.hasOpenSSL3) |
| 6 | + common.skip('OpenSSL legacy failures are only testable with OpenSSL 3+'); |
| 7 | + |
| 8 | +const fixtures = require('../common/fixtures'); |
| 9 | + |
| 10 | +const { |
| 11 | + assert, connect, keys |
| 12 | +} = require(fixtures.path('tls-connect')); |
| 13 | + |
| 14 | +const legacyPfx = fixtures.readKey('legacy.pfx'); |
| 15 | + |
| 16 | +connect({ |
| 17 | + client: { |
| 18 | + pfx: legacyPfx, |
| 19 | + passphrase: 'legacy', |
| 20 | + rejectUnauthorized: false |
| 21 | + }, |
| 22 | + server: keys.agent1 |
| 23 | +}, common.mustCall((e, pair, cleanup) => { |
| 24 | + assert.strictEqual(e.code, 'ERR_CRYPTO_UNSUPPORTED_OPERATION'); |
| 25 | + assert.strictEqual(e.message, 'Unsupported PKCS12 PFX data'); |
| 26 | + cleanup(); |
| 27 | +})); |