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/SaltedSHA512PasswordStorageScheme.java | 71 ++++++++++++++++-------------------
1 files changed, 33 insertions(+), 38 deletions(-)
diff --git a/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java
index b8c9480..b0a6bcf 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.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.*;
@@ -159,14 +154,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;
@@ -176,7 +171,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.
@@ -203,7 +198,7 @@
System.arraycopy(saltBytes, 0, hashPlusSalt, digestBytes.length,
NUM_SALT_BYTES);
- return ByteStringFactory.create(Base64.encode(hashPlusSalt));
+ return ByteString.valueOf(Base64.encode(hashPlusSalt));
}
@@ -212,7 +207,7 @@
* {@inheritDoc}
*/
@Override()
- public ByteString encodePasswordWithScheme(ByteString plaintext)
+ public ByteString encodePasswordWithScheme(ByteSequence plaintext)
throws DirectoryException
{
StringBuilder buffer = new StringBuilder();
@@ -220,11 +215,11 @@
buffer.append(STORAGE_SCHEME_NAME_SALTED_SHA_512);
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;
@@ -234,7 +229,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.
@@ -262,7 +257,7 @@
NUM_SALT_BYTES);
buffer.append(Base64.encode(hashPlusSalt));
- return ByteStringFactory.create(buffer.toString());
+ return ByteString.valueOf(buffer.toString());
}
@@ -271,15 +266,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];
@@ -295,17 +290,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;
@@ -359,14 +354,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;
@@ -376,7 +371,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.
@@ -405,7 +400,7 @@
authPWValue.append('$');
authPWValue.append(Base64.encode(digestBytes));
- return ByteStringFactory.create(authPWValue.toString());
+ return ByteString.valueOf(authPWValue.toString());
}
@@ -414,7 +409,7 @@
* {@inheritDoc}
*/
@Override()
- public boolean authPasswordMatches(ByteString plaintextPassword,
+ public boolean authPasswordMatches(ByteSequence plaintextPassword,
String authInfo, String authValue)
{
byte[] saltBytes;
@@ -435,10 +430,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)
@@ -465,7 +460,7 @@
* {@inheritDoc}
*/
@Override()
- public ByteString getPlaintextValue(ByteString storedPassword)
+ public ByteString getPlaintextValue(ByteSequence storedPassword)
throws DirectoryException
{
Message message =
--
Gitblit v1.10.0