Top Description Inners Fields Constructors Methods
com.ongres.scram.client

public Class ScramSession

extends Object
Class Inheritance
Static Imports
com.ongres.scram.common.util.Preconditions.checkNotEmpty, .Preconditions.checkNotNull

A class that represents a SCRAM client. Use this class to perform a SCRAM negotiation with a SCRAM server. This class performs an authentication execution for a given user, and has state related to it. Thus, it cannot be shared across users or authentication executions.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
ScramSession.ClientFinalProcessor

Processor that allows to generate the client-final-message, as well as process the server-final-message and verify server's signature.

public class
ScramSession.ServerFirstProcessor

Process a received server-first-message.

Field Summary

Modifier and TypeField and Description
private ClientFirstMessage
private final String
private final ScramMechanism
private String
private final StringPreparation
private final String

Constructor Summary

AccessConstructor and Description
public
ScramSession(ScramMechanism
The SCRAM mechanism that will be using this client
scramMechanism
,
StringPreparation stringPreparation, String user, String nonce)

Constructs a SCRAM client, to perform an authentication for a given user.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The message
clientFirstMessage
(Gs2CbindFlag
The channel binding flag
gs2CbindFlag
,
String
The channel binding algorithm name, if channel binding is supported, or null
cbindName
,
String
The optional
authzid
)

Returns the text representation of a SCRAM client-first-message, with the GSS-API header values indicated.

public String

Returns:

The message
clientFirstMessage
()

Returns the text representation of a SCRAM client-first-message, with no channel binding nor authzid.

public ScramSession.ServerFirstProcessor

Returns:

The handler
receiveServerFirstMessage
(String
The message
serverFirstMessage
)

Constructs a handler for the server-first-message, from its String representation.

private String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clientFirstMessageback to summary
private ClientFirstMessage clientFirstMessage
nonceback to summary
private final String nonce
scramMechanismback to summary
private final ScramMechanism scramMechanism
serverFirstMessageStringback to summary
private String serverFirstMessageString
stringPreparationback to summary
private final StringPreparation stringPreparation
userback to summary
private final String user

Constructor Detail

ScramSessionback to summary
public ScramSession(ScramMechanism scramMechanism, StringPreparation stringPreparation, String user, String nonce)

Constructs a SCRAM client, to perform an authentication for a given user. This class can be instantiated directly, but it is recommended that a ScramClient is used instead.

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism that will be using this client

Method Detail

clientFirstMessageback to summary
public String clientFirstMessage(Gs2CbindFlag gs2CbindFlag, String cbindName, String authzid)

Returns the text representation of a SCRAM client-first-message, with the GSS-API header values indicated.

Parameters
gs2CbindFlag:Gs2CbindFlag

The channel binding flag

cbindName:String

The channel binding algorithm name, if channel binding is supported, or null

authzid:String

The optional

Returns:String

The message

clientFirstMessageback to summary
public String clientFirstMessage()

Returns the text representation of a SCRAM client-first-message, with no channel binding nor authzid.

Returns:String

The message

receiveServerFirstMessageback to summary
public ScramSession.ServerFirstProcessor receiveServerFirstMessage(String serverFirstMessage) throws ScramParseException, IllegalArgumentException

Constructs a handler for the server-first-message, from its String representation.

Parameters
serverFirstMessage:String

The message

Returns:ScramSession.ServerFirstProcessor

The handler

Exceptions
ScramParseException:
If the message is not a valid server-first-message
IllegalArgumentException:
If the message is null or empty
setAndReturnClientFirstMessageback to summary
private String setAndReturnClientFirstMessage(ClientFirstMessage clientFirstMessage)
com.ongres.scram.client back to summary

public Class ScramSession.ClientFinalProcessor

extends Object
Class Inheritance

Processor that allows to generate the client-final-message, as well as process the server-final-message and verify server's signature. Generate the processor by calling either ServerFirstProcessor#clientFinalProcessor(String) or ServerFirstProcessor#clientFinalProcessor(byte[], byte[]).

Field Summary

Modifier and TypeField and Description
private String
private final byte[]
private final String
private final byte[]
private final byte[]

Constructor Summary

AccessConstructor and Description
private
ClientFinalProcessor(String nonce, byte[] clientKey, byte[] storedKey, byte[] serverKey)

private
ClientFinalProcessor(String nonce, byte[] clientKey, byte[] serverKey)

private
ClientFinalProcessor(String nonce, byte[] saltedPassword)

private
ClientFinalProcessor(String nonce, String password, String salt, int iteration)

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

The message
clientFinalMessage
(byte[]
The bytes of the channel-binding data
cbindData
)

Generates the SCRAM representation of the client-final-message, including the given channel-binding data.

public String

Returns:

The message
clientFinalMessage
()

Generates the SCRAM representation of the client-final-message.

private synchronized void
generateAndCacheAuthMessage(byte[] cbindData)

