45
45
#ifndef OPENSSL_NO_ENGINE
46
46
# include < openssl/engine.h>
47
47
#endif // !OPENSSL_NO_ENGINE
48
+
49
+ #ifdef OPENSSL_FIPS
50
+ # include < openssl/fips.h>
51
+ #endif // OPENSSL_FIPS
52
+
48
53
#include < openssl/evp.h>
49
54
#include < openssl/pem.h>
50
55
#include < openssl/x509v3.h>
@@ -183,6 +188,16 @@ static int PasswordCallback(char* buf, int size, int rwflag, void* u) {
183
188
return -1 ;
184
189
}
185
190
191
+ void TestFipsCrypto (const v8::FunctionCallbackInfo<v8::Value>& args) {
192
+ #ifdef OPENSSL_FIPS
193
+ const auto enabled = FIPS_selftest () ? 1 : 0 ;
194
+ #else // OPENSSL_FIPS
195
+ const auto enabled = 0 ;
196
+ #endif // OPENSSL_FIPS
197
+
198
+ args.GetReturnValue ().Set (enabled);
199
+ }
200
+
186
201
// Loads OpenSSL engine by engine id and returns it. The loaded engine
187
202
// gets a reference so remember the corresponding call to ENGINE_free.
188
203
// In case of error the appropriate js exception is scheduled
@@ -3618,12 +3633,10 @@ void CipherBase::Init(const char* cipher_type,
3618
3633
HandleScope scope (env ()->isolate ());
3619
3634
MarkPopErrorOnReturn mark_pop_error_on_return;
3620
3635
3621
- #ifdef NODE_FIPS_MODE
3622
3636
if (FIPS_mode ()) {
3623
3637
return env ()->ThrowError (
3624
3638
" crypto.createCipher() is not supported in FIPS mode." );
3625
3639
}
3626
- #endif // NODE_FIPS_MODE
3627
3640
3628
3641
const EVP_CIPHER* const cipher = EVP_get_cipherbyname (cipher_type);
3629
3642
if (cipher == nullptr )
@@ -3809,13 +3822,11 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len,
3809
3822
return false ;
3810
3823
}
3811
3824
3812
- #ifdef NODE_FIPS_MODE
3813
3825
// TODO(tniessen) Support CCM decryption in FIPS mode
3814
3826
if (mode == EVP_CIPH_CCM_MODE && kind_ == kDecipher && FIPS_mode ()) {
3815
3827
env ()->ThrowError (" CCM decryption not supported in FIPS mode" );
3816
3828
return false ;
3817
3829
}
3818
- #endif
3819
3830
3820
3831
// Tell OpenSSL about the desired length.
3821
3832
if (!EVP_CIPHER_CTX_ctrl (ctx_.get (), EVP_CTRL_AEAD_SET_TAG, auth_tag_len,
@@ -4690,7 +4701,6 @@ static AllocatedBuffer Node_SignFinal(Environment* env,
4690
4701
}
4691
4702
4692
4703
static inline bool ValidateDSAParameters (EVP_PKEY* key) {
4693
- #ifdef NODE_FIPS_MODE
4694
4704
/* Validate DSA2 parameters from FIPS 186-4 */
4695
4705
if (FIPS_mode () && EVP_PKEY_DSA == EVP_PKEY_base_id (key)) {
4696
4706
DSA* dsa = EVP_PKEY_get0_DSA (key);
@@ -4706,7 +4716,6 @@ static inline bool ValidateDSAParameters(EVP_PKEY* key) {
4706
4716
(L == 2048 && N == 256 ) ||
4707
4717
(L == 3072 && N == 256 );
4708
4718
}
4709
- #endif // NODE_FIPS_MODE
4710
4719
4711
4720
return true ;
4712
4721
}
@@ -6866,7 +6875,6 @@ void InitCryptoOnce() {
6866
6875
settings = nullptr ;
6867
6876
#endif
6868
6877
6869
- #ifdef NODE_FIPS_MODE
6870
6878
/* Override FIPS settings in cnf file, if needed. */
6871
6879
unsigned long err = 0 ; // NOLINT(runtime/int)
6872
6880
if (per_process::cli_options->enable_fips_crypto ||
@@ -6881,7 +6889,6 @@ void InitCryptoOnce() {
6881
6889
ERR_error_string (err, nullptr ));
6882
6890
UNREACHABLE ();
6883
6891
}
6884
- #endif // NODE_FIPS_MODE
6885
6892
6886
6893
6887
6894
// Turn off compression. Saves memory and protects against CRIME attacks.
@@ -6927,7 +6934,6 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) {
6927
6934
}
6928
6935
#endif // !OPENSSL_NO_ENGINE
6929
6936
6930
- #ifdef NODE_FIPS_MODE
6931
6937
void GetFipsCrypto (const FunctionCallbackInfo<Value>& args) {
6932
6938
args.GetReturnValue ().Set (FIPS_mode () ? 1 : 0 );
6933
6939
}
@@ -6945,7 +6951,6 @@ void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
6945
6951
return ThrowCryptoError (env, err);
6946
6952
}
6947
6953
}
6948
- #endif /* NODE_FIPS_MODE */
6949
6954
6950
6955
namespace {
6951
6956
// SecureBuffer uses openssl to allocate a Uint8Array using
@@ -7013,10 +7018,9 @@ void Initialize(Local<Object> target,
7013
7018
env->SetMethod (target, " setEngine" , SetEngine);
7014
7019
#endif // !OPENSSL_NO_ENGINE
7015
7020
7016
- #ifdef NODE_FIPS_MODE
7017
7021
env->SetMethodNoSideEffect (target, " getFipsCrypto" , GetFipsCrypto);
7018
7022
env->SetMethod (target, " setFipsCrypto" , SetFipsCrypto);
7019
- # endif
7023
+ env-> SetMethodNoSideEffect (target, " testFipsCrypto " , TestFipsCrypto);
7020
7024
7021
7025
env->SetMethod (target, " pbkdf2" , PBKDF2);
7022
7026
env->SetMethod (target, " generateKeyPairRSA" , GenerateKeyPairRSA);
0 commit comments