GeezerVison is showing github.com — crypto: support FIPS mode of OpenSSL · nodejs/node@282d4c9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: common.gypi +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 38 | 38 | 'OBJ_DIR': '<(PRODUCT_DIR)/obj.target', | 39 | 39 | 'V8_BASE': '<(PRODUCT_DIR)/obj.target/deps/v8/tools/gyp/libv8_base.a', | 40 | 40 | }], | | 41 | + ['openssl_fips != ""', { | | 42 | + 'OPENSSL_PRODUCT': 'libcrypto.a', | | 43 | + }, { | | 44 | + 'OPENSSL_PRODUCT': 'libopenssl.a', | | 45 | + }], | 41 | 46 | ['OS=="mac"', { | 42 | 47 | 'clang%': 1, | 43 | 48 | }, { | |
Collapse file Copy file name to clipboardExpand all lines: configure +27-1Lines changed: 27 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -88,6 +88,11 @@ parser.add_option("--openssl-no-asm", | 88 | 88 | dest="openssl_no_asm", | 89 | 89 | help="Do not build optimized assembly for OpenSSL") | 90 | 90 |
| | 91 | +parser.add_option("--openssl-fips", | | 92 | + action="store", | | 93 | + dest="openssl_fips", | | 94 | + help="Build OpenSSL using FIPS canister .o file in supplied folder") | | 95 | + | 91 | 96 | shared_optgroup.add_option('--shared-http-parser', | 92 | 97 | action='store_true', | 93 | 98 | dest='shared_http_parser', | @@ -720,6 +725,16 @@ def configure_openssl(o): | 720 | 725 | o['variables']['node_use_openssl'] = b(not options.without_ssl) | 721 | 726 | o['variables']['node_shared_openssl'] = b(options.shared_openssl) | 722 | 727 | o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0 | | 728 | + if options.openssl_fips: | | 729 | + o['variables']['openssl_fips'] = options.openssl_fips | | 730 | + fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips') | | 731 | + fips_ld = os.path.abspath(os.path.join(fips_dir, 'fipsld')) | | 732 | + o['make_global_settings'] = [ | | 733 | + ['LINK', fips_ld + ' <(openssl_fips)/bin/fipsld'], | | 734 | + ] | | 735 | + else: | | 736 | + o['variables']['openssl_fips'] = '' | | 737 | + | 723 | 738 |
| 724 | 739 | if options.without_ssl: | 725 | 740 | return | @@ -1025,10 +1040,21 @@ configure_fullystatic(output) | 1025 | 1040 | # move everything else to target_defaults | 1026 | 1041 | variables = output['variables'] | 1027 | 1042 | del output['variables'] | | 1043 | + | | 1044 | +# make_global_settings should be a root level element too | | 1045 | +if 'make_global_settings' in output: | | 1046 | + make_global_settings = output['make_global_settings'] | | 1047 | + del output['make_global_settings'] | | 1048 | +else: | | 1049 | + make_global_settings = False | | 1050 | + | 1028 | 1051 | output = { | 1029 | 1052 | 'variables': variables, | 1030 | | - 'target_defaults': output | | 1053 | + 'target_defaults': output, | 1031 | 1054 | } | | 1055 | +if make_global_settings: | | 1056 | + output['make_global_settings'] = make_global_settings | | 1057 | + | 1032 | 1058 | pprint.pprint(output, indent=2) | 1033 | 1059 |
| 1034 | 1060 | write('config.gypi', do_not_edit + | |
Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Building io.js with FIPS-compliant OpenSSL | | 2 | + | | 3 | +It is possible to build io.js with [OpenSSL FIPS module][0]. | | 4 | + | | 5 | +Instructions: | | 6 | + | | 7 | +1. Download and verify `openssl-fips-x.x.x.tar.gz` from | | 8 | + https://www.openssl.org/source/ | | 9 | +2. Extract source to `openssl-fips` folder | | 10 | +3. ``cd openssl-fips && ./config fipscanisterbuild --prefix=`pwd`/out`` | | 11 | + (NOTE: On OS X, you may want to run | | 12 | + ``./Configure darwin64-x86_64-cc --prefix=`pwd`/out`` if you are going to | | 13 | + build x64-mode io.js) | | 14 | +4. `make -j && make install` | | 15 | +5. Get into io.js checkout folder | | 16 | +6. `./configure --openssl-fips=/path/to/openssl-fips/out` | | 17 | +7. Build io.js with `make -j` | | 18 | + | | 19 | +[0]: https://www.openssl.org/docs/fips/fipsnotes.html |
Collapse file Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#!/bin/sh | | 2 | +ARGS= | | 3 | + | | 4 | +while [ "x$1" != "x" ]; do | | 5 | + ARG=$1 | | 6 | + shift | | 7 | + case $ARG in | | 8 | + *fips_premain.c) ARGS="$ARGS -x c $ARG -x none";; | | 9 | + *) ARGS="$ARGS $ARG";; | | 10 | + esac | | 11 | +done | | 12 | + | | 13 | +echo $CXX $ARGS | | 14 | +${CXX} $ARGS |
Collapse file Copy file name to clipboard +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#!/bin/sh | | 2 | + | | 3 | +# NOTE: Just a wrapper around normal fipsld | | 4 | +FIPSLD=$1 | | 5 | +shift | | 6 | + | | 7 | +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | | 8 | +FIPSLD_CC=$DIR/fipscc $FIPSLD $@ |
Collapse file Copy file name to clipboardExpand all lines: deps/openssl/openssl.gyp +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | 'openssl_no_asm%': 0, | 10 | 10 | 'llvm_version%': 0, | 11 | 11 | 'gas_version%': 0, | | 12 | + 'openssl_fips%': 'false', | 12 | 13 | }, | 13 | 14 | 'targets': [ | 14 | 15 | { | | 21 | 22 | ['exclude', 'store/.*$'] | 22 | 23 | ], | 23 | 24 | 'conditions': [ | | 25 | + # FIPS | | 26 | + ['openssl_fips != ""', { | | 27 | + 'defines': [ | | 28 | + 'OPENSSL_FIPS', | | 29 | + ], | | 30 | + 'include_dirs': [ | | 31 | + '<(openssl_fips)/include', | | 32 | + ], | | 33 | + | | 34 | + # Trick fipsld, it expects to see libcrypto.a | | 35 | + 'product_name': 'crypto', | | 36 | + | | 37 | + 'direct_dependent_settings': { | | 38 | + 'defines': [ | | 39 | + 'OPENSSL_FIPS', | | 40 | + ], | | 41 | + 'include_dirs': [ | | 42 | + '<(openssl_fips)/include', | | 43 | + ], | | 44 | + }, | | 45 | + }], | | 46 | + | 24 | 47 | ['openssl_no_asm!=0', { | 25 | 48 | # Disable asm | 26 | 49 | 'defines': [ | |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 233 | 233 | [ 'node_target_type!="static_library"', { | 234 | 234 | 'xcode_settings': { | 235 | 235 | 'OTHER_LDFLAGS': [ | 236 | | - '-Wl,-force_load,<(PRODUCT_DIR)/libopenssl.a', | | 236 | + '-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)', | 237 | 237 | ], | 238 | 238 | }, | 239 | 239 | 'conditions': [ | 240 | 240 | ['OS in "linux freebsd"', { | 241 | 241 | 'ldflags': [ | 242 | | - '-Wl,--whole-archive <(PRODUCT_DIR)/libopenssl.a', | | 242 | + '-Wl,--whole-archive <(PRODUCT_DIR)/<(OPENSSL_PRODUCT)', | 243 | 243 | '-Wl,--no-whole-archive', | 244 | 244 | ], | 245 | 245 | }], | |
Collapse file Copy file name to clipboardExpand all lines: src/node_crypto.cc +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5071,6 +5071,16 @@ void InitCryptoOnce() { | 5071 | 5071 | CRYPTO_set_locking_callback(crypto_lock_cb); | 5072 | 5072 | CRYPTO_THREADID_set_callback(crypto_threadid_cb); | 5073 | 5073 |
| | 5074 | +#ifdef OPENSSL_FIPS | | 5075 | + if (!FIPS_mode_set(1)) { | | 5076 | + int r; | | 5077 | + r = ERR_get_error(); | | 5078 | + fprintf(stderr, "openssl fips failed: %s\n", ERR_error_string(r, NULL)); | | 5079 | + UNREACHABLE(); | | 5080 | + } | | 5081 | +#endif // OPENSSL_FIPS | | 5082 | + | | 5083 | + | 5074 | 5084 | // Turn off compression. Saves memory and protects against CRIME attacks. | 5075 | 5085 | #if !defined(OPENSSL_NO_COMP) | 5076 | 5086 | #if OPENSSL_VERSION_NUMBER < 0x00908000L | |
|