Package io.github.mahmoudimus.quic.token
Class TokenValidator
java.lang.Object
io.github.mahmoudimus.quic.token.TokenValidator
Issues and checks a server's address validation tokens (RFC 9000 section 8.1): Retry tokens,
bound to the client's address and port and valid for
retryTokenLifetime, and NEW_TOKEN
tokens, bound to its IP address, valid for validationTokenLifetime and logged against
reuse.
A token the server cannot open is ignored, since it may come from another server or version
(RFC 9000 section 8.1.3); but an authentic Retry token that does not match the client's address
or has expired fails the connection with INVALID_TOKEN.
Wall-clock time comes from an injectable InstantSource, so tests can control expiry.
Threads. Safe to share if the TokenLog and random source are; the endpoint
layer must serialize calls when they are not, as with BloomTokenLog.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTokenValidator(TokenKey key, InstantSource clock, Duration retryTokenLifetime, Duration validationTokenLifetime, TokenLog log, RandomGenerator random) A validator. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]retryToken(InetSocketAddress client, ConnectionId originalDestinationId) A token for a Retry packet.validate(byte[] token, ConnectionId destinationId, InetSocketAddress remote) Checks the token of a client's first Initial packet.byte[]validationToken(InetAddress client) A token for a NEW_TOKEN frame.
-
Field Details
-
DEFAULT_RETRY_TOKEN_LIFETIME
quinn's default Retry token lifetime, 15 seconds. -
DEFAULT_VALIDATION_TOKEN_LIFETIME
quinn's default NEW_TOKEN token lifetime, two weeks.
-
-
Constructor Details
-
TokenValidator
public TokenValidator(TokenKey key, InstantSource clock, Duration retryTokenLifetime, Duration validationTokenLifetime, TokenLog log, RandomGenerator random) A validator.- Parameters:
key- the server's token keyclock- the wall clockretryTokenLifetime- how long Retry tokens are validvalidationTokenLifetime- how long NEW_TOKEN tokens are validlog- the reuse log for NEW_TOKEN tokensrandom- the source of nonces; aSecureRandomoutside tests
-
-
Method Details
-
retryToken
A token for a Retry packet.- Parameters:
client- the client's address and portoriginalDestinationId- the Destination Connection ID of the client's Initial- Returns:
- the sealed token
-
validationToken
A token for a NEW_TOKEN frame. Send a fresh one when a NEW_TOKEN frame is lost, so a client that receives both cannot reuse one token twice.- Parameters:
client- the client's IP address- Returns:
- the sealed token
-
validate
public IncomingToken validate(byte[] token, ConnectionId destinationId, InetSocketAddress remote) throws QuicException Checks the token of a client's first Initial packet.- Parameters:
token- the token, empty if nonedestinationId- the Initial's Destination Connection IDremote- the client's address and port- Returns:
- whether the address is validated, and the connection IDs to authenticate in the transport parameters
- Throws:
QuicException-INVALID_TOKENfor an authentic Retry token from another address or past its lifetime
-