Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: return a clearer error when loading an unsupported pkcs12 #54485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,16 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
if (!ret) {
// TODO(@jasnell): Should this use ThrowCryptoError?
unsigned long err = ERR_get_error(); // NOLINT(runtime/int)

#if OPENSSL_VERSION_MAJOR >= 3
if (ERR_GET_REASON(err) == ERR_R_UNSUPPORTED) {
// OpenSSL's "unsupported" error without any context is very
// common and not very helpful, so we override it:
return THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(
env, "Unsupported PKCS12 PFX data");
}
#endif

const char* str = ERR_reason_error_string(err);
str = str != nullptr ? str : "Unknown error";

Expand Down
Binary file added test/fixtures/keys/legacy.pfx
Binary file not shown.
27 changes: 27 additions & 0 deletions test/parallel/test-tls-legacy-pfx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasOpenSSL3)
common.skip('OpenSSL legacy failures are only testable with OpenSSL 3+');

const fixtures = require('../common/fixtures');

const {
assert, connect, keys
} = require(fixtures.path('tls-connect'));

const legacyPfx = fixtures.readKey('legacy.pfx');

connect({
client: {
pfx: legacyPfx,
passphrase: 'legacy',
rejectUnauthorized: false
},
server: keys.agent1
}, common.mustCall((e, pair, cleanup) => {
assert.strictEqual(e.code, 'ERR_CRYPTO_UNSUPPORTED_OPERATION');
assert.strictEqual(e.message, 'Unsupported PKCS12 PFX data');
cleanup();
}));
Loading