MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / checkMfaKeyDecodable

Function checkMfaKeyDecodable

apps/api/src/boot/invariants.ts:35–57  ·  view source on GitHub ↗

* Verify the MFA encryption key, if set, will actually drive AES-256-GCM. * Empty is allowed (the env validator already requires non-empty in * production, dev/test can opt out of MFA entirely).

(env: Env)

Source from the content-addressed store, hash-verified

33 * Empty is allowed (the env validator already requires non-empty in
34 * production, dev/test can opt out of MFA entirely).
35 */
36function checkMfaKeyDecodable(env: Env): string[] {
37 if (env.MFA_ENCRYPTION_KEY === "") {
38 return [];
39 }
40
41 let decoded: Buffer;
42
43 try {
44 decoded = Buffer.from(env.MFA_ENCRYPTION_KEY, "base64");
45 } catch {
46 return [
47 "MFA_ENCRYPTION_KEY is not valid base64. Regenerate with `openssl rand -base64 32`.",
48 ];
49 }
50
51 if (decoded.length !== AES_256_KEY_BYTES) {
52 return [
53 `MFA_ENCRYPTION_KEY decoded to ${String(decoded.length)} bytes; expected ${String(AES_256_KEY_BYTES)}. Regenerate with \`openssl rand -base64 32\`.`,
54 ];
55 }
56
57 return [];
58}
59
60/**

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected