Skip to content

Commit c95bf72

Browse files
committed
chore: enable FIPS before doing anything else
1 parent 09da3b8 commit c95bf72

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#!/usr/bin/env node
22

3+
let fipsError: Error | undefined;
4+
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.
9+
try {
10+
// eslint-disable-next-line
11+
require("crypto").setFips(1);
12+
} catch (err: unknown) {
13+
fipsError ??= err as Error;
14+
}
15+
}
16+
}
17+
18+
enableFipsIfRequested();
19+
320
import { ConsoleLogger, LogId } from "./common/logger.js";
421
import { config } from "./common/config.js";
522
import crypto from "crypto";
@@ -89,7 +106,6 @@ main().catch((error: unknown) => {
89106
});
90107

91108
function assertFIPSMode(): void | never {
92-
let fipsError: Error | undefined = undefined;
93109
if (config.tlsFIPSMode) {
94110
if (!fipsError && !crypto.getFips()) {
95111
fipsError = new Error("FIPS mode not enabled despite requested.");

0 commit comments

Comments
 (0)