Class MFAProof

java.lang.Object
com.iizix.user.MFAProof

public final class MFAProof extends Object
The proof that a sign-in verified a second factor: the MFA proof of HUB-DESIGN 7.4 (ruling RB-11), {method, verified, age}. The server that verified the factor issues it and keeps it with the session; a server that receives it inside a session transfer trusts it because an authenticated member sent it, and never verifies the code again - the code was spent once, where it was typed.

The age is measured on the issuing server's monotonic clock, so that a change of the wall clock neither ages a proof nor makes it young again. A proof older than MAX_AGE_MS is not fresh and is not sent. A sign-in that verified no second factor has the proof NONE. A passkey that was asserted with user verification is a proof, as a code is (METHOD_PASSKEY).

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The age in milliseconds up to which a proof is fresh: 120 seconds (HUB-DESIGN 7.4).
    final String
    The method that was verified, METHOD_NONE for none.
    static final String
    The method of NONE: no second factor was verified.
    static final String
    The method of a passkey that was asserted with user verification (CC-LOGIN-M11-PASSKEY-PROOF): the passkey is what the user has, the verification by its authenticator what the user is or knows.
    static final String
    The method of a recovery code.
    static final String
    The method of a verification code of an authenticator app (RFC 6238).
    static final MFAProof
    The proof of a sign-in that verified no second factor.
    final boolean
    Whether the second factor was verified.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MFAProof(String method, boolean verified, long verifiedAt)
    Constructs a proof.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    age()
    Gets the age of the proof now.
    long
    age(long now)
    Gets the age of the proof at a time.
    boolean
    Checks if the proof may be sent now: a factor was verified, at most MAX_AGE_MS ago.
    boolean
    isFresh(long now)
    Checks if the proof may be sent at a time.
    static long
    Gets the monotonic clock the age of a proof is measured on.
    Gets the proof as it is written in a log or sent: the method, whether it was verified and its age now.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • METHOD_NONE

      public static final String METHOD_NONE
      The method of NONE: no second factor was verified.
      See Also:
    • METHOD_TOTP

      public static final String METHOD_TOTP
      The method of a verification code of an authenticator app (RFC 6238).
      See Also:
    • METHOD_RECOVERY

      public static final String METHOD_RECOVERY
      The method of a recovery code.
      See Also:
    • METHOD_PASSKEY

      public static final String METHOD_PASSKEY
      The method of a passkey that was asserted with user verification (CC-LOGIN-M11-PASSKEY-PROOF): the passkey is what the user has, the verification by its authenticator what the user is or knows.
      See Also:
    • MAX_AGE_MS

      public static final long MAX_AGE_MS
      The age in milliseconds up to which a proof is fresh: 120 seconds (HUB-DESIGN 7.4).
      See Also:
    • NONE

      public static final MFAProof NONE
      The proof of a sign-in that verified no second factor.
    • method

      public final String method
      The method that was verified, METHOD_NONE for none.
    • verified

      public final boolean verified
      Whether the second factor was verified.
  • Constructor Details

    • MFAProof

      public MFAProof(String method, boolean verified, long verifiedAt)
      Constructs a proof.
      Parameters:
      method - The method that was verified.
      verified - Whether it was verified.
      verifiedAt - The monotonic clock time in milliseconds it was verified at, see monotonicMillis().
      Throws:
      NullPointerException - If method is null.
  • Method Details

    • monotonicMillis

      public static long monotonicMillis()
      Gets the monotonic clock the age of a proof is measured on.
      Returns:
      System.nanoTime() in milliseconds.
    • age

      public long age()
      Gets the age of the proof now.
      Returns:
      The milliseconds since the factor was verified, zero for a proof that verified nothing.
    • age

      public long age(long now)
      Gets the age of the proof at a time.
      Parameters:
      now - The monotonic clock time in milliseconds.
      Returns:
      The milliseconds since the factor was verified, never negative, zero for a proof that verified nothing.
    • isFresh

      public boolean isFresh()
      Checks if the proof may be sent now: a factor was verified, at most MAX_AGE_MS ago.
      Returns:
      true when fresh.
    • isFresh

      public boolean isFresh(long now)
      Checks if the proof may be sent at a time.
      Parameters:
      now - The monotonic clock time in milliseconds.
      Returns:
      true when a factor was verified, at most MAX_AGE_MS before.
    • toString

      public String toString()
      Gets the proof as it is written in a log or sent: the method, whether it was verified and its age now. Nothing in it is a secret.
      Overrides:
      toString in class Object
      Returns:
      The proof as {method:"totp",verified:true,age:1234}.