Record Class IceCredentials

java.lang.Object
java.lang.Record
com.hypixel.hytale.server.core.io.ice.IceCredentials

public record IceCredentials(@Nonnull String ufrag, @Nonnull String password) extends Record
Short-term credentials for one peer's connectivity checks.

The direction of USERNAME and the choice of key decide whether two independent implementations interoperate at all, so both are settled here rather than at each call site. A request carries peer-ufrag:local-ufrag and is keyed with the peer's password. A response carries no USERNAME and is keyed with the responder's own password.

See Also:
  • Field Details

  • Constructor Details

    • IceCredentials

      public IceCredentials(@Nonnull String ufrag, @Nonnull String password)
      Creates an instance of a IceCredentials record class.
      Parameters:
      ufrag - the value for the ufrag record component
      password - the value for the password record component
  • Method Details

    • generate

      public static IceCredentials generate()
      Mints credentials for one peer. Every joiner gets its own ufrag, which is how a listener serving several peers routes an inbound check to the right agent.
    • isValid

      public static boolean isValid(@Nullable String ufrag, @Nullable String password)
    • buildUsernameFor

      public String buildUsernameFor(@Nonnull String peerUfrag)
      Builds the USERNAME for a check sent to the peer owning peerUfrag.
    • parseLocalUfrag

      @Nullable public static String parseLocalUfrag(@Nullable String username)
      Extracts the local ufrag from a received USERNAME, which identifies the agent the check is for.
      Returns:
      the local ufrag, or null when the username is malformed
    • integrityKey

      public byte[] integrityKey()
      The HMAC key for short-term credentials, which is the password with no derivation applied.

      RFC 5389 section 15.4 (MESSAGE-INTEGRITY), or section 14.5 of RFC 8489 which obsoletes it, gives key = SASLprep(password). An ice-char password contains no character SASLprep would alter, so the raw bytes are the key.

    • 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.
    • ufrag

      @Nonnull public String ufrag()
      Returns the value of the ufrag record component.
      Returns:
      the value of the ufrag record component
    • password

      @Nonnull public String password()
      Returns the value of the password record component.
      Returns:
      the value of the password record component