Skip to content

Commit

Permalink
fixup! crypto: add support for RSA-PSS keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tniessen committed Apr 1, 2019
1 parent 42922a0 commit 70a2145
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 43 deletions.
28 changes: 0 additions & 28 deletions test/fixtures/test_unknown_privkey.pem

This file was deleted.

7 changes: 0 additions & 7 deletions test/parallel/test-crypto-key-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,6 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
});
}

{
// This should not cause a crash: https://github.com/nodejs/node/pull/26786
const pem = fixtures.readSync('test_unknown_privkey.pem', 'ascii');
const key = createPrivateKey(pem);
assert.strictEqual(key.asymmetricKeyType, undefined);
}

[
{ private: fixtures.readSync('test_ed25519_privkey.pem', 'ascii'),
public: fixtures.readSync('test_ed25519_pubkey.pem', 'ascii'),
Expand Down
29 changes: 21 additions & 8 deletions test/parallel/test-crypto-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const {
generateKeyPair,
generateKeyPairSync,
publicEncrypt,
privateDecrypt
privateDecrypt,
sign,
verify
} = require('crypto');
const { promisify } = require('util');

Expand Down Expand Up @@ -41,13 +43,24 @@ function testEncryptDecrypt(publicKey, privateKey) {

// Tests that a key pair can be used for signing / verification.
function testSignVerify(publicKey, privateKey) {
const message = 'Hello Node.js world!';
const signature = createSign('SHA256').update(message)
.sign(privateKey, 'hex');
for (const key of [publicKey, privateKey]) {
const okay = createVerify('SHA256').update(message)
.verify(key, signature, 'hex');
assert(okay);
const message = Buffer.from('Hello Node.js world!');

function oldSign(algo, data, key) {
return createSign(algo).update(data).sign(key);
}

function oldVerify(algo, data, key, signature) {
return createVerify(algo).update(data).verify(key, signature);
}

for (const signFn of [sign, oldSign]) {
const signature = signFn('SHA256', message, privateKey);
for (const verifyFn of [verify, oldVerify]) {
for (const key of [publicKey, privateKey]) {
const okay = verifyFn('SHA256', message, key, signature);
assert(okay);
}
}
}
}

Expand Down

0 comments on commit 70a2145

Please sign in to comment.