Class ServerFirstMessage

java.lang.Object
com.ongres.scram.common.message.ServerFirstMessage
All Implemented Interfaces:
StringWritable

public class ServerFirstMessage extends Object implements StringWritable
Constructs and parses server-first-messages. Formal syntax is: server-first-message = [reserved-mext ","] nonce "," salt "," iteration-count ["," extensions] Note that extensions are not supported.
See Also:
  • Field Details

    • ITERATION_MIN_VALUE

      public static final int ITERATION_MIN_VALUE
      Minimum allowed value for the iteration, as per the RFC.
      See Also:
    • clientNonce

      private final String clientNonce
    • serverNonce

      private final String serverNonce
    • salt

      private final String salt
    • iteration

      private final int iteration
  • Constructor Details

    • ServerFirstMessage

      public ServerFirstMessage(String clientNonce, String serverNonce, String salt, int iteration) throws IllegalArgumentException
      Constructs a server-first-message from a client-first-message and the additional required data.
      Parameters:
      clientNonce - String representing the client-first-message
      serverNonce - Server serverNonce
      salt - The salt
      iteration - The iteration count (must be <= 4096)
      Throws:
      IllegalArgumentException - If clientFirstMessage, serverNonce or salt are null or empty, or iteration < 4096
  • Method Details

    • getClientNonce

      public String getClientNonce()
    • getServerNonce

      public String getServerNonce()
    • getNonce

      public String getNonce()
    • getSalt

      public String getSalt()
    • getIteration

      public int getIteration()
    • writeTo

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

      public static ServerFirstMessage parseFrom(String serverFirstMessage, String clientNonce) throws ScramParseException, IllegalArgumentException
      Parses a server-first-message from a String.
      Parameters:
      serverFirstMessage - The string representing the server-first-message
      clientNonce - The serverNonce that is present in the client-first-message
      Returns:
      The parsed instance
      Throws:
      ScramParseException - If the argument is not a valid server-first-message
      IllegalArgumentException - If either argument is empty or serverFirstMessage is not a valid message
    • toString

      public String toString()
      Overrides:
      toString in class Object