Files
floci/src/test/java
Priamo Germosen 6a98f69a5d refactor(core): extract the shared TOTP primitive from Cognito (#4814)
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.
2026-10-01 07:50:53 -05:00
..