| | |
| | | |
| | | |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Random; |
| | | |
| | | import org.opends.messages.Message; |
| | |
| | | import org.opends.server.api.PasswordStorageScheme; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.ByteStringFactory; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.Crypt; |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public ByteString encodePassword(ByteString plaintext) |
| | | public ByteString encodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | |
| | |
| | | |
| | | try |
| | | { |
| | | digestBytes = crypt.crypt(plaintext.value(), randomSalt()); |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | digestBytes = crypt.crypt(plaintextBytes, randomSalt()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | message, e); |
| | | } |
| | | |
| | | return ByteStringFactory.create(digestBytes); |
| | | return ByteString.wrap(digestBytes); |
| | | } |
| | | |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public ByteString encodePasswordWithScheme(ByteString plaintext) |
| | | public ByteString encodePasswordWithScheme(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | StringBuilder buffer = |
| | |
| | | |
| | | buffer.append(encodePassword(plaintext)); |
| | | |
| | | return ByteStringFactory.create(buffer.toString()); |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | | |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public boolean passwordMatches(ByteString plaintextPassword, |
| | | ByteString storedPassword) |
| | | public boolean passwordMatches(ByteSequence plaintextPassword, |
| | | ByteSequence storedPassword) |
| | | { |
| | | byte[] storedPWDigestBytes = storedPassword.value(); |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | |
| | | byte[] userPWDigestBytes; |
| | | ByteString userPWDigestBytes; |
| | | try |
| | | { |
| | | // The salt is stored as the first two bytes of the storedPassword |
| | | // value, and crypt.crypt() only looks at the first two bytes, so |
| | | // we can pass it in directly. |
| | | byte[] salt = storedPWDigestBytes; |
| | | |
| | | userPWDigestBytes = crypt.crypt(plaintextPassword.value(), salt); |
| | | byte[] salt = storedPassword.copyTo(new byte[2]); |
| | | userPWDigestBytes = |
| | | ByteString.wrap(crypt.crypt(plaintextPasswordBytes, salt)); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | return Arrays.equals(userPWDigestBytes, storedPWDigestBytes); |
| | | return userPWDigestBytes.equals(storedPassword); |
| | | } |
| | | |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public ByteString encodeAuthPassword(ByteString plaintext) |
| | | public ByteString encodeAuthPassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | Message message = |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public boolean authPasswordMatches(ByteString plaintextPassword, |
| | | public boolean authPasswordMatches(ByteSequence plaintextPassword, |
| | | String authInfo, String authValue) |
| | | { |
| | | // This storage scheme does not support the authentication password syntax. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public ByteString getPlaintextValue(ByteString storedPassword) |
| | | public ByteString getPlaintextValue(ByteSequence storedPassword) |
| | | throws DirectoryException |
| | | { |
| | | Message message = |