public void
receiveServerFinalMessage(String
The received server-final-message
serverFinalMessage
)

Receive and process the server-final-message.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authMessageback to summary
private String authMessage
clientKeyback to summary
private final byte[] clientKey
nonceback to summary
private final String nonce
serverKeyback to summary
private final byte[] serverKey
storedKeyback to summary
private final byte[] storedKey

Constructor Detail

ClientFinalProcessorback to summary
private ClientFinalProcessor(String nonce, byte[] clientKey, byte[] storedKey, byte[] serverKey)
ClientFinalProcessorback to summary
private ClientFinalProcessor(String nonce, byte[] clientKey, byte[] serverKey)
ClientFinalProcessorback to summary
private ClientFinalProcessor(String nonce, byte[] saltedPassword)
ClientFinalProcessorback to summary
private ClientFinalProcessor(String nonce, String password, String salt, int iteration)

Method Detail

clientFinalMessageback to summary
private String clientFinalMessage(byte[] cbindData) throws IllegalArgumentException

Generates the SCRAM representation of the client-final-message, including the given channel-binding data.

Parameters
cbindData:byte[]

The bytes of the channel-binding data

Returns:String

The message

Exceptions
IllegalArgumentException:
If the channel binding data is null
clientFinalMessageback to summary
public String clientFinalMessage()

Generates the SCRAM representation of the client-final-message.

Returns:String

The message

generateAndCacheAuthMessageback to summary
private synchronized void generateAndCacheAuthMessage(byte[] cbindData)
receiveServerFinalMessageback to summary
public void receiveServerFinalMessage(String serverFinalMessage) throws ScramParseException, ScramServerErrorException, ScramInvalidServerSignatureException, IllegalArgumentException

Receive and process the server-final-message. Server SCRAM signatures is verified.

Parameters
serverFinalMessage:String

The received server-final-message

Exceptions
ScramParseException:
If the message is not a valid server-final-message
ScramServerErrorException:
If the server-final-message contained an error
IllegalArgumentException:
If the message is null or empty
com.ongres.scram.client back to summary

public Class ScramSession.ServerFirstProcessor

extends Object
Class Inheritance

Process a received server-first-message. Generate by calling receiveServerFirstMessage(String).

Field Summary

Modifier and TypeField and Description
private final ServerFirstMessage

Constructor Summary

AccessConstructor and Description
private
ServerFirstProcessor(String receivedServerFirstMessage)

Method Summary

Modifier and TypeMethod and Description
public ScramSession.ClientFinalProcessor

Returns:

The handler
clientFinalProcessor
(String
The user's password
password
)

Generates a ClientFinalProcessor, that allows to generate the client-final-message and also receive and parse the server-first-message.

public ScramSession.ClientFinalProcessor

Returns:

The handler
clientFinalProcessor
(byte[]
The client key, as per the SCRAM algorithm. It can be generated with: ScramFunctions#clientKey(ScramMechanism, StringPreparation, String, byte[], int)
clientKey
,
byte[]
The stored key, as per the SCRAM algorithm. It can be generated from the client key with: ScramFunctions#storedKey(ScramMechanism, byte[])
storedKey
)

Generates a ClientFinalProcessor, that allows to generate the client-final-message and also receive and parse the server-first-message.

public int
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serverFirstMessageback to summary
private final ServerFirstMessage serverFirstMessage

Constructor Detail

ServerFirstProcessorback to summary
private ServerFirstProcessor(String receivedServerFirstMessage) throws ScramParseException

Method Detail

clientFinalProcessorback to summary
public ScramSession.ClientFinalProcessor clientFinalProcessor(String password) throws IllegalArgumentException

Generates a ClientFinalProcessor, that allows to generate the client-final-message and also receive and parse the server-first-message. It is based on the user's password.

Parameters
password:String

The user's password

Returns:ScramSession.ClientFinalProcessor

The handler

Exceptions
IllegalArgumentException:
If the message is null or empty
clientFinalProcessorback to summary
public ScramSession.ClientFinalProcessor clientFinalProcessor(byte[] clientKey, byte[] storedKey) throws IllegalArgumentException

Generates a ClientFinalProcessor, that allows to generate the client-final-message and also receive and parse the server-first-message. It is based on the clientKey and storedKey, which, if available, provide an optimized path versus providing the original user's password.

Parameters
clientKey:byte[]

The client key, as per the SCRAM algorithm. It can be generated with: ScramFunctions#clientKey(ScramMechanism, StringPreparation, String, byte[], int)

storedKey:byte[]

The stored key, as per the SCRAM algorithm. It can be generated from the client key with: ScramFunctions#storedKey(ScramMechanism, byte[])

Returns:ScramSession.ClientFinalProcessor

The handler

Exceptions
IllegalArgumentException:
If the message is null or empty
getIterationback to summary
public int getIteration()
getSaltback to summary
public String getSalt()