| | |
| | | * |
| | | * |
| | | * 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; |