| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2c36596 commit 0d448ea
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,8 +201,8 @@ priority than `--dns-result-order`. | |||
| 201 | 201 | added: v6.0.0 | |
| 202 | 202 | --> | |
| 203 | 203 | ||
| 204 | - Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with | ||
| 205 | - `./configure --openssl-fips`.) | ||
| 204 | + Enable FIPS-compliant crypto at startup. (Requires Node.js to be built | ||
| 205 | + against FIPS-compatible OpenSSL.) | ||
| 206 | 206 | ||
| 207 | 207 | ### `--enable-source-maps` | |
| 208 | 208 | <!-- YAML | |
@@ -623,8 +623,8 @@ added: v6.9.0 | |||
| 623 | 623 | --> | |
| 624 | 624 | ||
| 625 | 625 | Load an OpenSSL configuration file on startup. Among other uses, this can be | |
| 626 | - used to enable FIPS-compliant crypto if Node.js is built with | ||
| 627 | - `./configure --openssl-fips`. | ||
| 626 | + used to enable FIPS-compliant crypto if Node.js is built | ||
| 627 | + against FIPS-enabled OpenSSL. | ||
| 628 | 628 | ||
| 629 | 629 | ### `--pending-deprecation` | |
| 630 | 630 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,12 +37,10 @@ assertCrypto(); | |||
| 37 | 37 | ||
| 38 | 38 | const { | |
| 39 | 39 | ERR_CRYPTO_FIPS_FORCED, | |
| 40 | - ERR_CRYPTO_FIPS_UNAVAILABLE | ||
| 41 | 40 | } = require('internal/errors').codes; | |
| 42 | 41 | const constants = internalBinding('constants').crypto; | |
| 43 | 42 | const { getOptionValue } = require('internal/options'); | |
| 44 | 43 | const pendingDeprecation = getOptionValue('--pending-deprecation'); | |
| 45 | - const { fipsMode } = internalBinding('config'); | ||
| 46 | 44 | const fipsForced = getOptionValue('--force-fips'); | |
| 47 | 45 | const { | |
| 48 | 46 | getFipsCrypto, | |
@@ -193,10 +191,8 @@ module.exports = { | |||
| 193 | 191 | sign: signOneShot, | |
| 194 | 192 | setEngine, | |
| 195 | 193 | timingSafeEqual, | |
| 196 | - getFips: !fipsMode ? getFipsDisabled : | ||
| 197 | - fipsForced ? getFipsForced : getFipsCrypto, | ||
| 198 | - setFips: !fipsMode ? setFipsDisabled : | ||
| 199 | - fipsForced ? setFipsForced : setFipsCrypto, | ||
| 194 | + getFips: fipsForced ? getFipsForced : getFipsCrypto, | ||
| 195 | + setFips: fipsForced ? setFipsForced : setFipsCrypto, | ||
| 200 | 196 | verify: verifyOneShot, | |
| 201 | 197 | ||
| 202 | 198 | // Classes | |
@@ -215,19 +211,11 @@ module.exports = { | |||
| 215 | 211 | Verify | |
| 216 | 212 | }; | |
| 217 | 213 | ||
| 218 | - function setFipsDisabled() { | ||
| 219 | - throw new ERR_CRYPTO_FIPS_UNAVAILABLE(); | ||
| 220 | - } | ||
| 221 | - | ||
| 222 | 214 | function setFipsForced(val) { | |
| 223 | 215 | if (val) return; | |
| 224 | 216 | throw new ERR_CRYPTO_FIPS_FORCED(); | |
| 225 | 217 | } | |
| 226 | 218 | ||
| 227 | - function getFipsDisabled() { | ||
| 228 | - return 0; | ||
| 229 | - } | ||
| 230 | - | ||
| 231 | 219 | function getFipsForced() { | |
| 232 | 220 | return 1; | |
| 233 | 221 | } | |
@@ -249,10 +237,8 @@ ObjectDefineProperties(module.exports, { | |||
| 249 | 237 | }, | |
| 250 | 238 | // crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips() | |
| 251 | 239 | fips: { | |
| 252 | - get: !fipsMode ? getFipsDisabled : | ||
| 253 | - fipsForced ? getFipsForced : getFipsCrypto, | ||
| 254 | - set: !fipsMode ? setFipsDisabled : | ||
| 255 | - fipsForced ? setFipsForced : setFipsCrypto | ||
| 240 | + get: fipsForced ? getFipsForced : getFipsCrypto, | ||
| 241 | + set: fipsForced ? setFipsForced : setFipsCrypto | ||
| 256 | 242 | }, | |
| 257 | 243 | DEFAULT_ENCODING: { | |
| 258 | 244 | enumerable: false, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,9 +319,6 @@ | |||
| 319 | 319 | [ 'node_use_openssl=="true"', { | |
| 320 | 320 | 'defines': [ 'HAVE_OPENSSL=1' ], | |
| 321 | 321 | 'conditions': [ | |
| 322 | - ['openssl_fips != "" or openssl_is_fips=="true"', { | ||
| 323 | - 'defines': [ 'NODE_FIPS_MODE' ], | ||
| 324 | - }], | ||
| 325 | 322 | [ 'node_shared_openssl=="false"', { | |
| 326 | 323 | 'dependencies': [ | |
| 327 | 324 | './deps/openssl/openssl.gyp:openssl', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1040,11 +1040,11 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) { | |||
| 1040 | 1040 | if (credentials::SafeGetenv("NODE_EXTRA_CA_CERTS", &extra_ca_certs)) | |
| 1041 | 1041 | crypto::UseExtraCaCerts(extra_ca_certs); | |
| 1042 | 1042 | } | |
| 1043 | - #ifdef NODE_FIPS_MODE | ||
| 1044 | 1043 | // In the case of FIPS builds we should make sure | |
| 1045 | 1044 | // the random source is properly initialized first. | |
| 1046 | - OPENSSL_init(); | ||
| 1047 | - #endif // NODE_FIPS_MODE | ||
| 1045 | + if (FIPS_mode()) { | ||
| 1046 | + OPENSSL_init(); | ||
| 1047 | + } | ||
| 1048 | 1048 | // V8 on Windows doesn't have a good source of entropy. Seed it from | |
| 1049 | 1049 | // OpenSSL's pool. | |
| 1050 | 1050 | V8::SetEntropySource(crypto::EntropySource); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,9 +42,7 @@ static void Initialize(Local<Object> target, | |||
| 42 | 42 | READONLY_FALSE_PROPERTY(target, "hasOpenSSL"); | |
| 43 | 43 | #endif // HAVE_OPENSSL | |
| 44 | 44 | ||
| 45 | - #ifdef NODE_FIPS_MODE | ||
| 46 | 45 | READONLY_TRUE_PROPERTY(target, "fipsMode"); | |
| 47 | - #endif | ||
| 48 | 46 | ||
| 49 | 47 | #ifdef NODE_HAVE_I18N_SUPPORT | |
| 50 | 48 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,11 @@ | |||
| 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> | |
@@ -98,6 +103,7 @@ using v8::ReadOnly; | |||
| 98 | 103 | using v8::SideEffectType; | |
| 99 | 104 | using v8::Signature; | |
| 100 | 105 | using v8::String; | |
| 106 | + using v8::TryCatch; | ||
| 101 | 107 | using v8::Uint32; | |
| 102 | 108 | using v8::Uint8Array; | |
| 103 | 109 | using v8::Undefined; | |
@@ -183,6 +189,16 @@ static int PasswordCallback(char* buf, int size, int rwflag, void* u) { | |||
| 183 | 189 | return -1; | |
| 184 | 190 | } | |
| 185 | 191 | ||
| 192 | + void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
| 193 | + #ifdef OPENSSL_FIPS | ||
| 194 | + const auto enabled = FIPS_selftest() ? 1 : 0; | ||
| 195 | + #else // OPENSSL_FIPS | ||
| 196 | + const auto enabled = 0; | ||
| 197 | + #endif // OPENSSL_FIPS | ||
| 198 | + | ||
| 199 | + args.GetReturnValue().Set(enabled); | ||
| 200 | + } | ||
| 201 | + | ||
| 186 | 202 | // Loads OpenSSL engine by engine id and returns it. The loaded engine | |
| 187 | 203 | // gets a reference so remember the corresponding call to ENGINE_free. | |
| 188 | 204 | // In case of error the appropriate js exception is scheduled | |
@@ -3618,12 +3634,10 @@ void CipherBase::Init(const char* cipher_type, | |||
| 3618 | 3634 | HandleScope scope(env()->isolate()); | |
| 3619 | 3635 | MarkPopErrorOnReturn mark_pop_error_on_return; | |
| 3620 | 3636 | ||
| 3621 | - #ifdef NODE_FIPS_MODE | ||
| 3622 | 3637 | if (FIPS_mode()) { | |
| 3623 | 3638 | return env()->ThrowError( | |
| 3624 | 3639 | "crypto.createCipher() is not supported in FIPS mode."); | |
| 3625 | 3640 | } | |
| 3626 | - #endif // NODE_FIPS_MODE | ||
| 3627 | 3641 | ||
| 3628 | 3642 | const EVP_CIPHER* const cipher = EVP_get_cipherbyname(cipher_type); | |
| 3629 | 3643 | if (cipher == nullptr) | |
@@ -3809,13 +3823,11 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len, | |||
| 3809 | 3823 | return false; | |
| 3810 | 3824 | } | |
| 3811 | 3825 | ||
| 3812 | - #ifdef NODE_FIPS_MODE | ||
| 3813 | 3826 | // TODO(tniessen) Support CCM decryption in FIPS mode | |
| 3814 | 3827 | if (mode == EVP_CIPH_CCM_MODE && kind_ == kDecipher && FIPS_mode()) { | |
| 3815 | 3828 | env()->ThrowError("CCM decryption not supported in FIPS mode"); | |
| 3816 | 3829 | return false; | |
| 3817 | 3830 | } | |
| 3818 | - #endif | ||
| 3819 | 3831 | ||
| 3820 | 3832 | // Tell OpenSSL about the desired length. | |
| 3821 | 3833 | if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len, | |
@@ -4690,7 +4702,6 @@ static AllocatedBuffer Node_SignFinal(Environment* env, | |||
| 4690 | 4702 | } | |
| 4691 | 4703 | ||
| 4692 | 4704 | static inline bool ValidateDSAParameters(EVP_PKEY* key) { | |
| 4693 | - #ifdef NODE_FIPS_MODE | ||
| 4694 | 4705 | /* Validate DSA2 parameters from FIPS 186-4 */ | |
| 4695 | 4706 | if (FIPS_mode() && EVP_PKEY_DSA == EVP_PKEY_base_id(key)) { | |
| 4696 | 4707 | DSA* dsa = EVP_PKEY_get0_DSA(key); | |
@@ -4706,7 +4717,6 @@ static inline bool ValidateDSAParameters(EVP_PKEY* key) { | |||
| 4706 | 4717 | (L == 2048 && N == 256) || | |
| 4707 | 4718 | (L == 3072 && N == 256); | |
| 4708 | 4719 | } | |
| 4709 | - #endif // NODE_FIPS_MODE | ||
| 4710 | 4720 | ||
| 4711 | 4721 | return true; | |
| 4712 | 4722 | } | |
@@ -6866,7 +6876,6 @@ void InitCryptoOnce() { | |||
| 6866 | 6876 | settings = nullptr; | |
| 6867 | 6877 | #endif | |
| 6868 | 6878 | ||
| 6869 | - #ifdef NODE_FIPS_MODE | ||
| 6870 | 6879 | /* Override FIPS settings in cnf file, if needed. */ | |
| 6871 | 6880 | unsigned long err = 0; // NOLINT(runtime/int) | |
| 6872 | 6881 | if (per_process::cli_options->enable_fips_crypto || | |
@@ -6876,12 +6885,10 @@ void InitCryptoOnce() { | |||
| 6876 | 6885 | } | |
| 6877 | 6886 | } | |
| 6878 | 6887 | if (0 != err) { | |
| 6879 | - fprintf(stderr, | ||
| 6880 | - "openssl fips failed: %s\n", | ||
| 6881 | - ERR_error_string(err, nullptr)); | ||
| 6882 | - UNREACHABLE(); | ||
| 6888 | + auto* isolate = Isolate::GetCurrent(); | ||
| 6889 | + auto* env = Environment::GetCurrent(isolate); | ||
| 6890 | + return ThrowCryptoError(env, err); | ||
| 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 | |
@@ -6981,10 +6986,16 @@ void Initialize(Local<Object> target, | |||
| 6981 | 6986 | Local<Value> unused, | |
| 6982 | 6987 | Local<Context> context, | |
| 6983 | 6988 | void* priv) { | |
| 6989 | + Environment* env = Environment::GetCurrent(context); | ||
| 6984 | 6990 | static uv_once_t init_once = UV_ONCE_INIT; | |
| 6991 | + TryCatch try_catch{env->isolate()}; | ||
| 6985 | 6992 | uv_once(&init_once, InitCryptoOnce); | |
| 6986 | 6993 | ||
| 6987 | - Environment* env = Environment::GetCurrent(context); | ||
| 6994 | + if (try_catch.HasCaught() && !try_catch.HasTerminated()) { | ||
| 6995 | + try_catch.ReThrow(); | ||
| 6996 | + return; | ||
| 6997 | + } | ||
| 6998 | + | ||
| 6988 | 6999 | SecureContext::Initialize(env, target); | |
| 6989 | 7000 | target->Set(env->context(), | |
| 6990 | 7001 | FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"), | |
@@ -7013,10 +7024,9 @@ void Initialize(Local<Object> target, | |||
| 7013 | 7024 | env->SetMethod(target, "setEngine", SetEngine); | |
| 7014 | 7025 | #endif // !OPENSSL_NO_ENGINE | |
| 7015 | 7026 | ||
| 7016 | - #ifdef NODE_FIPS_MODE | ||
| 7017 | 7027 | env->SetMethodNoSideEffect(target, "getFipsCrypto", GetFipsCrypto); | |
| 7018 | 7028 | env->SetMethod(target, "setFipsCrypto", SetFipsCrypto); | |
| 7019 | - #endif | ||
| 7029 | + env->SetMethodNoSideEffect(target, "testFipsCrypto", TestFipsCrypto); | ||
| 7020 | 7030 | ||
| 7021 | 7031 | env->SetMethod(target, "pbkdf2", PBKDF2); | |
| 7022 | 7032 | env->SetMethod(target, "generateKeyPairRSA", GenerateKeyPairRSA); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -766,7 +766,6 @@ PerProcessOptionsParser::PerProcessOptionsParser( | |||
| 766 | 766 | &PerProcessOptions::ssl_openssl_cert_store); | |
| 767 | 767 | Implies("--use-openssl-ca", "[ssl_openssl_cert_store]"); | |
| 768 | 768 | ImpliesNot("--use-bundled-ca", "[ssl_openssl_cert_store]"); | |
| 769 | - #if NODE_FIPS_MODE | ||
| 770 | 769 | AddOption("--enable-fips", | |
| 771 | 770 | "enable FIPS crypto at startup", | |
| 772 | 771 | &PerProcessOptions::enable_fips_crypto, | |
@@ -775,7 +774,6 @@ PerProcessOptionsParser::PerProcessOptionsParser( | |||
| 775 | 774 | "force FIPS crypto (cannot be disabled)", | |
| 776 | 775 | &PerProcessOptions::force_fips_crypto, | |
| 777 | 776 | kAllowedInEnvironment); | |
| 778 | - #endif | ||
| 779 | 777 | #endif | |
| 780 | 778 | AddOption("--use-largepages", | |
| 781 | 779 | "Map the Node.js static code to large pages. Options are " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,10 +245,8 @@ class PerProcessOptions : public Options { | |||
| 245 | 245 | #endif | |
| 246 | 246 | bool use_openssl_ca = false; | |
| 247 | 247 | bool use_bundled_ca = false; | |
| 248 | - #if NODE_FIPS_MODE | ||
| 249 | 248 | bool enable_fips_crypto = false; | |
| 250 | 249 | bool force_fips_crypto = false; | |
| 251 | - #endif | ||
| 252 | 250 | #endif | |
| 253 | 251 | ||
| 254 | 252 | // Per-process because reports can be triggered outside a known V8 context. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,8 +8,6 @@ const common = require('../common'); | |||
| 8 | 8 | ||
| 9 | 9 | const assert = require('assert'); | |
| 10 | 10 | const { exec } = require('child_process'); | |
| 11 | - const { internalBinding } = require('internal/test/binding'); | ||
| 12 | - const { fipsMode } = internalBinding('config'); | ||
| 13 | 11 | let stdOut; | |
| 14 | 12 | ||
| 15 | 13 | ||
@@ -28,9 +26,8 @@ function validateNodePrintHelp() { | |||
| 28 | 26 | const cliHelpOptions = [ | |
| 29 | 27 | { compileConstant: HAVE_OPENSSL, | |
| 30 | 28 | flags: [ '--openssl-config=...', '--tls-cipher-list=...', | |
| 31 | - '--use-bundled-ca', '--use-openssl-ca' ] }, | ||
| 32 | - { compileConstant: fipsMode, | ||
| 33 | - flags: [ '--enable-fips', '--force-fips' ] }, | ||
| 29 | + '--use-bundled-ca', '--use-openssl-ca', | ||
| 30 | + '--enable-fips', '--force-fips' ] }, | ||
| 34 | 31 | { compileConstant: NODE_HAVE_I18N_SUPPORT, | |
| 35 | 32 | flags: [ '--icu-data-dir=...', 'NODE_ICU_DATA' ] }, | |
| 36 | 33 | { compileConstant: HAVE_INSPECTOR, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments