From 969bd1eb7b56fda3573ad3d41745a491f2b06dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 16 Mar 2019 23:51:26 +0100 Subject: [PATCH] crypto: add support for RSA-PSS keys This commit adds support for RSA-PSS keys, including - KeyObjects of type rsa-pss, - key pair generation for RSA-PSS, and - signing and verification using RSA-PSS keys. PR-URL: https://github.com/nodejs/node/pull/26960 Reviewed-By: Sam Roberts Reviewed-By: Daniel Bevenius --- doc/api/crypto.md | 31 +++- lib/internal/crypto/keygen.js | 30 +++- lib/internal/crypto/sig.js | 12 +- src/env.h | 1 + src/node_crypto.cc | 159 +++++++++++++++--- src/node_crypto.h | 4 +- test/fixtures/keys/Makefile | 24 +++ test/fixtures/keys/rsa_pss_private_2048.pem | 28 +++ .../rsa_pss_private_2048_sha256_sha256_16.pem | 29 ++++ .../rsa_pss_private_2048_sha512_sha256_20.pem | 29 ++++ test/fixtures/keys/rsa_pss_public_2048.pem | 9 + .../rsa_pss_public_2048_sha256_sha256_16.pem | 10 ++ .../rsa_pss_public_2048_sha512_sha256_20.pem | 10 ++ test/fixtures/test_unknown_privkey.pem | 28 --- test/parallel/test-crypto-key-objects.js | 149 +++++++++++++++- test/parallel/test-crypto-keygen.js | 71 ++++++-- 16 files changed, 535 insertions(+), 89 deletions(-) create mode 100644 test/fixtures/keys/rsa_pss_private_2048.pem create mode 100644 test/fixtures/keys/rsa_pss_private_2048_sha256_sha256_16.pem create mode 100644 test/fixtures/keys/rsa_pss_private_2048_sha512_sha256_20.pem create mode 100644 test/fixtures/keys/rsa_pss_public_2048.pem create mode 100644 test/fixtures/keys/rsa_pss_public_2048_sha256_sha256_16.pem create mode 100644 test/fixtures/keys/rsa_pss_public_2048_sha512_sha256_20.pem delete mode 100644 test/fixtures/test_unknown_privkey.pem diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 4cacde0d8e9083..9ba401f15381ff 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1129,6 +1129,9 @@ passing keys as strings or `Buffer`s due to improved security features. * {string} -For asymmetric keys, this property represents the type of the embedded key -(`'rsa'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, `'x25519'` or `'x448'`). +For asymmetric keys, this property represents the type of the key. Supported key +types are: + +* `'rsa'` (OID 1.2.840.113549.1.1.1) +* `'rsa-pss'` (OID 1.2.840.113549.1.1.10) +* `'dsa'` (OID 1.2.840.10040.4.1) +* `'ec'` (OID 1.2.840.10045.2.1) +* `'x25519'` (OID 1.3.101.110) +* `'x448'` (OID 1.3.101.111) +* `'ed25519'` (OID 1.3.101.112) +* `'ed448'` (OID 1.3.101.113) + This property is `undefined` for unrecognized `KeyObject` types and symmetric keys. @@ -1271,6 +1284,9 @@ console.log(verify.verify(publicKey, signature));