Skip to content

Commit 12cbfbb

Browse files
committed
test,crypto: handle a few more BoringSSL tests
1 parent 0d128e3 commit 12cbfbb

9 files changed

+53
-50
lines changed

test/parallel/test-crypto-async-sign-verify.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,21 @@ test('rsa_public.pem', 'rsa_private.pem', 'sha256', false,
8888

8989
// ED25519
9090
test('ed25519_public.pem', 'ed25519_private.pem', undefined, true);
91-
// ED448
92-
test('ed448_public.pem', 'ed448_private.pem', undefined, true);
9391

94-
// ECDSA w/ der signature encoding
95-
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
96-
false);
97-
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
98-
false, { dsaEncoding: 'der' });
92+
if (!process.features.openssl_is_boringssl) {
93+
// ED448
94+
test('ed448_public.pem', 'ed448_private.pem', undefined, true);
9995

100-
// ECDSA w/ ieee-p1363 signature encoding
101-
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384', false,
102-
{ dsaEncoding: 'ieee-p1363' });
96+
// ECDSA w/ der signature encoding
97+
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
98+
false);
99+
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
100+
false, { dsaEncoding: 'der' });
101+
102+
// ECDSA w/ ieee-p1363 signature encoding
103+
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384', false,
104+
{ dsaEncoding: 'ieee-p1363' });
105+
}
103106

104107
// DSA w/ der signature encoding
105108
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
@@ -150,7 +153,10 @@ MCowBQYDK2VuAyEA6pwGRbadNQAI/tYN8+/p/0/hbsdHfOEGr1ADiLVk/Gc=
150153
const data = crypto.randomBytes(32);
151154
const signature = crypto.randomBytes(16);
152155

153-
const expected = hasOpenSSL3 ? /operation not supported for this keytype/ : /no default digest/;
156+
let expected = /no default digest/;
157+
if (hasOpenSSL3 || !process.features.openssl_is_boringssl) {
158+
expected = /operation[\s_]not[\s_]supported[\s_]for[\s_]this[\s_]keytype/i;
159+
}
154160

155161
crypto.verify(undefined, data, untrustedKey, signature, common.mustCall((err) => {
156162
assert.ok(err);
@@ -164,6 +170,6 @@ MCowBQYDK2VuAyEA6pwGRbadNQAI/tYN8+/p/0/hbsdHfOEGr1ADiLVk/Gc=
164170
});
165171
crypto.sign('sha512', 'message', privateKey, common.mustCall((err) => {
166172
assert.ok(err);
167-
assert.match(err.message, /digest too big for rsa key/);
173+
assert.match(err.message, /digest[\s_]too[\s_]big[\s_]for[\s_]rsa[\s_]key/i);
168174
}));
169175
}

