public abstract class ScramShaSaslClient
extends java.lang.Object
implements javax.security.sasl.SaslClient
SaslClient implementation for SCRAM-SHA mechanisms as specified in RFC 5802.
Subclasses of this class must implement the hashing algorithms for the corresponding authentication mechanism.| Modifier and Type | Class and Description |
|---|---|
protected static class |
ScramShaSaslClient.ScramExchangeStage |
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
authenticationId |
protected java.lang.String |
authorizationId |
protected static byte[] |
CLIENT_KEY |
protected java.lang.String |
clientFirstMessageBare |
protected java.lang.String |
cNonce |
protected static java.lang.String |
GS2_CBIND_FLAG |
protected java.lang.String |
gs2Header |
protected static int |
MINIMUM_ITERATIONS |
protected java.lang.String |
password |
protected ScramShaSaslClient.ScramExchangeStage |
scramStage |
protected static byte[] |
SERVER_KEY |
protected byte[] |
serverSignature |
| Constructor and Description |
|---|
ScramShaSaslClient(java.lang.String authorizationId,
java.lang.String authenticationId,
java.lang.String password) |
| Modifier and Type | Method and Description |
|---|---|
void |
dispose() |
byte[] |
evaluateChallenge(byte[] challenge) |
private java.lang.String |
generateRandomPrintableAsciiString(int length)
Generates a RFC 5802 safe nonce: "a sequence of random printable ASCII characters excluding ','"
|
(package private) abstract java.lang.String |
getIanaMechanismName()
Returns the real IANA-registered mechanism name of this SASL client.
|
java.lang.Object |
getNegotiatedProperty(java.lang.String propName) |
(package private) abstract byte[] |
h(byte[] str)
The "H(str)" cryptographic hash function as described in RFC 5802, Section 2.2.
|
boolean |
hasInitialResponse() |
(package private) abstract byte[] |
hi(java.lang.String str,
byte[] salt,
int iterations)
The "Hi(str, salt, i)" PBKDF2 function as described in RFC 5802, Section 2.2.
|
(package private) abstract byte[] |
hmac(byte[] key,
byte[] str)
The "HMAC(key, str)" HMAC keyed hash algorithm as described in RFC 5802, Section 2.2.
|
boolean |
isComplete() |
private java.util.Map<java.lang.String,java.lang.String> |
parseChallenge(java.lang.String challenge)
Parses a SASL challenge.
|
private java.lang.String |
prepUserName(java.lang.String userName) |
byte[] |
unwrap(byte[] incoming,
int offset,
int len) |
byte[] |
wrap(byte[] outgoing,
int offset,
int len) |
(package private) byte[] |
xorInPlace(byte[] inOut,
byte[] other)
Combines the two byte arrays in a XOR operation, changing the contents of the first.
|
protected static final int MINIMUM_ITERATIONS
protected static final java.lang.String GS2_CBIND_FLAG
protected static final byte[] CLIENT_KEY
protected static final byte[] SERVER_KEY
protected java.lang.String authorizationId
protected java.lang.String authenticationId
protected java.lang.String password
protected ScramShaSaslClient.ScramExchangeStage scramStage
protected java.lang.String cNonce
protected java.lang.String gs2Header
protected java.lang.String clientFirstMessageBare
protected byte[] serverSignature
public ScramShaSaslClient(java.lang.String authorizationId,
java.lang.String authenticationId,
java.lang.String password)
throws javax.security.sasl.SaslException
javax.security.sasl.SaslExceptionabstract java.lang.String getIanaMechanismName()
SaslClient.getMechanismName() except that subclasses may
use custom mechanism names to avoid future name clashes.public boolean hasInitialResponse()
hasInitialResponse in interface javax.security.sasl.SaslClientpublic byte[] evaluateChallenge(byte[] challenge)
throws javax.security.sasl.SaslException
evaluateChallenge in interface javax.security.sasl.SaslClientjavax.security.sasl.SaslExceptionpublic boolean isComplete()
isComplete in interface javax.security.sasl.SaslClientpublic byte[] unwrap(byte[] incoming,
int offset,
int len)
throws javax.security.sasl.SaslException
unwrap in interface javax.security.sasl.SaslClientjavax.security.sasl.SaslExceptionpublic byte[] wrap(byte[] outgoing,
int offset,
int len)
throws javax.security.sasl.SaslException
wrap in interface javax.security.sasl.SaslClientjavax.security.sasl.SaslExceptionpublic java.lang.Object getNegotiatedProperty(java.lang.String propName)
getNegotiatedProperty in interface javax.security.sasl.SaslClientpublic void dispose()
throws javax.security.sasl.SaslException
dispose in interface javax.security.sasl.SaslClientjavax.security.sasl.SaslExceptionprivate java.lang.String prepUserName(java.lang.String userName)
private java.util.Map<java.lang.String,java.lang.String> parseChallenge(java.lang.String challenge)
challenge - the server message (challenge) to parse.Map with the key/value pairs obtained from the server challenge.private java.lang.String generateRandomPrintableAsciiString(int length)
length - the length of the nonce.abstract byte[] h(byte[] str)
str - the string to hash.abstract byte[] hmac(byte[] key,
byte[] str)
key - the hash key.str - the input string.abstract byte[] hi(java.lang.String str,
byte[] salt,
int iterations)
str - the string value to use as the internal HMAC key.salt - the input string to hash in the initial iteration.iterations - the number of iterations to run the algorithm.byte[] xorInPlace(byte[] inOut,
byte[] other)
inOut - the left operand of the XOR operation and the destination of the result.other - the right operand of the XOR operation.inOut, after being updated.