CR-2005 Fix OPENDJ-1036 Cleanup passwords in memory?
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock, AS |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.Base64; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | import static org.opends.server.extensions.ExtensionsConstants.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | |
| | | public ByteString encodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | byte[] plaintextBytes = null; |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_AES, |
| | | KEY_SIZE_AES, |
| | | plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | buffer.append('{'); |
| | | buffer.append(STORAGE_SCHEME_NAME_AES); |
| | | buffer.append('}'); |
| | | |
| | | byte[] plaintextBytes = null; |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_AES, |
| | | KEY_SIZE_AES, |
| | | plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.Base64; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | import static org.opends.server.extensions.ExtensionsConstants.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | |
| | | public ByteString encodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | byte[] plaintextBytes = null; |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = |
| | | cryptoManager.encrypt(CIPHER_TRANSFORMATION_BLOWFISH, |
| | | KEY_SIZE_BLOWFISH, plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | buffer.append('{'); |
| | | buffer.append(STORAGE_SCHEME_NAME_BLOWFISH); |
| | | buffer.append('}'); |
| | | byte[] plaintextBytes = null; |
| | | |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = |
| | | cryptoManager.encrypt(CIPHER_TRANSFORMATION_BLOWFISH, |
| | | KEY_SIZE_BLOWFISH, plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | import java.util.Random; |
| | |
| | | private ByteString unixCryptEncodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | |
| | | byte[] plaintextBytes = null; |
| | | byte[] digestBytes; |
| | | |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | // TODO: can we avoid this copy? |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | digestBytes = crypt.crypt(plaintextBytes, randomSalt()); |
| | | } |
| | | catch (Exception e) |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | |
| | | return ByteString.wrap(digestBytes); |
| | | } |
| | |
| | | private ByteString sha256CryptEncodePassword(ByteSequence plaintext) |
| | | throws DirectoryException { |
| | | String output; |
| | | byte[] plaintextBytes = null; |
| | | |
| | | try |
| | | { |
| | | output = Sha2Crypt.sha256Crypt(plaintext.toByteArray()); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | output = Sha2Crypt.sha256Crypt(plaintextBytes); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | throw new DirectoryException( |
| | | DirectoryServer.getServerErrorResultCode(), message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | return ByteString.valueOf(output); |
| | | } |
| | | |
| | | private ByteString sha512CryptEncodePassword(ByteSequence plaintext) |
| | | throws DirectoryException { |
| | | String output; |
| | | byte[] plaintextBytes = null; |
| | | |
| | | try |
| | | { |
| | | output = Sha2Crypt.sha512Crypt(plaintext.toByteArray()); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | output = Sha2Crypt.sha512Crypt(plaintextBytes); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | throw new DirectoryException( |
| | | DirectoryServer.getServerErrorResultCode(), message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | return ByteString.valueOf(output); |
| | | } |
| | | |
| | |
| | | ByteSequence storedPassword) |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | byte[] plaintextPasswordBytes = null; |
| | | |
| | | ByteString userPWDigestBytes; |
| | | try |
| | | { |
| | | plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | // 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. |
| | |
| | | { |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextPasswordBytes != null) |
| | | Arrays.fill(plaintextPasswordBytes, (byte) 0); |
| | | } |
| | | |
| | | return userPWDigestBytes.equals(storedPassword); |
| | | } |
| | |
| | | |
| | | private boolean sha256CryptPasswordMatches(ByteSequence plaintextPassword, |
| | | ByteSequence storedPassword) { |
| | | byte[] plaintextPasswordBytes = null; |
| | | String storedString = storedPassword.toString(); |
| | | try |
| | | { |
| | | plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | String userString = Sha2Crypt.sha256Crypt( |
| | | plaintextPassword.toByteArray(), storedString); |
| | | plaintextPasswordBytes, storedString); |
| | | return userString.equals(storedString); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextPasswordBytes != null) |
| | | Arrays.fill(plaintextPasswordBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | private boolean sha512CryptPasswordMatches(ByteSequence plaintextPassword, |
| | | ByteSequence storedPassword) { |
| | | byte[] plaintextPasswordBytes = null; |
| | | String storedString = storedPassword.toString(); |
| | | try |
| | | { |
| | | plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | String userString = Sha2Crypt.sha512Crypt( |
| | | plaintextPassword.toByteArray(), storedString); |
| | | plaintextPasswordBytes, storedString); |
| | | return userString.equals(storedString); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextPasswordBytes != null) |
| | | Arrays.fill(plaintextPasswordBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | |
| | | import java.security.MessageDigest; |
| | | import java.util.Arrays; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.std.server.MD5PasswordStorageSchemeCfg; |
| | |
| | | throws DirectoryException |
| | | { |
| | | byte[] digestBytes; |
| | | byte[] plaintextBytes = null; |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | digestBytes = messageDigest.digest(plaintextBytes); |
| | | } |
| | | catch (Exception e) |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(Base64.encode(digestBytes)); |
| | |
| | | buffer.append(STORAGE_SCHEME_NAME_MD5); |
| | | buffer.append('}'); |
| | | |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | byte[] plaintextBytes = null; |
| | | byte[] digestBytes; |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | digestBytes = messageDigest.digest(plaintextBytes); |
| | | } |
| | | catch (Exception e) |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | buffer.append(Base64.encode(digestBytes)); |
| | |
| | | public boolean passwordMatches(ByteSequence plaintextPassword, |
| | | ByteSequence storedPassword) |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | byte[] plaintextPasswordBytes = null; |
| | | ByteString userPWDigestBytes; |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | userPWDigestBytes = |
| | | ByteString.wrap(messageDigest.digest(plaintextPasswordBytes)); |
| | | } |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextPasswordBytes != null) |
| | | Arrays.fill(plaintextPasswordBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | ByteString storedPWDigestBytes; |
| | |
| | | public ByteString encodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | byte[] saltBytes = new byte[NUM_SALT_BYTES]; |
| | | byte[] saltBytes = new byte[NUM_SALT_BYTES]; |
| | | byte[] digestBytes; |
| | | int iterations = config.getPBKDF2Iterations(); |
| | | char[] plaintextChars = null; |
| | | int iterations = config.getPBKDF2Iterations(); |
| | | |
| | | synchronized(factoryLock) |
| | | { |
| | |
| | | { |
| | | random.nextBytes(saltBytes); |
| | | |
| | | KeySpec spec = new PBEKeySpec(plaintext.toString().toCharArray(), |
| | | plaintextChars = plaintext.toString().toCharArray(); |
| | | KeySpec spec = new PBEKeySpec(plaintextChars, |
| | | saltBytes, iterations, SHA1_LENGTH * 8); |
| | | digestBytes = factory.generateSecret(spec).getEncoded(); |
| | | } |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextChars != null) |
| | | Arrays.fill(plaintextChars, '0'); |
| | | } |
| | | } |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | | byte[] hashPlusSalt = new byte[digestBytes.length + NUM_SALT_BYTES]; |
| | |
| | | saltLength); |
| | | |
| | | byte[] userDigestBytes; |
| | | char[] plaintextChars = null; |
| | | |
| | | synchronized (factoryLock) |
| | | { |
| | | try |
| | | { |
| | | plaintextChars = plaintextPassword.toString().toCharArray(); |
| | | KeySpec spec = new PBEKeySpec( |
| | | plaintextPassword.toString().toCharArray(), saltBytes, |
| | | plaintextChars, saltBytes, |
| | | iterations, SHA1_LENGTH * 8); |
| | | userDigestBytes = factory.generateSecret(spec).getEncoded(); |
| | | } |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextChars != null) |
| | | Arrays.fill(plaintextChars, '0'); |
| | | } |
| | | } |
| | | |
| | | return Arrays.equals(digestBytes, userDigestBytes); |
| | |
| | | public ByteString encodeAuthPassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | byte[] saltBytes = new byte[NUM_SALT_BYTES]; |
| | | byte[] saltBytes = new byte[NUM_SALT_BYTES]; |
| | | byte[] digestBytes; |
| | | int iterations = config.getPBKDF2Iterations(); |
| | | char[] plaintextChars = null; |
| | | int iterations = config.getPBKDF2Iterations(); |
| | | |
| | | synchronized(factoryLock) |
| | | { |
| | |
| | | { |
| | | random.nextBytes(saltBytes); |
| | | |
| | | plaintextChars = plaintext.toString().toCharArray(); |
| | | KeySpec spec = new PBEKeySpec( |
| | | plaintext.toString().toCharArray(), saltBytes, |
| | | plaintextChars, saltBytes, |
| | | iterations, SHA1_LENGTH * 8); |
| | | digestBytes = factory.generateSecret(spec).getEncoded(); |
| | | } |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextChars != null) |
| | | Arrays.fill(plaintextChars, '0'); |
| | | } |
| | | } |
| | | // Encode and return the value. |
| | | StringBuilder authPWValue = new StringBuilder(); |
| | |
| | | saltBytes.length); |
| | | |
| | | byte[] userDigestBytes; |
| | | char[] plaintextChars = null; |
| | | |
| | | synchronized (factoryLock) |
| | | { |
| | | try |
| | | { |
| | | plaintextChars = plaintextPassword.toString().toCharArray(); |
| | | KeySpec spec = new PBEKeySpec( |
| | | plaintextPassword.toString().toCharArray(), saltBytes, |
| | | plaintextChars, saltBytes, |
| | | iterations, SHA1_LENGTH * 8); |
| | | userDigestBytes = factory.generateSecret(spec).getEncoded(); |
| | | } |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextChars != null) |
| | | Arrays.fill(plaintextChars, '0'); |
| | | } |
| | | } |
| | | |
| | | return Arrays.equals(digestBytes, userDigestBytes); |
| | |
| | | public static String encodeOffline(byte[] passwordBytes) |
| | | throws DirectoryException |
| | | { |
| | | byte[] saltBytes = new byte[NUM_SALT_BYTES]; |
| | | byte[] saltBytes = new byte[NUM_SALT_BYTES]; |
| | | byte[] digestBytes; |
| | | int iterations = 10000; |
| | | char[] plaintextChars = null; |
| | | int iterations = 10000; |
| | | |
| | | try |
| | | { |
| | | SecureRandom.getInstance(SECURE_PRNG_SHA1).nextBytes(saltBytes); |
| | | |
| | | plaintextChars = passwordBytes.toString().toCharArray(); |
| | | KeySpec spec = new PBEKeySpec( |
| | | passwordBytes.toString().toCharArray(), saltBytes, |
| | | plaintextChars, saltBytes, |
| | | iterations, SHA1_LENGTH * 8); |
| | | digestBytes = SecretKeyFactory |
| | | .getInstance(MESSAGE_DIGEST_ALGORITHM_PBKDF2) |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextChars != null) |
| | | Arrays.fill(plaintextChars, '0'); |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | | byte[] hashPlusSalt = new byte[digestBytes.length + NUM_SALT_BYTES]; |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.Base64; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | import static org.opends.server.extensions.ExtensionsConstants.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | |
| | | public ByteString encodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | byte[] plaintextBytes = null; |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_RC4, |
| | | KEY_SIZE_RC4, |
| | | plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | buffer.append('{'); |
| | | buffer.append(STORAGE_SCHEME_NAME_RC4); |
| | | buffer.append('}'); |
| | | byte[] plaintextBytes = null; |
| | | |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_RC4, |
| | | KEY_SIZE_RC4, |
| | | plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | |
| | | import java.security.MessageDigest; |
| | | import java.util.Arrays; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.std.server.SHA1PasswordStorageSchemeCfg; |
| | |
| | | throws DirectoryException |
| | | { |
| | | byte[] digestBytes; |
| | | byte[] plaintextBytes = null; |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | digestBytes = messageDigest.digest(plaintextBytes); |
| | | } |
| | | catch (Exception e) |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(Base64.encode(digestBytes)); |
| | |
| | | buffer.append('}'); |
| | | |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | byte[] plaintextBytes = null; |
| | | byte[] digestBytes; |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | try |
| | | { |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | digestBytes = messageDigest.digest(plaintextBytes); |
| | | } |
| | | catch (Exception e) |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | buffer.append(Base64.encode(digestBytes)); |
| | |
| | | ByteSequence storedPassword) |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | byte[] plaintextPasswordBytes = null; |
| | | ByteString userPWDigestBytes; |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | try |
| | | { |
| | | plaintextPasswordBytes = plaintextPassword.toByteArray(); |
| | | userPWDigestBytes = |
| | | ByteString.wrap(messageDigest.digest(plaintextPasswordBytes)); |
| | | } |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextPasswordBytes != null) |
| | | Arrays.fill(plaintextPasswordBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | ByteString storedPWDigestBytes; |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | return Arrays.equals(digestBytes, userDigestBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | try |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSaltBytes, (byte) 0); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2010 ForgeRock AS. |
| | | * Portions Copyright 2010-2013 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | return Arrays.equals(digestBytes, userDigestBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | try |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSaltBytes, (byte) 0); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | System.arraycopy(digestBytes, 0, digestPlusSalt, 0, digestBytes.length); |
| | | System.arraycopy(saltBytes, 0, digestPlusSalt, digestBytes.length, |
| | | NUM_SALT_BYTES); |
| | | Arrays.fill(passwordPlusSalt, (byte) 0); |
| | | |
| | | return "{" + STORAGE_SCHEME_NAME_SALTED_SHA_1 + "}" + |
| | | Base64.encode(digestPlusSalt); |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2010 ForgeRock AS. |
| | | * Portions Copyright 2010-2013 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | return Arrays.equals(digestBytes, userDigestBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | try |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSaltBytes, (byte) 0); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2010 ForgeRock AS. |
| | | * Portions Copyright 2010-2013 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | return Arrays.equals(digestBytes, userDigestBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | try |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSaltBytes, (byte) 0); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2010 ForgeRock AS. |
| | | * Portions Copyright 2010-2013 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | // Append the salt to the hashed value and base64-the whole thing. |
| | |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | return Arrays.equals(digestBytes, userDigestBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSalt, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | try |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | Arrays.fill(plainPlusSaltBytes, (byte) 0); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | System.arraycopy(digestBytes, 0, digestPlusSalt, 0, digestBytes.length); |
| | | System.arraycopy(saltBytes, 0, digestPlusSalt, digestBytes.length, |
| | | NUM_SALT_BYTES); |
| | | Arrays.fill(passwordPlusSalt, (byte) 0); |
| | | |
| | | return "{" + STORAGE_SCHEME_NAME_SALTED_SHA_512 + "}" + |
| | | Base64.encode(digestPlusSalt); |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.Base64; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | import static org.opends.server.extensions.ExtensionsConstants.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | |
| | | public ByteString encodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | | byte[] plaintextBytes = null; |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_3DES, |
| | | KEY_SIZE_3DES, |
| | | plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | buffer.append('{'); |
| | | buffer.append(STORAGE_SCHEME_NAME_3DES); |
| | | buffer.append('}'); |
| | | byte[] plaintextBytes = null; |
| | | |
| | | try |
| | | { |
| | | // TODO: Can we avoid this copy? |
| | | byte[] plaintextBytes = plaintext.toByteArray(); |
| | | plaintextBytes = plaintext.toByteArray(); |
| | | byte[] encodedBytes = cryptoManager.encrypt(CIPHER_TRANSFORMATION_3DES, |
| | | KEY_SIZE_3DES, |
| | | plaintextBytes); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | m, e); |
| | | } |
| | | finally |
| | | { |
| | | if (plaintextBytes != null) |
| | | Arrays.fill(plaintextBytes, (byte) 0); |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |