1
1
#!/usr/bin/env node
2
2
3
- let fipsError : Error | undefined ;
4
3
function enableFipsIfRequested ( ) : void {
5
- if ( process . argv . includes ( "--tlsFIPSMode" ) ) {
6
- // FIPS mode should be enabled before we run any other code, including any dependencies.
7
- // We still wrap this into a function so we can also call it immediately after
8
- // entering the snapshot main function.
4
+ let fipsError : Error | undefined ;
5
+ const tlsFIPSMode = process . argv . includes ( "--tlsFIPSMode" ) ;
6
+
7
+ if ( tlsFIPSMode ) {
9
8
try {
10
9
// eslint-disable-next-line
11
10
require ( "crypto" ) . setFips ( 1 ) ;
12
11
} catch ( err : unknown ) {
13
12
fipsError ??= err as Error ;
14
13
}
15
14
}
15
+
16
+ if ( tlsFIPSMode ) {
17
+ if ( ! fipsError && ! crypto . getFips ( ) ) {
18
+ fipsError = new Error ( "FIPS mode not enabled despite requested due to unknown error." ) ;
19
+ }
20
+ }
21
+
22
+ if ( fipsError ) {
23
+ if ( process . config . variables . node_shared_openssl ) {
24
+ console . error (
25
+ "Could not enable FIPS mode. Please ensure that your system OpenSSL installation supports FIPS."
26
+ ) ;
27
+ } else {
28
+ console . error ( "Could not enable FIPS mode. This installation does not appear to support FIPS." ) ;
29
+ }
30
+ console . error ( "Error details:" ) ;
31
+ console . error ( fipsError ) ;
32
+ process . exit ( 1 ) ;
33
+ }
16
34
}
17
35
18
36
enableFipsIfRequested ( ) ;
@@ -28,7 +46,6 @@ import { systemCA } from "@mongodb-js/devtools-proxy-support";
28
46
async function main ( ) : Promise < void > {
29
47
systemCA ( ) . catch ( ( ) => undefined ) ; // load system CA asynchronously as in mongosh
30
48
31
- assertFIPSMode ( ) ;
32
49
assertHelpMode ( ) ;
33
50
assertVersionMode ( ) ;
34
51
@@ -105,27 +122,6 @@ main().catch((error: unknown) => {
105
122
process . exit ( 1 ) ;
106
123
} ) ;
107
124
108
- function assertFIPSMode ( ) : void | never {
109
- if ( config . tlsFIPSMode ) {
110
- if ( ! fipsError && ! crypto . getFips ( ) ) {
111
- fipsError = new Error ( "FIPS mode not enabled despite requested." ) ;
112
- }
113
- }
114
-
115
- if ( fipsError ) {
116
- if ( process . config . variables . node_shared_openssl ) {
117
- console . error (
118
- "Could not enable FIPS mode. Please ensure that your system OpenSSL installation supports FIPS."
119
- ) ;
120
- } else {
121
- console . error ( "Could not enable FIPS mode. This installation does not appear to support FIPS." ) ;
122
- }
123
- console . error ( "Error details:" ) ;
124
- console . error ( fipsError ) ;
125
- process . exit ( 1 ) ;
126
- }
127
- }
128
-
129
125
function assertHelpMode ( ) : void | never {
130
126
if ( config . help ) {
131
127
console . log ( "For usage information refer to the README.md:" ) ;
0 commit comments