Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace node {
using ncrypto::ClearErrorOnReturn;
using ncrypto::EVPKeyPointer;
using ncrypto::KeyAlgorithm;
using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::StackOfX509;
Expand All @@ -49,6 +50,7 @@ using v8::Value;
namespace crypto {

SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length) {
MarkPopErrorOnReturn mark_pop_error_on_return;
return SSLSessionPointer(d2i_SSL_SESSION(nullptr, &buf, length));
}

Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-tls-socket-invalid-session.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');

const assert = require('assert');
const crypto = require('crypto');
const tls = require('tls');

// A session that fails to deserialize must not leave an error on the OpenSSL
// error queue for the next unrelated crypto operation to pick up.

const badKey = '-----BEGIN PRIVATE KEY-----\nAAAA\n-----END PRIVATE KEY-----';

function keyErrorCode() {
try {
crypto.createPrivateKey(badKey);
} catch (err) {
return err.code;
}
assert.fail('createPrivateKey() should have thrown');
}

const expected = keyErrorCode();
new tls.TLSSocket(null, { session: Buffer.from('invalid session') });
assert.strictEqual(keyErrorCode(), expected);
Loading