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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringName of the MAC algorithm.private final SecretKeySpecThe signing key.static final StringLabel of the purpose the key is derived for.private static final charSeparator between the token and its signature. -
Constructor Summary
ConstructorsConstructorDescriptionHmacTrustedDeviceTokenSigner(PurposeKeyDerivation derivation) Derives the signing key. -
Method Summary
-
Field Details
-
PURPOSE
Label of the purpose the key is derived for.- See Also:
-
SEPARATOR
private static final char SEPARATORSeparator between the token and its signature.- See Also:
-
ALGORITHM
Name of the MAC algorithm.- See Also:
-
key
The signing key.
-
-
Constructor Details
-
HmacTrustedDeviceTokenSigner
Derives the signing key.- Parameters:
derivation- derives the key of a purpose from the key-encryption secret.
-
-
Method Details
-
sign
Description copied from interface:TrustedDeviceTokenSignerSigns a token.- Specified by:
signin interfaceTrustedDeviceTokenSigner- 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
Description copied from interface:TrustedDeviceTokenSignerChecks the signature of a cookie value, in constant time.- Specified by:
verifyin interfaceTrustedDeviceTokenSigner- Parameters:
signedValue- the value presented by the browser, possiblynullor malformed.- Returns:
- the raw token when the value is well formed and its signature is valid; empty otherwise.
-
mac
Computes the signature of a token.- Parameters:
token- the token.- Returns:
- the HMAC-SHA256 of its UTF-8 bytes.
-