Class OneTimePasswordImpl
- java.lang.Object
-
- org.wildfly.security.password.impl.AbstractPasswordImpl
-
- org.wildfly.security.password.impl.OneTimePasswordImpl
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Key
,OneTimePassword
,OneWayPassword
,Password
class OneTimePasswordImpl extends AbstractPasswordImpl implements OneTimePassword
APassword
implementation forOneTimePassword
.- Author:
- Farah Juma
-
-
Field Summary
Fields Modifier and Type Field Description private String
algorithm
private byte[]
hash
private String
seed
private int
sequenceNumber
private static long
serialVersionUID
-
Fields inherited from interface org.wildfly.security.password.interfaces.OneTimePassword
ALGORITHM_OTP_MD5, ALGORITHM_OTP_SHA_256, ALGORITHM_OTP_SHA_384, ALGORITHM_OTP_SHA_512, ALGORITHM_OTP_SHA1, OTP_HASH_SIZE
-
-
Constructor Summary
Constructors Constructor Description OneTimePasswordImpl(String algorithm, byte[] hash, String seed, int sequenceNumber)
OneTimePasswordImpl(String algorithm, char[] password, OneTimePasswordAlgorithmSpec spec)
OneTimePasswordImpl(String algorithm, OneTimePasswordSpec spec)
OneTimePasswordImpl(OneTimePassword password)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OneTimePasswordImpl
clone()
Creates and returns a copy of thisPassword
.(package private) static byte[]
computeHash(byte[] hash, String algorithm, MessageDigest messageDigest, int start, int end)
(package private) <T extends KeySpec>
booleanconvertibleTo(Class<T> keySpecType)
boolean
equals(Object obj)
private static byte[]
generateOTP(String algorithm, byte[] passPhrase, String seed, int sequenceNumber)
Generate a 64-bit OTP as specified in RFC 2289.String
getAlgorithm()
byte[]
getHash()
Get the hash represented by this password.(package private) <S extends KeySpec>
SgetKeySpec(Class<S> keySpecType)
private static MessageDigest
getMessageDigest(String algorithm)
String
getSeed()
Get the seed used to generate the hash.int
getSequenceNumber()
Get the sequence number used to generate the hash.private static byte[]
hashAndFold(String algorithm, MessageDigest messageDigest, byte[] input)
Pass the given input through a hash function and fold the result to 64 bits.int
hashCode()
private void
readObject(ObjectInputStream ignored)
private static void
reverse(byte[] bytes, int offset, int length)
(package private) Password
translate(AlgorithmParameterSpec parameterSpec)
(package private) boolean
verify(char[] guess)
(package private) Object
writeReplace()
-
Methods inherited from class org.wildfly.security.password.impl.AbstractPasswordImpl
getEncoded, getFormat, getNormalizedPasswordBytes, getNormalizedPasswordBytes, verify
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.security.Key
getEncoded, getFormat
-
Methods inherited from interface org.wildfly.security.password.interfaces.OneTimePassword
getParameterSpec, impliesParameters
-
Methods inherited from interface org.wildfly.security.password.Password
castAndApply, castAndApply, castAs, castAs
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
algorithm
private final String algorithm
-
hash
private final byte[] hash
-
seed
private final String seed
-
sequenceNumber
private final int sequenceNumber
-
-
Constructor Detail
-
OneTimePasswordImpl
OneTimePasswordImpl(String algorithm, byte[] hash, String seed, int sequenceNumber)
-
OneTimePasswordImpl
OneTimePasswordImpl(OneTimePassword password)
-
OneTimePasswordImpl
OneTimePasswordImpl(String algorithm, OneTimePasswordSpec spec)
-
OneTimePasswordImpl
OneTimePasswordImpl(String algorithm, char[] password, OneTimePasswordAlgorithmSpec spec) throws SaslException
- Throws:
SaslException
-
-
Method Detail
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceKey
-
getHash
public byte[] getHash()
Description copied from interface:OneTimePassword
Get the hash represented by this password.- Specified by:
getHash
in interfaceOneTimePassword
- Returns:
- the hash represented by this password
-
getSeed
public String getSeed()
Description copied from interface:OneTimePassword
Get the seed used to generate the hash.- Specified by:
getSeed
in interfaceOneTimePassword
- Returns:
- the seed used to generate the hash
-
getSequenceNumber
public int getSequenceNumber()
Description copied from interface:OneTimePassword
Get the sequence number used to generate the hash.- Specified by:
getSequenceNumber
in interfaceOneTimePassword
- Returns:
- the sequence number used to generate the hash
-
getKeySpec
<S extends KeySpec> S getKeySpec(Class<S> keySpecType) throws InvalidKeySpecException
- Specified by:
getKeySpec
in classAbstractPasswordImpl
- Throws:
InvalidKeySpecException
-
translate
Password translate(AlgorithmParameterSpec parameterSpec) throws InvalidKeyException, InvalidAlgorithmParameterException
- Overrides:
translate
in classAbstractPasswordImpl
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
verify
boolean verify(char[] guess) throws InvalidKeyException
- Specified by:
verify
in classAbstractPasswordImpl
- Throws:
InvalidKeyException
-
generateOTP
private static byte[] generateOTP(String algorithm, byte[] passPhrase, String seed, int sequenceNumber) throws SaslException
Generate a 64-bit OTP as specified in RFC 2289.- Parameters:
algorithm
- the OTP algorithm, must be either "otp-md5" or "otp-sha1"passPhrase
- the pass phrase, as a byte arrayseed
- the seedsequenceNumber
- the number of times the hash function will be applied- Returns:
- the 64-bit OTP hash
- Throws:
SaslException
- if the given OTP algorithm is invalid
-
computeHash
static byte[] computeHash(byte[] hash, String algorithm, MessageDigest messageDigest, int start, int end)
-
getMessageDigest
private static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
hashAndFold
private static byte[] hashAndFold(String algorithm, MessageDigest messageDigest, byte[] input)
Pass the given input through a hash function and fold the result to 64 bits.- Parameters:
algorithm
- the OTP algorithm, must be either "otp-md5" or "otp-sha1"messageDigest
- theMessageDigest
to use when generating the hashinput
- the data to hash- Returns:
- the folded hash
-
reverse
private static void reverse(byte[] bytes, int offset, int length)
-
convertibleTo
<T extends KeySpec> boolean convertibleTo(Class<T> keySpecType)
- Specified by:
convertibleTo
in classAbstractPasswordImpl
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classAbstractPasswordImpl
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in classAbstractPasswordImpl
-
readObject
private void readObject(ObjectInputStream ignored) throws NotSerializableException
- Throws:
NotSerializableException
-
writeReplace
Object writeReplace()
-
clone
public OneTimePasswordImpl clone()
Description copied from interface:Password
Creates and returns a copy of thisPassword
.- Specified by:
clone
in interfaceOneTimePassword
- Specified by:
clone
in interfaceOneWayPassword
- Specified by:
clone
in interfacePassword
- Specified by:
clone
in classAbstractPasswordImpl
- Returns:
- a copy of this
Password
.
-
-