test/parallel/test-crypto-certificate.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function copyArrayBuffer(buf) {
4141

4242
function checkMethods(certificate) {
4343

44-
assert.strictEqual(certificate.verifySpkac(spkacValid), true);
44+
if (!process.features.openssl_is_boringssl)
45+
assert.strictEqual(certificate.verifySpkac(spkacValid), true);
4546
assert.strictEqual(certificate.verifySpkac(spkacFail), false);
4647

4748
assert.strictEqual(
@@ -56,10 +57,12 @@ function checkMethods(certificate) {
5657
);
5758
assert.strictEqual(certificate.exportChallenge(spkacFail), '');
5859

59-
const ab = copyArrayBuffer(spkacValid);
60-
assert.strictEqual(certificate.verifySpkac(ab), true);
61-
assert.strictEqual(certificate.verifySpkac(new Uint8Array(ab)), true);
62-
assert.strictEqual(certificate.verifySpkac(new DataView(ab)), true);
60+
if (!process.features.openssl_is_boringssl) {
61+
const ab = copyArrayBuffer(spkacValid);
62+
assert.strictEqual(certificate.verifySpkac(ab), true);
63+
assert.strictEqual(certificate.verifySpkac(new Uint8Array(ab)), true);
64+
assert.strictEqual(certificate.verifySpkac(new DataView(ab)), true);
65+
}
6366
}
6467

6568
{

test/parallel/test-crypto-dh-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ for (const bits of [-1, 0, 1]) {
3535
assert.throws(() => crypto.createDiffieHellman(bits), {
3636
code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
3737
name: 'Error',
38-
message: /bits too small/,
38+
message: /bits[\s_]too[\s_]small/i,
3939
});
4040
}
4141
}

test/parallel/test-crypto-dh.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,17 @@ const {
6060
let wrongBlockLength;
6161
if (hasOpenSSL3) {
6262
wrongBlockLength = {
63-
message: 'error:1C80006B:Provider routines::wrong final block length',
64-
code: 'ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH',
65-
library: 'Provider routines',
66-
reason: 'wrong final block length'
63+
message: /wrong[\s_]final[\s_]block[\s_]length/i,
64+
code: /ERR_OSSL_(EVP_)?WRONG_FINAL_BLOCK_LENGTH/,
65+
library: /Provider routines|Cipher functions/,
66+
reason: /wrong[\s_]final[\s_]block[\s_]length/i,
6767
};
6868
} else {
6969
wrongBlockLength = {
70-
message: 'error:0606506D:digital envelope' +
71-
' routines:EVP_DecryptFinal_ex:wrong final block length',
72-
code: 'ERR_OSSL_EVP_WRONG_FINAL_BLOCK_LENGTH',
73-
library: 'digital envelope routines',
74-
reason: 'wrong final block length'
70+
message: /wrong[\s_]final[\s_]block[\s_]length/i,
71+
code: /ERR_OSSL_(EVP_)?WRONG_FINAL_BLOCK_LENGTH/,
72+
library: /digital envelope routines|Cipher functions/,
73+
reason: /wrong[\s_]final[\s_]block[\s_]length/i,
7574
};
7675
}
7776

test/parallel/test-crypto-hash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ assert.throws(
182182
}
183183

184184
// Test XOF hash functions and the outputLength option.
185-
{
185+
if (!process.features.openssl_is_boringssl) {
186186
// Default outputLengths.
187187
assert.strictEqual(crypto.createHash('shake128').digest('hex'),
188188
'7f9c2ba4e88f827d616045507605853e');

test/parallel/test-crypto-padding.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,13 @@ assert.throws(function() {
8484
// Input must have block length %.
8585
enc(ODD_LENGTH_PLAIN, false);
8686
}, hasOpenSSL3 ? {
87-
message: 'error:1C80006B:Provider routines::wrong final block length',
88-
code: 'ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH',
89-
reason: 'wrong final block length',
87+
message: /wrong[\s_]final[\s_]block[\s_]length/i,
88+
code: /ERR_OSSL(_EVP)?_WRONG_FINAL_BLOCK_LENGTH/,
89+
message: /wrong[\s_]final[\s_]block[\s_]length/i,
9090
} : {
91-
message: 'error:0607F08A:digital envelope routines:EVP_EncryptFinal_ex:' +
92-
'data not multiple of block length',
93-
code: 'ERR_OSSL_EVP_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH',
94-
reason: 'data not multiple of block length',
91+
message: /data[\s_]not[\s_]multiple[\s_]of[\s_]block[\s_]length/i,
92+
code: /ERR_OSSL(_EVP)?_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH/,
93+
reason: /data[\s_]not[\s_]multiple[\s_]of[\s_]block[\s_]length/i,
9594
}
9695
);
9796

@@ -110,15 +109,10 @@ assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48);
110109
assert.throws(function() {
111110
// Must have at least 1 byte of padding (PKCS):
112111
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN);
113-
}, hasOpenSSL3 ? {
114-
message: 'error:1C800064:Provider routines::bad decrypt',
115-
reason: 'bad decrypt',
116-
code: 'ERR_OSSL_BAD_DECRYPT',
117-
} : {
118-
message: 'error:06065064:digital envelope routines:EVP_DecryptFinal_ex:' +
119-
'bad decrypt',
120-
reason: 'bad decrypt',
121-
code: 'ERR_OSSL_EVP_BAD_DECRYPT',
112+
}, {
113+
message: /bad[\s_]decrypt/i,
114+
reason: /bad[\s_]decrypt/i,
115+
code: /ERR_OSSL(_EVP)?_BAD_DECRYPT/,
122116
});
123117

124118
// No-pad encrypted string should return the same:

test/parallel/test-crypto-stream.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ const cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
7373
const decipher = crypto.createDecipheriv('aes-128-cbc', badkey, iv);
7474

7575
cipher.pipe(decipher)
76-
.on('error', common.expectsError(hasOpenSSL3 ? {
77-
message: /bad[\s_]decrypt/,
78-
library: 'Provider routines',
76+
.on('error', common.expectsError((hasOpenSSL3 || process.features.openssl_is_boringssl) ? {
77+
message: /bad[\s_]decrypt/i,
78+
library: /Provider routines|Cipher functions/,
7979
reason: /bad[\s_]decrypt/i,
8080
} : {
8181
message: /bad[\s_]decrypt/i,

test/parallel/test-tls-alert-handling.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const errorHandler = common.mustCall((err) => {
4343

4444
assert.strictEqual(err.code, expectedErrorCode);
4545
assert.strictEqual(err.library, 'SSL routines');
46-
if (!hasOpenSSL3) assert.strictEqual(err.function, 'ssl3_get_record');
46+
if (!hasOpenSSL3 && !process.features.openssl_is_boringssl)
47+
assert.strictEqual(err.function, 'ssl3_get_record');
4748
assert.match(err.reason, expectedErrorReason);
4849
errorReceived = true;
4950
if (canCloseServer())
@@ -105,7 +106,7 @@ function sendBADTLSRecord() {
105106
}
106107
assert.strictEqual(err.code, expectedErrorCode);
107108
assert.strictEqual(err.library, 'SSL routines');
108-
if (!hasOpenSSL3)
109+
if (!hasOpenSSL3 && !process.features.openssl_is_boringssl)
109110
assert.strictEqual(err.function, 'ssl3_read_bytes');
110111
assert.match(err.reason, expectedErrorReason);
111112
}));

test/parallel/test-x509-escaping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ const { hasOpenSSL3 } = require('../common/crypto');
438438
const cert = fixtures.readKey('incorrect_san_correct_subject-cert.pem');
439439

440440
// The hostname is the CN, but not a SAN entry.
441-
const servername = 'good.example.com';
441+
const servername = process.features.openssl_is_boringssl ? undefined : 'good.example.com';
442442
const certX509 = new X509Certificate(cert);
443443
assert.strictEqual(certX509.subject, `CN=${servername}`);
444444
assert.strictEqual(certX509.subjectAltName, 'DNS:evil.example.com');

0 commit comments

Comments
 (0)