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
18 changes: 9 additions & 9 deletions test/parallel/test-crypto-async-sign-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ if (!process.features.openssl_is_boringssl) {
// ECDSA w/ ieee-p1363 signature encoding
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384', false,
{ dsaEncoding: 'ieee-p1363' });
}

// DSA w/ der signature encoding
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
false);
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
false, { dsaEncoding: 'der' });
// DSA w/ der signature encoding
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
false);
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
false, { dsaEncoding: 'der' });

// DSA w/ ieee-p1363 signature encoding
test('dsa_public.pem', 'dsa_private.pem', 'sha256', false,
{ dsaEncoding: 'ieee-p1363' });
// DSA w/ ieee-p1363 signature encoding
test('dsa_public.pem', 'dsa_private.pem', 'sha256', false,
{ dsaEncoding: 'ieee-p1363' });
}

// Test Parallel Execution w/ KeyObject is threadsafe in openssl3
{
Expand Down
45 changes: 28 additions & 17 deletions test/parallel/test-crypto-authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,22 +626,27 @@ for (const test of TEST_CASES) {

{
// CCM cipher without data should not crash, see https://github.com/nodejs/node/issues/38035.
const algo = 'aes-128-ccm';
const key = Buffer.alloc(16);
const iv = Buffer.alloc(12);
const opts = { authTagLength: 10 };
if (!ciphers.includes('aes-128-ccm')) {
common.printSkipMessage(`unsupported aes-128-ccm test`);
} else {
const key = Buffer.alloc(16);
const iv = Buffer.alloc(12);
const opts = { authTagLength: 10 };

const cipher = crypto.createCipheriv(algo, key, iv, opts);
assert.throws(() => {
cipher.final();
}, hasOpenSSL3 ? {
code: 'ERR_OSSL_TAG_NOT_SET'
} : {
message: /Unsupported state/
});
const cipher = crypto.createCipheriv('aes-128-ccm', key, iv, opts);
assert.throws(() => {
cipher.final();
}, hasOpenSSL3 ? {
code: 'ERR_OSSL_TAG_NOT_SET'
} : {
message: /Unsupported state/
});
}
}

{
if (process.features.openssl_is_boringssl) {
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
} else {
const key = Buffer.alloc(32);
const iv = Buffer.alloc(12);

Expand All @@ -657,13 +662,15 @@ for (const test of TEST_CASES) {

// ChaCha20-Poly1305 should respect the authTagLength option and should not
// require the authentication tag before calls to update() during decryption.
{
if (process.features.openssl_is_boringssl) {
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
} else {
const key = Buffer.alloc(32);
const iv = Buffer.alloc(12);

for (let authTagLength = 1; authTagLength <= 16; authTagLength++) {
const cipher =
crypto.createCipheriv('chacha20-poly1305', key, iv, { authTagLength });
crypto.createCipheriv('chacha20-poly1305', key, iv, { authTagLength });
const ciphertext = Buffer.concat([cipher.update('foo'), cipher.final()]);
const authTag = cipher.getAuthTag();
assert.strictEqual(authTag.length, authTagLength);
Expand Down Expand Up @@ -706,7 +713,9 @@ for (const test of TEST_CASES) {
// shorter tags as long as their length was valid according to NIST SP 800-38D.
// For ChaCha20-Poly1305, we intentionally deviate from that because there are
// no recommended or approved authentication tag lengths below 16 bytes.
{
if (process.features.openssl_is_boringssl) {
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
} else {
const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
return algo === 'chacha20-poly1305' && tampered === false;
});
Expand Down Expand Up @@ -743,7 +752,9 @@ for (const test of TEST_CASES) {
}

// https://github.com/nodejs/node/issues/45874
{
if (process.features.openssl_is_boringssl) {
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
} else {
const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
return algo === 'chacha20-poly1305' && tampered === false;
});
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-crypto-default-shake-lengths-oneshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

if (process.features.openssl_is_boringssl) {
common.skip('Skipping unsupported shake128 digest method test');
}

const { hash } = require('crypto');

common.expectWarning({
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-crypto-dh-curves.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
crypto.createDiffieHellman(p, 'hex');

// Confirm DH_check() results are exposed for optional examination.
const bad_dh = crypto.createDiffieHellman('02', 'hex');
const bad_dh = crypto.createDiffieHellman('abcd', 'hex', 0);
assert.notStrictEqual(bad_dh.verifyError, 0);

const availableCurves = new Set(crypto.getCurves());
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-crypto-dh-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ assert.throws(() => crypto.createDiffieHellman('abcdef', 13.37), {
for (const bits of [-1, 0, 1]) {
if (hasOpenSSL3) {
assert.throws(() => crypto.createDiffieHellman(bits), {
code: 'ERR_OSSL_DH_MODULUS_TOO_SMALL',
code: /ERR_OSSL_(BN_BITS|DH_MODULUS)_TOO_SMALL/,
name: 'Error',
message: /modulus too small/,
});
} else {
assert.throws(() => crypto.createDiffieHellman(bits), {
code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
code: /ERR_OSSL_(BN_BITS|DH_MODULUS)_TOO_SMALL/,
name: 'Error',
message: /bits[\s_]too[\s_]small/i,
});
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-crypto-dh-group-setters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if (!common.hasCrypto)
const assert = require('assert');
const crypto = require('crypto');

if (process.features.openssl_is_boringssl) {
common.skip('Skipping unsupported Diffie-Hellman tests');
}

// Unlike DiffieHellman, DiffieHellmanGroup does not have any setters.
const dhg = crypto.getDiffieHellman('modp1');
assert.strictEqual(dhg.constructor, crypto.DiffieHellmanGroup);
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-crypto-dh-modp2-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const assert = require('assert');
const crypto = require('crypto');
const { modp2buf } = require('../common/crypto');

if (process.features.openssl_is_boringssl) {
common.skip('Skipping unsupported Diffie-Hellman tests');
}

const modp2 = crypto.createDiffieHellmanGroup('modp2');

const views = common.getArrayBufferViews(modp2buf);
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-crypto-dh-modp2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ if (!common.hasCrypto)
const assert = require('assert');
const crypto = require('crypto');
const { modp2buf } = require('../common/crypto');

if (process.features.openssl_is_boringssl) {
common.skip('Skipping unsupported Diffie-Hellman tests');
}

const modp2 = crypto.createDiffieHellmanGroup('modp2');

{
Expand Down
10 changes: 7 additions & 3 deletions test/parallel/test-crypto-dh.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,21 @@ const {
dh3.computeSecret('');
}, { message: hasOpenSSL3 && !hasOpenSSL3WithNewErrorMessage ?
'Unspecified validation error' :
'Supplied key is too small' });
/Supplied key is (too small|invalid)/ });
}
}

// Through a fluke of history, g=0 defaults to DH_GENERATOR (2).
{
if (!process.features.openssl_is_boringssl) {
const g = 0;
crypto.createDiffieHellman('abcdef', g);
crypto.createDiffieHellman('abcdef', 'hex', g);
} else {
common.printSkipMessage('Skipping unsupported g=0 Diffie-Hellman tests');
}

{
if (!process.features.openssl_is_boringssl) {
crypto.createDiffieHellman('abcdef', Buffer.from([2])); // OK
} else {
common.printSkipMessage('Skipping unsupported g=0 Diffie-Hellman tests');
}
10 changes: 5 additions & 5 deletions test/parallel/test-crypto-hash-stream-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const crypto = require('crypto');

const stream = require('stream');
const s = new stream.PassThrough();
const h = crypto.createHash('sha3-512');
const expect = '36a38a2a35e698974d4e5791a3f05b05' +
'198235381e864f91a0e8cd6a26b677ec' +
'dcde8e2b069bd7355fabd68abd6fc801' +
'19659f25e92f8efc961ee3a7c815c758';
const h = crypto.createHash('sha512');
const expect = 'fba055c6fd0c5b6645407749ed7a8b41' +
'b8f629f2163c3ca3701d864adabda1f8' +
'93c37bf82b22fdd151ba8e357f611da4' +
'88a74b6a5525dd9b69554c6ce5138ad7';

s.pipe(h).on('data', common.mustCall(function(c) {
assert.strictEqual(c, expect);
Expand Down
15 changes: 13 additions & 2 deletions test/parallel/test-crypto-key-objects-to-crypto-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ function assertCryptoKey(cryptoKey, keyObject, algorithm, extractable, usages) {
{
for (const length of [128, 192, 256]) {
const key = createSecretKey(randomBytes(length >> 3));
const algorithms = ['AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-KW'];
let algorithms = ['AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-KW'];
if (length === 256)
algorithms.push('ChaCha20-Poly1305');

if (process.features.openssl_is_boringssl) {
algorithms = algorithms.filter((a) => a !== 'AES-KW' && a !== 'ChaCha20-Poly1305');
}

for (const algorithm of algorithms) {
const usages = algorithm === 'AES-KW' ? ['wrapKey', 'unwrapKey'] : ['encrypt', 'decrypt'];
for (const extractable of [true, false]) {
Expand Down Expand Up @@ -97,7 +102,13 @@ function assertCryptoKey(cryptoKey, keyObject, algorithm, extractable, usages) {
}

{
for (const algorithm of ['Ed25519', 'Ed448', 'X25519', 'X448']) {
const algorithms = ['Ed25519', 'X25519'];

if (!process.features.openssl_is_boringssl) {
algorithms.push('X448', 'Ed448');
}

for (const algorithm of algorithms) {
const { publicKey, privateKey } = generateKeyPairSync(algorithm.toLowerCase());
assert.throws(() => {
publicKey.toCryptoKey(algorithm === 'Ed25519' ? 'X25519' : 'Ed25519', true, []);
Expand Down
Loading
Loading