private byte[] generateOtpHash(final String algorithm, final String passPhrase, final String seed, final int newSequenceNumber) throws NoSuchAlgorithmException, InvalidKeySpecException { PasswordFactory otpFactory = PasswordFactory.getInstance(algorithm, providers); OneTimePasswordAlgorithmSpec otpSpec = new OneTimePasswordAlgorithmSpec(algorithm, seed, newSequenceNumber); EncryptablePasswordSpec passwordSpec = new EncryptablePasswordSpec(passPhrase.toCharArray(), otpSpec); OneTimePassword otPassword = (OneTimePassword) otpFactory.generatePassword(passwordSpec); return otPassword.getHash(); } }
OneTimePasswordImpl(final OneTimePassword password) { this(password.getAlgorithm(), password.getHash().clone(), password.getSeed(), password.getSequenceNumber()); }
streamWriter.writeStartElement("otp"); streamWriter.writeAttribute("algorithm", otp.getAlgorithm()); streamWriter.writeAttribute("hash", ByteIterator.ofBytes(otp.getHash()).base64Encode().drainToString()); streamWriter.writeAttribute("seed", ByteIterator.ofBytes(otp.getSeed().getBytes(StandardCharsets.US_ASCII)).base64Encode().drainToString()); streamWriter.writeAttribute("sequence", Integer.toString(otp.getSequenceNumber()));
@Override public void persistCredential(final Credential credential) throws RealmUnavailableException { OneTimePassword password = credential.castAndApply(PasswordCredential.class, c -> c.getPassword(OneTimePassword.class)); try { Attributes attributes = new BasicAttributes(); attributes.put(algorithmAttributeName, password.getAlgorithm()); attributes.put(hashAttributeName, ByteIterator.ofBytes(password.getHash()).base64Encode().drainToString()); attributes.put(seedAttributeName, password.getSeed()); attributes.put(sequenceAttributeName, Integer.toString(password.getSequenceNumber())); context.modifyAttributes(distinguishedName, DirContext.REPLACE_ATTRIBUTE, attributes); } catch (NamingException e) { throw log.ldapRealmCredentialPersistingFailed(credential.toString(), distinguishedName, e); } }
previousSequenceNumber = previousPassword.getSequenceNumber(); validateSequenceNumber(previousSequenceNumber); previousHash = previousPassword.getHash();
private byte[] generateOtpHash(final String algorithm, final String passPhrase, final String seed, final int newSequenceNumber) throws NoSuchAlgorithmException, InvalidKeySpecException { PasswordFactory otpFactory = PasswordFactory.getInstance(algorithm, providers); OneTimePasswordAlgorithmSpec otpSpec = new OneTimePasswordAlgorithmSpec(algorithm, seed, newSequenceNumber); EncryptablePasswordSpec passwordSpec = new EncryptablePasswordSpec(passPhrase.toCharArray(), otpSpec); OneTimePassword otPassword = (OneTimePassword) otpFactory.generatePassword(passwordSpec); return otPassword.getHash(); } }
private byte[] generateOtpHash(final String algorithm, final String passPhrase, final String seed, final int newSequenceNumber) throws NoSuchAlgorithmException, InvalidKeySpecException { PasswordFactory otpFactory = PasswordFactory.getInstance(algorithm, providers); OneTimePasswordAlgorithmSpec otpSpec = new OneTimePasswordAlgorithmSpec(algorithm, seed, newSequenceNumber); EncryptablePasswordSpec passwordSpec = new EncryptablePasswordSpec(passPhrase.toCharArray(), otpSpec); OneTimePassword otPassword = (OneTimePassword) otpFactory.generatePassword(passwordSpec); return otPassword.getHash(); } }
private byte[] generateOtpHash(final String algorithm, final String passPhrase, final String seed, final int newSequenceNumber) throws NoSuchAlgorithmException, InvalidKeySpecException { PasswordFactory otpFactory = PasswordFactory.getInstance(algorithm, providers); OneTimePasswordAlgorithmSpec otpSpec = new OneTimePasswordAlgorithmSpec(algorithm, seed, newSequenceNumber); EncryptablePasswordSpec passwordSpec = new EncryptablePasswordSpec(passPhrase.toCharArray(), otpSpec); OneTimePassword otPassword = (OneTimePassword) otpFactory.generatePassword(passwordSpec); return otPassword.getHash(); } }
OneTimePasswordImpl(final OneTimePassword password) { this(password.getAlgorithm(), password.getHash().clone(), password.getSeed(), password.getSequenceNumber()); }
streamWriter.writeStartElement("otp"); streamWriter.writeAttribute("algorithm", otp.getAlgorithm()); streamWriter.writeAttribute("hash", ByteIterator.ofBytes(otp.getHash()).base64Encode().drainToString()); streamWriter.writeAttribute("seed", ByteIterator.ofBytes(otp.getSeed().getBytes(StandardCharsets.US_ASCII)).base64Encode().drainToString()); streamWriter.writeAttribute("sequence", Integer.toString(otp.getSequenceNumber()));
OneTimePasswordImpl(final OneTimePassword password) { this(password.getAlgorithm(), password.getHash().clone(), password.getSeed(), password.getSequenceNumber()); }
streamWriter.writeStartElement("otp"); streamWriter.writeAttribute("algorithm", otp.getAlgorithm()); streamWriter.writeAttribute("hash", ByteIterator.ofBytes(otp.getHash()).base64Encode().drainToString()); streamWriter.writeAttribute("seed", ByteIterator.ofBytes(otp.getSeed().getBytes(StandardCharsets.US_ASCII)).base64Encode().drainToString()); streamWriter.writeAttribute("sequence", Integer.toString(otp.getSequenceNumber()));
streamWriter.writeStartElement("otp"); streamWriter.writeAttribute("algorithm", otp.getAlgorithm()); streamWriter.writeAttribute("hash", ByteIterator.ofBytes(otp.getHash()).base64Encode().drainToString()); streamWriter.writeAttribute("seed", ByteIterator.ofBytes(otp.getSeed().getBytes(StandardCharsets.US_ASCII)).base64Encode().drainToString()); streamWriter.writeAttribute("sequence", Integer.toString(otp.getSequenceNumber()));
OneTimePasswordImpl(final OneTimePassword password) { this(password.getAlgorithm(), password.getHash().clone(), password.getSeed(), password.getSequenceNumber()); }
@Override public void persistCredential(final Credential credential) throws RealmUnavailableException { OneTimePassword password = credential.castAndApply(PasswordCredential.class, c -> c.getPassword(OneTimePassword.class)); try { Attributes attributes = new BasicAttributes(); attributes.put(algorithmAttributeName, password.getAlgorithm()); attributes.put(hashAttributeName, ByteIterator.ofBytes(password.getHash()).base64Encode().drainToString()); attributes.put(seedAttributeName, password.getSeed()); attributes.put(sequenceAttributeName, Integer.toString(password.getSequenceNumber())); context.modifyAttributes(distinguishedName, DirContext.REPLACE_ATTRIBUTE, attributes); } catch (NamingException e) { throw log.ldapRealmCredentialPersistingFailed(credential.toString(), distinguishedName, e); } }
@Override public void persistCredential(final Credential credential) throws RealmUnavailableException { OneTimePassword password = credential.castAndApply(PasswordCredential.class, c -> c.getPassword(OneTimePassword.class)); try { Attributes attributes = new BasicAttributes(); attributes.put(algorithmAttributeName, password.getAlgorithm()); attributes.put(hashAttributeName, ByteIterator.ofBytes(password.getHash()).base64Encode().drainToString()); attributes.put(seedAttributeName, password.getSeed()); attributes.put(sequenceAttributeName, Integer.toString(password.getSequenceNumber())); context.modifyAttributes(distinguishedName, DirContext.REPLACE_ATTRIBUTE, attributes); } catch (NamingException e) { throw log.ldapRealmCredentialPersistingFailed(credential.toString(), distinguishedName, e); } }
@Override public void persistCredential(final Credential credential) throws RealmUnavailableException { OneTimePassword password = credential.castAndApply(PasswordCredential.class, c -> c.getPassword(OneTimePassword.class)); try { Attributes attributes = new BasicAttributes(); attributes.put(algorithmAttributeName, password.getAlgorithm()); attributes.put(hashAttributeName, ByteIterator.ofBytes(password.getHash()).base64Encode().drainToString()); attributes.put(seedAttributeName, password.getSeed()); attributes.put(sequenceAttributeName, Integer.toString(password.getSequenceNumber())); context.modifyAttributes(distinguishedName, DirContext.REPLACE_ATTRIBUTE, attributes); } catch (NamingException e) { throw log.ldapRealmCredentialPersistingFailed(credential.toString(), distinguishedName, e); } }
previousSequenceNumber = previousPassword.getSequenceNumber(); validateSequenceNumber(previousSequenceNumber); previousHash = previousPassword.getHash();
previousSequenceNumber = previousPassword.getSequenceNumber(); validateSequenceNumber(previousSequenceNumber); previousHash = previousPassword.getHash();
previousSequenceNumber = previousPassword.getSequenceNumber(); validateSequenceNumber(previousSequenceNumber); previousHash = previousPassword.getHash();