| | |
| | | |
| | | |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.std.server.RC4PasswordStorageSchemeCfg; |
| | | import org.opends.server.api.PasswordStorageScheme; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public ByteString encodePassword(ByteString plaintext) |
| | | public ByteString encodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_RC4, |
| | | KEY_SIZE_RC4, |
| | | plaintext.value()); |
| | | return ByteStringFactory.create(Base64.encode(encodedBytes)); |
| | | plaintextBytes); |
| | | return ByteString.valueOf(Base64.encode(encodedBytes)); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public ByteString encodePasswordWithScheme(ByteString plaintext) |
| | | public ByteString encodePasswordWithScheme(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | StringBuilder buffer = new StringBuilder(); |
| | |
| | | |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_RC4, |
| | | KEY_SIZE_RC4, |
| | | plaintext.value()); |
| | | plaintextBytes); |
| | | buffer.append(Base64.encode(encodedBytes)); |
| | | } |
| | | catch (Exception e) |
| | |
| | | m, e); |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | try |
| | | { |
| | | byte[] decryptedPassword = |
| | | cryptoManager.decrypt(Base64.decode(storedPassword.stringValue())); |
| | | return Arrays.equals(plaintextPassword.value(), decryptedPassword); |
| | | ByteString decryptedPassword = |
| | | ByteString.wrap(cryptoManager.decrypt( |
| | | Base64.decode(storedPassword.toString()))); |
| | | return plaintextPassword.equals(decryptedPassword); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public ByteString getPlaintextValue(ByteString storedPassword) |
| | | public ByteString getPlaintextValue(ByteSequence storedPassword) |
| | | throws DirectoryException |
| | | { |
| | | try |
| | | { |
| | | byte[] decryptedPassword = |
| | | cryptoManager.decrypt(Base64.decode(storedPassword.stringValue())); |
| | | return ByteStringFactory.create(decryptedPassword); |
| | | cryptoManager.decrypt(Base64.decode(storedPassword.toString())); |
| | | return ByteString.wrap(decryptedPassword); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | * {@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. |