From 22094368c2865dcfb6daf8366425212b721a4657 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 05 Feb 2009 17:42:14 +0000
Subject: [PATCH] Merge ASN1 branch to trunk
---
opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java | 71 ++++++++++++++++-------------------
1 files changed, 33 insertions(+), 38 deletions(-)
diff --git a/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
index ed111d6..18d63f2 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
@@ -39,12 +39,7 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.ErrorLogger;
import org.opends.server.loggers.debug.DebugTracer;
-import org.opends.server.types.ByteString;
-import org.opends.server.types.ByteStringFactory;
-import org.opends.server.types.DebugLogLevel;
-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.Base64;
import static org.opends.messages.ExtensionMessages.*;
@@ -157,14 +152,14 @@
* {@inheritDoc}
*/
@Override()
- public ByteString encodePassword(ByteString plaintext)
+ public ByteString encodePassword(ByteSequence plaintext)
throws DirectoryException
{
- byte[] plainBytes = plaintext.value();
+ int plainBytesLength = plaintext.length();
byte[] saltBytes = new byte[NUM_SALT_BYTES];
- byte[] plainPlusSalt = new byte[plainBytes.length + NUM_SALT_BYTES];
+ byte[] plainPlusSalt = new byte[plainBytesLength + NUM_SALT_BYTES];
- System.arraycopy(plainBytes, 0, plainPlusSalt,0,plainBytes.length);
+ plaintext.copyTo(plainPlusSalt);
byte[] digestBytes;
@@ -174,7 +169,7 @@
{
// Generate the salt and put in the plain+salt array.
random.nextBytes(saltBytes);
- System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
+ System.arraycopy(saltBytes,0, plainPlusSalt, plainBytesLength,
NUM_SALT_BYTES);
// Create the hash from the concatenated value.
@@ -201,7 +196,7 @@
System.arraycopy(saltBytes, 0, hashPlusSalt, digestBytes.length,
NUM_SALT_BYTES);
- return ByteStringFactory.create(Base64.encode(hashPlusSalt));
+ return ByteString.valueOf(Base64.encode(hashPlusSalt));
}
@@ -210,7 +205,7 @@
* {@inheritDoc}
*/
@Override()
- public ByteString encodePasswordWithScheme(ByteString plaintext)
+ public ByteString encodePasswordWithScheme(ByteSequence plaintext)
throws DirectoryException
{
StringBuilder buffer = new StringBuilder();
@@ -218,11 +213,11 @@
buffer.append(STORAGE_SCHEME_NAME_SALTED_SHA_1);
buffer.append('}');
- byte[] plainBytes = plaintext.value();
+ int plainBytesLength = plaintext.length();
byte[] saltBytes = new byte[NUM_SALT_BYTES];
- byte[] plainPlusSalt = new byte[plainBytes.length + NUM_SALT_BYTES];
+ byte[] plainPlusSalt = new byte[plainBytesLength + NUM_SALT_BYTES];
- System.arraycopy(plainBytes, 0, plainPlusSalt,0,plainBytes.length);
+ plaintext.copyTo(plainPlusSalt);
byte[] digestBytes;
@@ -232,7 +227,7 @@
{
// Generate the salt and put in the plain+salt array.
random.nextBytes(saltBytes);
- System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
+ System.arraycopy(saltBytes,0, plainPlusSalt, plainBytesLength,
NUM_SALT_BYTES);
// Create the hash from the concatenated value.
@@ -260,7 +255,7 @@
NUM_SALT_BYTES);
buffer.append(Base64.encode(hashPlusSalt));
- return ByteStringFactory.create(buffer.toString());
+ return ByteString.valueOf(buffer.toString());
}
@@ -269,15 +264,15 @@
* {@inheritDoc}
*/
@Override()
- public boolean passwordMatches(ByteString plaintextPassword,
- ByteString storedPassword)
+ public boolean passwordMatches(ByteSequence plaintextPassword,
+ ByteSequence storedPassword)
{
// Base64-decode the stored value and take the last 8 bytes as the salt.
byte[] saltBytes = new byte[NUM_SALT_BYTES];
byte[] digestBytes;
try
{
- byte[] decodedBytes = Base64.decode(storedPassword.stringValue());
+ byte[] decodedBytes = Base64.decode(storedPassword.toString());
int digestLength = decodedBytes.length - NUM_SALT_BYTES;
digestBytes = new byte[digestLength];
@@ -293,17 +288,17 @@
}
Message message = ERR_PWSCHEME_CANNOT_BASE64_DECODE_STORED_PASSWORD.get(
- storedPassword.stringValue(), String.valueOf(e));
+ storedPassword.toString(), String.valueOf(e));
ErrorLogger.logError(message);
return false;
}
// Use the salt to generate a digest based on the provided plain-text value.
- byte[] plainBytes = plaintextPassword.value();
- byte[] plainPlusSalt = new byte[plainBytes.length + NUM_SALT_BYTES];
- System.arraycopy(plainBytes, 0, plainPlusSalt, 0, plainBytes.length);
- System.arraycopy(saltBytes, 0,plainPlusSalt, plainBytes.length,
+ int plainBytesLength = plaintextPassword.length();
+ byte[] plainPlusSalt = new byte[plainBytesLength + NUM_SALT_BYTES];
+ plaintextPassword.copyTo(plainPlusSalt);
+ System.arraycopy(saltBytes, 0,plainPlusSalt, plainBytesLength,
NUM_SALT_BYTES);
byte[] userDigestBytes;
@@ -357,14 +352,14 @@
* {@inheritDoc}
*/
@Override()
- public ByteString encodeAuthPassword(ByteString plaintext)
+ public ByteString encodeAuthPassword(ByteSequence plaintext)
throws DirectoryException
{
- byte[] plainBytes = plaintext.value();
+ int plaintextLength = plaintext.length();
byte[] saltBytes = new byte[NUM_SALT_BYTES];
- byte[] plainPlusSalt = new byte[plainBytes.length + NUM_SALT_BYTES];
+ byte[] plainPlusSalt = new byte[plaintextLength + NUM_SALT_BYTES];
- System.arraycopy(plainBytes, 0, plainPlusSalt, 0, plainBytes.length);
+ plaintext.copyTo(plainPlusSalt);
byte[] digestBytes;
@@ -374,7 +369,7 @@
{
// Generate the salt and put in the plain+salt array.
random.nextBytes(saltBytes);
- System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
+ System.arraycopy(saltBytes,0, plainPlusSalt, plaintextLength,
NUM_SALT_BYTES);
// Create the hash from the concatenated value.
@@ -403,7 +398,7 @@
authPWValue.append('$');
authPWValue.append(Base64.encode(digestBytes));
- return ByteStringFactory.create(authPWValue.toString());
+ return ByteString.valueOf(authPWValue.toString());
}
@@ -412,7 +407,7 @@
* {@inheritDoc}
*/
@Override()
- public boolean authPasswordMatches(ByteString plaintextPassword,
+ public boolean authPasswordMatches(ByteSequence plaintextPassword,
String authInfo, String authValue)
{
byte[] saltBytes;
@@ -433,10 +428,10 @@
}
- byte[] plainBytes = plaintextPassword.value();
- byte[] plainPlusSaltBytes = new byte[plainBytes.length + saltBytes.length];
- System.arraycopy(plainBytes, 0, plainPlusSaltBytes, 0, plainBytes.length);
- System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytes.length,
+ int plainBytesLength = plaintextPassword.length();
+ byte[] plainPlusSaltBytes = new byte[plainBytesLength + saltBytes.length];
+ plaintextPassword.copyTo(plainPlusSaltBytes);
+ System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytesLength,
saltBytes.length);
synchronized (digestLock)
@@ -463,7 +458,7 @@
* {@inheritDoc}
*/
@Override()
- public ByteString getPlaintextValue(ByteString storedPassword)
+ public ByteString getPlaintextValue(ByteSequence storedPassword)
throws DirectoryException
{
Message message =
--
Gitblit v1.10.0