mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
Cognito's software-token MFA computes RFC 6238 time-based one-time passwords: HMAC-SHA1 over 30-second steps, truncated to six digits, with the secret handed out as RFC 4648 base32 so an authenticator app can be programmed from it. None of that is specific to Cognito, and IAM's virtual MFA devices need exactly the same arithmetic. Move it to core.common.Totp and leave CognitoTotp as a thin view over it, keeping its single-code drift window and its attempt budget. Behaviour is unchanged: CognitoTotp's public surface and semantics are identical, which its existing test still covers, and the new TotpTest pins the arithmetic against RFC 6238 Appendix B's published vectors rather than against this implementation's own output. The static SecureRandom moves with it, so the --initialize-at-run-time registration moves from CognitoTotp to Totp. Without it GraalVM captures the instance in the image heap and the native build aborts. Only what Cognito needs crosses the package boundary. isSixDigits, codeEquals and the base32 helpers stay package-private until a second caller actually needs them. This is step 1 of 2. Step 2 adds IAM virtual MFA device support on top of this primitive, instead of landing a second copy of the same code.