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
APasswordimplementation forOneTimePassword.- Author:
- Farah Juma
-
-
Field Summary
Fields Modifier and Type Field Description private Stringalgorithmprivate byte[]hashprivate Stringseedprivate intsequenceNumberprivate static longserialVersionUID-
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 OneTimePasswordImplclone()Creates and returns a copy of thisPassword.(package private) <T extends KeySpec>
booleanconvertibleTo(Class<T> keySpecType)booleanequals(Object obj)private static byte[]generateOTP(String algorithm, byte[] passPhrase, String seed, int sequenceNumber)Generate a 64-bit OTP as specified in RFC 2289.StringgetAlgorithm()byte[]getHash()Get the hash represented by this password.(package private) <S extends KeySpec>
SgetKeySpec(Class<S> keySpecType)private static MessageDigestgetMessageDigest(String algorithm)StringgetSeed()Get the seed used to generate the hash.intgetSequenceNumber()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.inthashCode()private voidreadObject(ObjectInputStream ignored)private static voidreverse(byte[] bytes, int offset, int length)(package private) booleanverify(char[] guess)(package private) ObjectwriteReplace()-
Methods inherited from class org.wildfly.security.password.impl.AbstractPasswordImpl
getEncoded, getFormat, getNormalizedPasswordBytes, getNormalizedPasswordBytes, translate, 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:
getAlgorithmin interfaceKey
-
getHash
public byte[] getHash()
Description copied from interface:OneTimePasswordGet the hash represented by this password.- Specified by:
getHashin interfaceOneTimePassword- Returns:
- the hash represented by this password
-
getSeed
public String getSeed()
Description copied from interface:OneTimePasswordGet the seed used to generate the hash.- Specified by:
getSeedin interfaceOneTimePassword- Returns:
- the seed used to generate the hash
-
getSequenceNumber
public int getSequenceNumber()
Description copied from interface:OneTimePasswordGet the sequence number used to generate the hash.- Specified by:
getSequenceNumberin interfaceOneTimePassword- Returns:
- the sequence number used to generate the hash
-
getKeySpec
<S extends KeySpec> S getKeySpec(Class<S> keySpecType) throws InvalidKeySpecException
- Specified by:
getKeySpecin classAbstractPasswordImpl- Throws:
InvalidKeySpecException
-
verify
boolean verify(char[] guess) throws InvalidKeyException- Specified by:
verifyin 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
-
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- theMessageDigestto 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:
convertibleToin classAbstractPasswordImpl
-
hashCode
public int hashCode()
- Specified by:
hashCodein classAbstractPasswordImpl
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin classAbstractPasswordImpl
-
readObject
private void readObject(ObjectInputStream ignored) throws NotSerializableException
- Throws:
NotSerializableException
-
writeReplace
Object writeReplace()
-
clone
public OneTimePasswordImpl clone()
Description copied from interface:PasswordCreates and returns a copy of thisPassword.- Specified by:
clonein interfaceOneTimePassword- Specified by:
clonein interfaceOneWayPassword- Specified by:
clonein interfacePassword- Specified by:
clonein classAbstractPasswordImpl- Returns:
- a copy of this
Password.
-
-