summaryrefslogtreecommitdiff
path: root/src/node_crypto.cc
diff options
context:
space:
mode:
authorStefan Budeanu <stefan@budeanu.com>2015-11-10 11:50:32 -0500
committerJames M Snell <jasnell@gmail.com>2015-11-14 07:53:35 -0800
commit4adaaa4897487db6de74be5b35577b843882f6c9 (patch)
tree90d8b142307f0ba6571ec0e24241a3d074a426dd /src/node_crypto.cc
parent70405d47c374bab6510e27732f0b5019668574d0 (diff)
downloadnode-new-4adaaa4897487db6de74be5b35577b843882f6c9.tar.gz
crypto: DSA parameter validation in FIPS mode
FIPS 180-4 requires specific (L,N) values. OpenSSL will crash if an invalid combination is used, so we must check the input sanity first. PR-URL: https://github.com/nodejs/node/pull/3756 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r--src/node_crypto.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index f0569eb354..f699ef8222 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3781,6 +3781,29 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
if (pkey == nullptr || 0 != ERR_peek_error())
goto exit;
+#ifdef NODE_FIPS_MODE
+ /* Validate DSA2 parameters from FIPS 186-4 */
+ if (EVP_PKEY_DSA == pkey->type) {
+ size_t L = BN_num_bits(pkey->pkey.dsa->p);
+ size_t N = BN_num_bits(pkey->pkey.dsa->q);
+ bool result = false;
+
+ if (L == 1024 && N == 160)
+ result = true;
+ else if (L == 2048 && N == 224)
+ result = true;
+ else if (L == 2048 && N == 256)
+ result = true;
+ else if (L == 3072 && N == 256)
+ result = true;
+
+ if (!result) {
+ fatal = true;
+ goto exit;
+ }
+ }
+#endif // NODE_FIPS_MODE
+
if (EVP_SignFinal(&mdctx_, *sig, sig_len, pkey))
fatal = false;