Record Class Keys

java.lang.Object
java.lang.Record
io.github.mahmoudimus.quic.crypto.Keys
Record Components:
local - the keys for packets this endpoint sends
remote - the keys for packets this endpoint receives

public record Keys(DirectionalKeys local, DirectionalKeys remote) extends Record
The packet protection keys of one encryption level, from one endpoint's point of view: local protects what it sends and remote removes protection from what it receives.

Keys come from TLS traffic secrets (fromSecrets(io.github.mahmoudimus.quic.Secrets, boolean)), or for Initial packets from the client's first Destination Connection ID (initial(io.github.mahmoudimus.quic.QuicVersion, io.github.mahmoudimus.quic.ConnectionId, boolean)). A 1-RTT key update (RFC 9001 section 6) derives the next secrets with nextSecrets(io.github.mahmoudimus.quic.Secrets, io.github.mahmoudimus.quic.QuicVersion) and the next keys with update(io.github.mahmoudimus.quic.Secrets, boolean, io.github.mahmoudimus.quic.QuicVersion), which keeps the header protection keys.

  • Constructor Details

    • Keys

      public Keys(DirectionalKeys local, DirectionalKeys remote)
      Keys from their parts.
      Parameters:
      local - the keys for packets this endpoint sends
      remote - the keys for packets this endpoint receives
  • Method Details

    • fromSecrets

      public static Keys fromSecrets(Secrets secrets, boolean isServer)
      QUIC version 1 keys from the traffic secrets the TLS handshake produced.
      Parameters:
      secrets - the client and server secrets of one level
      isServer - whether this endpoint is the server, which picks the local secret
      Returns:
      the keys
    • fromSecrets

      public static Keys fromSecrets(Secrets secrets, boolean isServer, QuicVersion version)
      Keys from the traffic secrets the TLS handshake produced.
      Parameters:
      secrets - the client and server secrets of one level
      isServer - whether this endpoint is the server, which picks the local secret
      version - the QUIC version, which picks the HKDF labels
      Returns:
      the keys
    • initialSecrets

      public static Secrets initialSecrets(QuicVersion version, ConnectionId clientDestinationId)
      The Initial secrets for a client's first Destination Connection ID (RFC 9001 section 5.2): HKDF-Extract with the version's salt, then the "client in" and "server in" labels.
      Parameters:
      version - the QUIC version, which picks the salt
      clientDestinationId - the Destination Connection ID of the client's first Initial
      Returns:
      the secrets, for CipherSuite.TLS_AES_128_GCM_SHA256
    • initial

      public static Keys initial(QuicVersion version, ConnectionId clientDestinationId, boolean isServer)
      The Initial keys for a client's first Destination Connection ID.
      Parameters:
      version - the QUIC version
      clientDestinationId - the Destination Connection ID of the client's first Initial
      isServer - whether this endpoint is the server
      Returns:
      the keys
    • nextSecrets

      public static Secrets nextSecrets(Secrets secrets, QuicVersion version)
      The secrets after a key update: each secret expanded with the version's "quic ku" label to the hash length (RFC 9001 section 6.1).
      Parameters:
      secrets - the current 1-RTT secrets
      version - the QUIC version, which picks the label
      Returns:
      the next secrets, for the same level and suite
    • nextSecret

      public static byte[] nextSecret(CipherSuite suite, byte[] secret, QuicVersion version)
      The next secret of one direction after a key update.
      Parameters:
      suite - the cipher suite
      secret - the current traffic secret
      version - the QUIC version, which picks the label
      Returns:
      the next traffic secret
    • update

      public Keys update(Secrets nextSecrets, boolean isServer, QuicVersion version)
      The keys of the next key phase: new packet keys from the next secrets, with these header keys, which a key update does not change (RFC 9001 section 6).
      Parameters:
      nextSecrets - the secrets from nextSecrets(io.github.mahmoudimus.quic.Secrets, io.github.mahmoudimus.quic.QuicVersion)
      isServer - whether this endpoint is the server
      version - the QUIC version, which picks the labels
      Returns:
      the keys for the next key phase
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • local

      public DirectionalKeys local()
      Returns the value of the local record component.
      Returns:
      the value of the local record component
    • remote

      public DirectionalKeys remote()
      Returns the value of the remote record component.
      Returns:
      the value of the remote record component