Class HmacTrustedDeviceTokenSigner

java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.HmacTrustedDeviceTokenSigner
All Implemented Interfaces:
TrustedDeviceTokenSigner

@Component public class HmacTrustedDeviceTokenSigner extends Object implements TrustedDeviceTokenSigner
TrustedDeviceTokenSigner that signs the trusted-device cookie with HMAC-SHA256, under a key derived from the key-encryption secret for this purpose only (PurposeKeyDerivation). The value is token.signature, the signature Base64url encoded without padding; it is compared in constant time.
  • Field Details

  • Constructor Details

    • HmacTrustedDeviceTokenSigner

      public HmacTrustedDeviceTokenSigner(PurposeKeyDerivation derivation)
      Derives the signing key.
      Parameters:
      derivation - derives the key of a purpose from the key-encryption secret.
  • Method Details

    • sign

      public String sign(String token)
      Description copied from interface: TrustedDeviceTokenSigner
      Signs a token.
      Specified by:
      sign in interface TrustedDeviceTokenSigner
      Parameters:
      token - the raw token of a trusted device.
      Returns:
      the value to put in the cookie: the token, a dot and its signature.
    • verify

      public Optional<String> verify(String signedValue)
      Description copied from interface: TrustedDeviceTokenSigner
      Checks the signature of a cookie value, in constant time.
      Specified by:
      verify in interface TrustedDeviceTokenSigner
      Parameters:
      signedValue - the value presented by the browser, possibly null or malformed.
      Returns:
      the raw token when the value is well formed and its signature is valid; empty otherwise.
    • mac

      private byte[] mac(String token)
      Computes the signature of a token.
      Parameters:
      token - the token.
      Returns:
      the HMAC-SHA256 of its UTF-8 bytes.