Class ClientFirstMessage


public final class ClientFirstMessage extends AbstractScramMessage
Constructs and parses client-first-messages. Message contains a gs2-header, a username and a nonce.
Formal Syntax:
client-first-message-bare [reserved-mext ","] username "," nonce ["," extensions]
client-first-message gs2-header client-first-message-bare
See Also:
  • Field Details

    • gs2Header

      private final Gs2Header gs2Header
      gs2-header = gs2-cbind-flag "," [ authzid ] ",".
    • username

      private final String username
      username = "n=" saslname.
    • clientNonce

      private final String clientNonce
      nonce= "r=" c-nonce [s-nonce].
  • Constructor Details

    • ClientFirstMessage

      public ClientFirstMessage(Gs2Header gs2Header, String username, String clientNonce)
      Constructs a client-first-message for the given user, nonce and gs2Header. This constructor is intended to be instantiated by a scram client, and not directly. The client should be providing the header, and nonce (and probably the user too).
      Parameters:
      gs2Header - The GSS-API header
      username - The SCRAM username
      clientNonce - The nonce for this session
      Throws:
      IllegalArgumentException - If any of the arguments is null or empty
    • ClientFirstMessage

      public ClientFirstMessage(Gs2CbindFlag gs2CbindFlag, String cbindName, String authzid, String username, String clientNonce)
      Constructs a client-first-message for the given parameters. Under normal operation, this constructor is intended to be instantiated by a scram client, and not directly. However, this constructor is more user- or test-friendly, as the arguments are easier to provide without building other indirect object parameters.
      Parameters:
      gs2CbindFlag - The channel-binding flag
      cbindName - The optional channel binding name
      authzid - The optional authzid
      username - The SCRAM user
      clientNonce - The nonce for this session
      Throws:
      IllegalArgumentException - If the flag, user or nonce are null or empty
    • ClientFirstMessage

      public ClientFirstMessage(String username, String clientNonce)
      Constructs a client-first-message for the given parameters, with no channel binding nor authzid. Under normal operation, this constructor is intended to be instantiated by a scram client, and not directly. However, this constructor is more user- or test-friendly, as the arguments are easier to provide without building other indirect object parameters.
      Parameters:
      username - The SCRAM user
      clientNonce - The nonce for this session
      Throws:
      IllegalArgumentException - If the user or nonce are null or empty
  • Method Details

    • isChannelBindingRequired

      public boolean isChannelBindingRequired()
      Check to probe if gs2-cbind-flag is set to "p=".
      Returns:
      true if the message requires channel binding
    • getGs2Header

      public Gs2Header getGs2Header()
      Return the Gs2Header.
      Returns:
      the gs2-header
    • getUsername

      public String getUsername()
      Return the username.
      Returns:
      the "n=" saslname
    • getClientNonce

      public String getClientNonce()
      Return the client nonce.
      Returns:
      the c-nonce
    • clientFirstMessageBare

      StringBuilder clientFirstMessageBare(StringBuilder sb)
      Limited version of the StringWritableCsv method, that doesn't write the GS2 header. This method is useful to construct the auth message used as part of the SCRAM algorithm.
      Parameters:
      sb - A StringBuffer where to write the data to.
      Returns:
      The same StringBuffer
    • parseFrom

      public static ClientFirstMessage parseFrom(String clientFirstMessage) throws ScramParseException
      Construct a ClientFirstMessage instance from a message (String).
      Parameters:
      clientFirstMessage - The String representing the client-first-message
      Returns:
      The instance
      Throws:
      ScramParseException - If the message is not a valid client-first-message
      IllegalArgumentException - If the message is null or empty
    • writeTo

      Description copied from class: StringWritable
      Write the class information to the given StringBuffer.
      Specified by:
      writeTo in class StringWritable
      Parameters:
      sb - Where to write the data.
      Returns:
      The same StringBuffer.