Package com.ongres.scram.common
Enum ScramMechanism
- java.lang.Object
-
- java.lang.Enum<ScramMechanism>
-
- com.ongres.scram.common.ScramMechanism
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<ScramMechanism>
public enum ScramMechanism extends java.lang.Enum<ScramMechanism>
SCRAM Mechanisms supported by this library. At least,SCRAM-SHA-1
andSCRAM-SHA-256
are provided, since both the hash and the HMAC implementations are provided by the Java JDK version 8 or greater.MessageDigest
: "Every implementation of the Java platform is required to support the following standard MessageDigest algorithms:SHA-1
,SHA-256
".Mac
: "Every implementation of the Java platform is required to support the following standard Mac algorithms:HmacSHA1
,HmacSHA256
".- See Also:
- SASL SCRAM Family Mechanisms
-
-
Enum Constant Summary
Enum Constants Enum Constant Description SCRAM_SHA_1
SCRAM-SHA-1 mechanism, defined in RFC-5802.SCRAM_SHA_1_PLUS
SCRAM-SHA-1-PLUS mechanism, defined in RFC-5802.SCRAM_SHA_224
SCRAM-SHA-224 mechanism, not defined in an RFC.SCRAM_SHA_224_PLUS
SCRAM-SHA-224-PLUS mechanism, not defined in an RFC.SCRAM_SHA_256
SCRAM-SHA-256 mechanism, defined in RFC-7677.SCRAM_SHA_256_PLUS
SCRAM-SHA-256-PLUS mechanism, defined in RFC-7677.SCRAM_SHA_384
SCRAM-SHA-384 mechanism, not defined in an RFC.SCRAM_SHA_384_PLUS
SCRAM-SHA-384-PLUS mechanism, not defined in an RFC.SCRAM_SHA_512
SCRAM-SHA-512 mechanism.SCRAM_SHA_512_PLUS
SCRAM-SHA-512-PLUS mechanism.
-
Field Summary
Fields Modifier and Type Field Description private static @Unmodifiable java.util.Map<java.lang.String,ScramMechanism>
BY_NAME_MAPPING
private boolean
channelBinding
private @NotNull java.lang.String
hashAlgorithmName
private @NotNull java.lang.String
hmacAlgorithmName
private int
iterationCount
private @NotNull java.lang.String
keyFactoryAlgorithmName
private int
keyLength
private @NotNull java.lang.String
mechanismName
private static @Unmodifiable java.util.List<java.lang.String>
SUPPORTED_MECHANISMS
-
Constructor Summary
Constructors Modifier Constructor Description private
ScramMechanism(java.lang.String name, java.lang.String hashAlgorithmName, int keyLength, java.lang.String hmacAlgorithmName, int iterationCount)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static @Nullable ScramMechanism
byName(@NotNull java.lang.String name)
Gets a SCRAM mechanism given its standard IANA name, supported by the Java security provider.(package private) byte @NotNull []
digest(byte @NotNull [] message)
Calculate a message digest, according to the algorithm of the SCRAM mechanism.(package private) @NotNull java.lang.String
getHashAlgorithmName()
Method that returns the name of the hash algorithm.(package private) @NotNull java.lang.String
getHmacAlgorithmName()
Method that returns the name of the HMAC algorithm.(package private) int
getIterationCount()
(package private) int
getKeyLength()
Returns the length of the key length of the algorithm.@NotNull java.lang.String
getName()
The name of the mechanism.(package private) byte @NotNull []
hmac(byte @NotNull [] key, byte @NotNull [] message)
Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.private static boolean
isAlgorithmSupported(@NotNull ScramMechanism mechanism)
boolean
isPlus()
The mechanism-PLUS
require channel binding.(package private) byte @NotNull []
saltedPassword(@NotNull StringPreparation stringPreparation, char @NotNull [] password, byte @NotNull [] salt, int iterationCount)
Compute the salted password.static @Unmodifiable @NotNull java.util.List<@NotNull java.lang.String>
supportedMechanisms()
List all the supported SCRAM mechanisms by this client implementation.static ScramMechanism
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static ScramMechanism[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
SCRAM_SHA_1
public static final ScramMechanism SCRAM_SHA_1
SCRAM-SHA-1 mechanism, defined in RFC-5802.
-
SCRAM_SHA_1_PLUS
public static final ScramMechanism SCRAM_SHA_1_PLUS
SCRAM-SHA-1-PLUS mechanism, defined in RFC-5802.
-
SCRAM_SHA_224
public static final ScramMechanism SCRAM_SHA_224
SCRAM-SHA-224 mechanism, not defined in an RFC.
-
SCRAM_SHA_224_PLUS
public static final ScramMechanism SCRAM_SHA_224_PLUS
SCRAM-SHA-224-PLUS mechanism, not defined in an RFC.
-
SCRAM_SHA_256
public static final ScramMechanism SCRAM_SHA_256
SCRAM-SHA-256 mechanism, defined in RFC-7677.
-
SCRAM_SHA_256_PLUS
public static final ScramMechanism SCRAM_SHA_256_PLUS
SCRAM-SHA-256-PLUS mechanism, defined in RFC-7677.
-
SCRAM_SHA_384
public static final ScramMechanism SCRAM_SHA_384
SCRAM-SHA-384 mechanism, not defined in an RFC.
-
SCRAM_SHA_384_PLUS
public static final ScramMechanism SCRAM_SHA_384_PLUS
SCRAM-SHA-384-PLUS mechanism, not defined in an RFC.
-
SCRAM_SHA_512
public static final ScramMechanism SCRAM_SHA_512
SCRAM-SHA-512 mechanism.
-
SCRAM_SHA_512_PLUS
public static final ScramMechanism SCRAM_SHA_512_PLUS
SCRAM-SHA-512-PLUS mechanism.
-
-
Field Detail
-
BY_NAME_MAPPING
private static final @Unmodifiable java.util.Map<java.lang.String,ScramMechanism> BY_NAME_MAPPING
-
SUPPORTED_MECHANISMS
private static final @Unmodifiable java.util.List<java.lang.String> SUPPORTED_MECHANISMS
-
mechanismName
@NotNull private final @NotNull java.lang.String mechanismName
-
hashAlgorithmName
@NotNull private final @NotNull java.lang.String hashAlgorithmName
-
keyLength
private final int keyLength
-
hmacAlgorithmName
@NotNull private final @NotNull java.lang.String hmacAlgorithmName
-
keyFactoryAlgorithmName
@NotNull private final @NotNull java.lang.String keyFactoryAlgorithmName
-
channelBinding
private final boolean channelBinding
-
iterationCount
private final int iterationCount
-
-
Method Detail
-
values
public static ScramMechanism[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ScramMechanism c : ScramMechanism.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ScramMechanism valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
getHashAlgorithmName
@NotNull @NotNull java.lang.String getHashAlgorithmName()
Method that returns the name of the hash algorithm. It is protected since should be of no interest for direct users. The instance is supposed to provide abstractions over the algorithm names, and are not meant to be directly exposed.- Returns:
- The name of the hash algorithm
-
getHmacAlgorithmName
@NotNull @NotNull java.lang.String getHmacAlgorithmName()
Method that returns the name of the HMAC algorithm. It is protected since should be of no interest for direct users. The instance is supposed to provide abstractions over the algorithm names, and are not meant to be directly exposed.- Returns:
- The name of the HMAC algorithm
-
getName
@NotNull public @NotNull java.lang.String getName()
The name of the mechanism.Must be a value registered under IANA: SASL SCRAM Family Mechanisms
- Returns:
- The mechanism name
-
isPlus
public boolean isPlus()
The mechanism-PLUS
require channel binding.- Returns:
- true if the mechanism requires channel binding
-
getKeyLength
int getKeyLength()
Returns the length of the key length of the algorithm.- Returns:
- The length (in bits)
-
getIterationCount
int getIterationCount()
-
digest
byte @NotNull [] digest(byte @NotNull [] message)
Calculate a message digest, according to the algorithm of the SCRAM mechanism.- Parameters:
message
- the message- Returns:
- The calculated message digest
- Throws:
ScramRuntimeException
- If the algorithm is not provided by current JVM or any included implementations
-
hmac
byte @NotNull [] hmac(byte @NotNull [] key, byte @NotNull [] message)
Calculate the hmac of a key and a message, according to the algorithm of the SCRAM mechanism.- Parameters:
key
- the keymessage
- the message- Returns:
- The calculated message hmac instance
- Throws:
ScramRuntimeException
- If the algorithm is not provided by current JVM or any included implementations
-
saltedPassword
byte @NotNull [] saltedPassword(@NotNull @NotNull StringPreparation stringPreparation, char @NotNull [] password, byte @NotNull [] salt, int iterationCount)
Compute the salted password.- Parameters:
stringPreparation
- Type of preparation to perform in the stringpassword
- Password usedsalt
- Salt usediterationCount
- Number of iterations- Returns:
- The salted password
- Throws:
ScramRuntimeException
- If the algorithm is not provided by current JVM or any included implementations
-
byName
@Nullable public static @Nullable ScramMechanism byName(@NotNull @NotNull java.lang.String name)
Gets a SCRAM mechanism given its standard IANA name, supported by the Java security provider.- Parameters:
name
- The standard IANA full name of the mechanism.- Returns:
- An instance that contains the ScramMechanism if it was found, or null otherwise.
-
supportedMechanisms
@NotNull public static @Unmodifiable @NotNull java.util.List<@NotNull java.lang.String> supportedMechanisms()
List all the supported SCRAM mechanisms by this client implementation.- Returns:
- A unmodifiable list of the IANA-registered, SCRAM supported mechanisms
-
isAlgorithmSupported
private static boolean isAlgorithmSupported(@NotNull @NotNull ScramMechanism mechanism)
-
-