Class ScramMessageFormatter


  • public final class ScramMessageFormatter
    extends Object
    Formats SCRAM protocol messages (RFC 5802) and HTTP headers (RFC 7804). Thread-safe: all methods are stateless.
    • Method Detail

      • escapeUsername

        public static String escapeUsername​(String username)
        Escape a username per RFC 5802: "=" → "=3D", "," → "=2C".
      • clientFirstMessageBare

        public static String clientFirstMessageBare​(String username,
                                                    String clientNonce)
        Format the bare portion of client-first-message (without gs2-header). "n=<escaped-user>,r=<c-nonce>"
      • formatClientFirstMessage

        public static String formatClientFirstMessage​(String username,
                                                      String clientNonce)
        Format the full client-first-message including gs2-header. "n,,n=<escaped-user>,r=<c-nonce>"
      • clientFinalMessageWithoutProof

        public static String clientFinalMessageWithoutProof​(String fullNonce)
        Format client-final-message-without-proof. "c=biws,r=<full-nonce>"
      • formatClientFinalMessage

        public static String formatClientFinalMessage​(String fullNonce,
                                                      byte[] clientProof)
        Format the full client-final-message with proof. "c=biws,r=<full-nonce>,p=<base64-proof>"
      • formatAuthorizationHeader

        public static String formatAuthorizationHeader​(String mechanism,
                                                       @Nullable
                                                       @Nullable String realm,
                                                       @Nullable
                                                       @Nullable String sid,
                                                       String base64Data)
        Format the HTTP Authorization header value for SCRAM. Per Erratum 6558, the data attribute is quoted.
        Parameters:
        mechanism - "SCRAM-SHA-256"
        realm - realm value (may be null)
        sid - session ID (may be null)
        base64Data - base64-encoded SCRAM message
        Returns:
        formatted header value