Class EmailVerificationLink
A link carries one query parameter, PARAM, whose value is the address, the user ID, the purpose and the expiry time of the link, sealed with the server's own key through ISensitiveParameterHandler.encodeParameter(String) - in the server that is ServerSecurityManager: AES-256-GCM under a key generated once per installation, persisted in the server keys file, rotated with the old keys retained, and tagged with the key's fingerprint so that a link survives a rotation. The GCM authentication tag is the keyed MAC of the link; the JDK verifies it before a byte of the content is returned. Nothing in the URL lets a link be forged, be altered, or be replayed for another address or user, because every one of those values is inside the sealed content and the key never leaves the server.
Before CC-SEC-FIX S2 the link carried v=base64(SHA-256(seed, email, q, uid)) with the seed, the address, q and the user ID all in the URL as well, so anyone could compute v for any address of any user; and a link never expired.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe sealed content of a link.static final recordA verification result: the status, and the claim when the token was sealed by this server for this purpose (VALID or EXPIRED), null when INVALID.static enumThe outcome of a verification.Field Summary
FieldsMethod Summary
Modifier and TypeMethodDescriptionstatic StringbuildQuery(ISensitiveParameterHandler keys, String email, long userID, long expiresAt) Builds the query string of a link:v=token.static EmailVerificationLink.Resultverify(ISensitiveParameterHandler keys, String token, long now) Verifies a token.
Field Details
PATH
The path of the verification route, without the leading slash: "iizi-email-verification".- See Also:
PARAM
VALIDITY_MS
public static final long VALIDITY_MSHow long a link is valid from the moment it is built: 72 hours.- See Also:
Method Details
buildQuery
public static String buildQuery(ISensitiveParameterHandler keys, String email, long userID, long expiresAt) throws GeneralSecurityException Builds the query string of a link:v=token.- Parameters:
keys- The server's sealing keys.email- The address to verify.userID- The user ID the address belongs to.expiresAt- The expiry time, milliseconds since the epoch.- Returns:
- The query string, URL-safe.
- Throws:
GeneralSecurityException- If the content cannot be sealed.NullPointerException- Ifkeysoremailis null.IllegalArgumentException- If the address contains a line break.
verify
public static EmailVerificationLink.Result verify(ISensitiveParameterHandler keys, String token, long now) Verifies a token.The token is opened with the server's keys, which fails for a token sealed by another server, for one altered anywhere and for anything that is not a token at all; the content must then carry the purpose; and the expiry time must not have passed. Nothing is thrown for a bad token: a verification route is unauthenticated by design and answers every caller the same way.
- Parameters:
keys- The server's sealing keys.token- The token from the link, null or empty for none.now- The current time, milliseconds since the epoch.- Returns:
- The result, never null.