Skip to content

Commit 70a2145

Browse files
committed
fixup! crypto: add support for RSA-PSS keys
1 parent 42922a0 commit 70a2145

File tree

3 files changed

+21
-43
lines changed

3 files changed

+21
-43
lines changed

test/fixtures/test_unknown_privkey.pem

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/parallel/test-crypto-key-objects.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,6 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
180180
});
181181
}
182182

183-
{
184-
// This should not cause a crash: https://github.com/nodejs/node/pull/26786
185-
const pem = fixtures.readSync('test_unknown_privkey.pem', 'ascii');
186-
const key = createPrivateKey(pem);
187-
assert.strictEqual(key.asymmetricKeyType, undefined);
188-
}
189-
190183
[
191184
{ private: fixtures.readSync('test_ed25519_privkey.pem', 'ascii'),
192185
public: fixtures.readSync('test_ed25519_pubkey.pem', 'ascii'),

test/parallel/test-crypto-keygen.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const {
1212
generateKeyPair,
1313
generateKeyPairSync,
1414
publicEncrypt,
15-
privateDecrypt
15+
privateDecrypt,
16+
sign,
17+
verify
1618
} = require('crypto');
1719
const { promisify } = require('util');
1820

@@ -41,13 +43,24 @@ function testEncryptDecrypt(publicKey, privateKey) {
4143

4244
// Tests that a key pair can be used for signing / verification.
4345
function testSignVerify(publicKey, privateKey) {
44-
const message = 'Hello Node.js world!';
45-
const signature = createSign('SHA256').update(message)
46-
.sign(privateKey, 'hex');
47-
for (const key of [publicKey, privateKey]) {
48-
const okay = createVerify('SHA256').update(message)
49-
.verify(key, signature, 'hex');
50-
assert(okay);
46+
const message = Buffer.from('Hello Node.js world!');
47+
48+
function oldSign(algo, data, key) {
49+
return createSign(algo).update(data).sign(key);
50+
}
51+
52+
function oldVerify(algo, data, key, signature) {
53+
return createVerify(algo).update(data).verify(key, signature);
54+
}
55+
56+
for (const signFn of [sign, oldSign]) {
57+
const signature = signFn('SHA256', message, privateKey);
58+
for (const verifyFn of [verify, oldVerify]) {
59+
for (const key of [publicKey, privateKey]) {
60+
const okay = verifyFn('SHA256', message, key, signature);
61+
assert(okay);
62+
}
63+
}
5164
}
5265
}
5366

0 commit comments

Comments
 (0)