Class Token

java.lang.Object
io.github.mahmoudimus.quic.token.Token

public final class Token extends Object
An address validation token: a payload and a random nonce. On the wire it is the payload sealed with a one-time key derived from the nonce, followed by the 16-byte nonce in the clear.
   type (1) | address: family (1), 4 or 16 bytes [, port (2) for Retry]
            | [original DCID: length (1), bytes, for Retry] | issued, Unix seconds (8)
 

Immutable.

  • Field Details

    • NONCE_LENGTH

      public static final int NONCE_LENGTH
      The nonce length, in bytes.
      See Also:
  • Constructor Details

    • Token

      public Token(TokenPayload payload, byte[] nonce)
      A token.
      Parameters:
      payload - what the token says
      nonce - a unique random value of 16 bytes
  • Method Details

    • create

      public static Token create(TokenPayload payload, RandomGenerator random)
      A token with a fresh random nonce.
      Parameters:
      payload - what the token says
      random - the source of randomness; a SecureRandom outside tests
      Returns:
      the token
    • payload

      public TokenPayload payload()
      What the token says.
      Returns:
      the payload
    • nonce

      public byte[] nonce()
      The token's nonce, visible to the client.
      Returns:
      a copy
    • encode

      public byte[] encode(TokenKey key)
      Encodes and seals the token.
      Parameters:
      key - the server's token key
      Returns:
      the token as sent to the client
    • decode

      public static Token decode(TokenKey key, byte[] raw)
      Opens and decodes a token.
      Parameters:
      key - the server's token key
      raw - the token from the client
      Returns:
      the token, or null if it does not authenticate or decode, as for a token from another server or version