| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a0f7ae6 commit ee76f31
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -643,6 +643,17 @@ Used when an invalid value for the `format` argument has been passed to the | |||
| 643 | 643 | Used when an invalid crypto engine identifier is passed to | |
| 644 | 644 | [`require('crypto').setEngine()`][]. | |
| 645 | 645 | ||
| 646 | + <a id="ERR_CRYPTO_FIPS_FORCED"></a> | ||
| 647 | + ### ERR_CRYPTO_FIPS_FORCED | ||
| 648 | + | ||
| 649 | + Used when trying to enable or disable FIPS mode in the crypto module and | ||
| 650 | + the [`--force-fips`][] command-line argument is used. | ||
| 651 | + | ||
| 652 | + <a id="ERR_CRYPTO_FIPS_UNAVAILABLE"></a> | ||
| 653 | + ### ERR_CRYPTO_FIPS_UNAVAILABLE | ||
| 654 | + | ||
| 655 | + Used when trying to enable or disable FIPS mode when FIPS is not available. | ||
| 656 | + | ||
| 646 | 657 | <a id="ERR_CRYPTO_HASH_DIGEST_NO_UTF16"></a> | |
| 647 | 658 | ### ERR_CRYPTO_HASH_DIGEST_NO_UTF16 | |
| 648 | 659 | ||
@@ -1440,6 +1451,7 @@ Used when a given value is out of the accepted range. | |||
| 1440 | 1451 | Used when an attempt is made to use a `zlib` object after it has already been | |
| 1441 | 1452 | closed. | |
| 1442 | 1453 | ||
| 1454 | + [`--force-fips`]: cli.html#cli_force_fips | ||
| 1443 | 1455 | [`crypto.timingSafeEqual()`]: crypto.html#crypto_crypto_timingsafeequal_a_b | |
| 1444 | 1456 | [`dgram.createSocket()`]: dgram.html#dgram_dgram_createsocket_options_callback | |
| 1445 | 1457 | [`ERR_INVALID_ARG_TYPE`]: #ERR_INVALID_ARG_TYPE | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,12 @@ const { | |||
| 30 | 30 | } = require('internal/util'); | |
| 31 | 31 | assertCrypto(); | |
| 32 | 32 | ||
| 33 | + const errors = require('internal/errors'); | ||
| 33 | 34 | const constants = process.binding('constants').crypto; | |
| 35 | + const { | ||
| 36 | + fipsMode, | ||
| 37 | + fipsForced | ||
| 38 | + } = process.binding('config'); | ||
| 34 | 39 | const { | |
| 35 | 40 | getFipsCrypto, | |
| 36 | 41 | setFipsCrypto, | |
@@ -173,10 +178,29 @@ module.exports = exports = { | |||
| 173 | 178 | Verify | |
| 174 | 179 | }; | |
| 175 | 180 | ||
| 181 | + function setFipsDisabled() { | ||
| 182 | + throw new errors.Error('ERR_CRYPTO_FIPS_UNAVAILABLE'); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + function setFipsForced(val) { | ||
| 186 | + if (val) return; | ||
| 187 | + throw new errors.Error('ERR_CRYPTO_FIPS_FORCED'); | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + function getFipsDisabled() { | ||
| 191 | + return 0; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + function getFipsForced() { | ||
| 195 | + return 1; | ||
| 196 | + } | ||
| 197 | + | ||
| 176 | 198 | Object.defineProperties(exports, { | |
| 177 | 199 | fips: { | |
| 178 | - get: getFipsCrypto, | ||
| 179 | - set: setFipsCrypto | ||
| 200 | + get: !fipsMode ? getFipsDisabled : | ||
| 201 | + fipsForced ? getFipsForced : getFipsCrypto, | ||
| 202 | + set: !fipsMode ? setFipsDisabled : | ||
| 203 | + fipsForced ? setFipsForced : setFipsCrypto | ||
| 180 | 204 | }, | |
| 181 | 205 | DEFAULT_ENCODING: { | |
| 182 | 206 | enumerable: true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,6 +156,9 @@ E('ERR_CONSOLE_WRITABLE_STREAM', | |||
| 156 | 156 | E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s'); | |
| 157 | 157 | E('ERR_CRYPTO_ECDH_INVALID_FORMAT', 'Invalid ECDH format: %s'); | |
| 158 | 158 | E('ERR_CRYPTO_ENGINE_UNKNOWN', 'Engine "%s" was not found'); | |
| 159 | + E('ERR_CRYPTO_FIPS_FORCED', | ||
| 160 | + 'Cannot set FIPS mode, it was forced with --force-fips at startup.'); | ||
| 161 | + E('ERR_CRYPTO_FIPS_UNAVAILABLE', 'Cannot set FIPS mode in a non-FIPS build.'); | ||
| 159 | 162 | E('ERR_CRYPTO_HASH_DIGEST_NO_UTF16', 'hash.digest() does not support UTF-16'); | |
| 160 | 163 | E('ERR_CRYPTO_HASH_FINALIZED', 'Digest already called'); | |
| 161 | 164 | E('ERR_CRYPTO_HASH_UPDATE_FAILED', 'Hash update failed'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,12 @@ static void InitConfig(Local<Object> target, | |||
| 44 | 44 | Environment* env = Environment::GetCurrent(context); | |
| 45 | 45 | Isolate* isolate = env->isolate(); | |
| 46 | 46 | ||
| 47 | + #ifdef NODE_FIPS_MODE | ||
| 48 | + READONLY_BOOLEAN_PROPERTY("fipsMode"); | ||
| 49 | + if (force_fips_crypto) | ||
| 50 | + READONLY_BOOLEAN_PROPERTY("fipsForced"); | ||
| 51 | + #endif | ||
| 52 | + | ||
| 47 | 53 | #ifdef NODE_HAVE_I18N_SUPPORT | |
| 48 | 54 | ||
| 49 | 55 | READONLY_BOOLEAN_PROPERTY("hasIntl"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5946,32 +5946,24 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) { | |||
| 5946 | 5946 | } | |
| 5947 | 5947 | #endif // !OPENSSL_NO_ENGINE | |
| 5948 | 5948 | ||
| 5949 | + #ifdef NODE_FIPS_MODE | ||
| 5949 | 5950 | void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | |
| 5950 | - if (FIPS_mode()) { | ||
| 5951 | - args.GetReturnValue().Set(1); | ||
| 5952 | - } else { | ||
| 5953 | - args.GetReturnValue().Set(0); | ||
| 5954 | - } | ||
| 5951 | + args.GetReturnValue().Set(FIPS_mode() ? 1 : 0); | ||
| 5955 | 5952 | } | |
| 5956 | 5953 | ||
| 5957 | 5954 | void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | |
| 5955 | + CHECK(!force_fips_crypto); | ||
| 5958 | 5956 | Environment* env = Environment::GetCurrent(args); | |
| 5959 | - #ifdef NODE_FIPS_MODE | ||
| 5960 | 5957 | const bool enabled = FIPS_mode(); | |
| 5961 | 5958 | const bool enable = args[0]->BooleanValue(); | |
| 5962 | 5959 | if (enable == enabled) | |
| 5963 | 5960 | return; // No action needed. | |
| 5964 | - if (force_fips_crypto) { | ||
| 5965 | - return env->ThrowError( | ||
| 5966 | - "Cannot set FIPS mode, it was forced with --force-fips at startup."); | ||
| 5967 | - } else if (!FIPS_mode_set(enable)) { | ||
| 5961 | + if (!FIPS_mode_set(enable)) { | ||
| 5968 | 5962 | unsigned long err = ERR_get_error(); // NOLINT(runtime/int) | |
| 5969 | 5963 | return ThrowCryptoError(env, err); | |
| 5970 | 5964 | } | |
| 5971 | - #else | ||
| 5972 | - return env->ThrowError("Cannot set FIPS mode in a non-FIPS build."); | ||
| 5973 | - #endif /* NODE_FIPS_MODE */ | ||
| 5974 | 5965 | } | |
| 5966 | + #endif /* NODE_FIPS_MODE */ | ||
| 5975 | 5967 | ||
| 5976 | 5968 | void InitCrypto(Local<Object> target, | |
| 5977 | 5969 | Local<Value> unused, | |
@@ -5997,8 +5989,12 @@ void InitCrypto(Local<Object> target, | |||
| 5997 | 5989 | #ifndef OPENSSL_NO_ENGINE | |
| 5998 | 5990 | env->SetMethod(target, "setEngine", SetEngine); | |
| 5999 | 5991 | #endif // !OPENSSL_NO_ENGINE | |
| 5992 | + | ||
| 5993 | + #ifdef NODE_FIPS_MODE | ||
| 6000 | 5994 | env->SetMethod(target, "getFipsCrypto", GetFipsCrypto); | |
| 6001 | 5995 | env->SetMethod(target, "setFipsCrypto", SetFipsCrypto); | |
| 5996 | + #endif | ||
| 5997 | + | ||
| 6002 | 5998 | env->SetMethod(target, "PBKDF2", PBKDF2); | |
| 6003 | 5999 | env->SetMethod(target, "randomBytes", RandomBytes); | |
| 6004 | 6000 | env->SetMethod(target, "randomFill", RandomBytesBuffer); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,12 @@ const fixtures = require('../common/fixtures'); | |||
| 10 | 10 | ||
| 11 | 11 | const FIPS_ENABLED = 1; | |
| 12 | 12 | const FIPS_DISABLED = 0; | |
| 13 | - const FIPS_ERROR_STRING = 'Error: Cannot set FIPS mode'; | ||
| 13 | + const FIPS_ERROR_STRING = | ||
| 14 | + 'Error [ERR_CRYPTO_FIPS_UNAVAILABLE]: Cannot set FIPS mode in a ' + | ||
| 15 | + 'non-FIPS build.'; | ||
| 16 | + const FIPS_ERROR_STRING2 = | ||
| 17 | + 'Error [ERR_CRYPTO_FIPS_FORCED]: Cannot set FIPS mode, it was forced with ' + | ||
| 18 | + '--force-fips at startup.'; | ||
| 14 | 19 | const OPTION_ERROR_STRING = 'bad option'; | |
| 15 | 20 | ||
| 16 | 21 | const CNF_FIPS_ON = fixtures.path('openssl_fips_enabled.cnf'); | |
@@ -208,7 +213,7 @@ testHelper( | |||
| 208 | 213 | testHelper( | |
| 209 | 214 | 'stderr', | |
| 210 | 215 | ['--force-fips'], | |
| 211 | - compiledWithFips() ? FIPS_ERROR_STRING : OPTION_ERROR_STRING, | ||
| 216 | + compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING, | ||
| 212 | 217 | 'require("crypto").fips = false', | |
| 213 | 218 | process.env); | |
| 214 | 219 | ||
@@ -225,14 +230,14 @@ testHelper( | |||
| 225 | 230 | testHelper( | |
| 226 | 231 | 'stderr', | |
| 227 | 232 | ['--force-fips', '--enable-fips'], | |
| 228 | - compiledWithFips() ? FIPS_ERROR_STRING : OPTION_ERROR_STRING, | ||
| 233 | + compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING, | ||
| 229 | 234 | 'require("crypto").fips = false', | |
| 230 | 235 | process.env); | |
| 231 | 236 | ||
| 232 | 237 | //--enable-fips and --force-fips order does not matter | |
| 233 | 238 | testHelper( | |
| 234 | 239 | 'stderr', | |
| 235 | 240 | ['--enable-fips', '--force-fips'], | |
| 236 | - compiledWithFips() ? FIPS_ERROR_STRING : OPTION_ERROR_STRING, | ||
| 241 | + compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING, | ||
| 237 | 242 | 'require("crypto").fips = false', | |
| 238 | 243 | process.env); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments