| | |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2010-2013 ForgeRock AS |
| | | * Portions Copyright 2012 Dariusz Janny <dariusz.janny@gmail.com> |
| | | * |
| | | */ |
| | | |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | import java.util.Random; |
| | | |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | | import org.opends.server.admin.std.server.PasswordStorageSchemeCfg; |
| | | import org.opends.server.admin.std.server.CryptPasswordStorageSchemeCfg; |
| | | import org.opends.server.admin.std.server.PasswordStorageSchemeCfg; |
| | | import org.opends.server.api.PasswordStorageScheme; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.Crypt; |
| | | import org.opends.server.util.BSDMD5Crypt; |
| | | import org.opends.server.util.Crypt; |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | import static org.opends.server.extensions.ExtensionsConstants.*; |
| | | import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString; |
| | | |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | /** |
| | | * This class defines a Directory Server password storage scheme based on the |
| | |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.extensions.CryptPasswordStorageScheme"; |
| | | |
| | | /* |
| | | /** |
| | | * The current configuration for the CryptPasswordStorageScheme |
| | | */ |
| | | private CryptPasswordStorageSchemeCfg currentConfig; |
| | |
| | | /** |
| | | * An array of values that can be used to create salt characters |
| | | * when encoding new crypt hashes. |
| | | * */ |
| | | */ |
| | | private static final byte[] SALT_CHARS = |
| | | ("./0123456789abcdefghijklmnopqrstuvwxyz" |
| | | +"ABCDEFGHIJKLMNOPQRSTUVWXYZ").getBytes(); |
| | |
| | | private final Random randomSaltIndex = new Random(); |
| | | private final Object saltLock = new Object(); |
| | | private final Crypt crypt = new Crypt(); |
| | | private final BSDMD5Crypt bsdmd5crypt = new BSDMD5Crypt(); |
| | | |
| | | |
| | | /** |
| | |
| | | /** |
| | | * Encrypt plaintext password with the Unix Crypt algorithm. |
| | | */ |
| | | |
| | | private ByteString unixCryptEncodePassword(ByteSequence plaintext) |
| | | throws DirectoryException |
| | | { |
| | |
| | | private byte[] randomSalt() { |
| | | synchronized (saltLock) |
| | | { |
| | | byte[] salt = new byte[2]; |
| | | int sb1 = randomSaltIndex.nextInt(SALT_CHARS.length); |
| | | int sb2 = randomSaltIndex.nextInt(SALT_CHARS.length); |
| | | salt[0] = SALT_CHARS[sb1]; |
| | | salt[1] = SALT_CHARS[sb2]; |
| | | |
| | | return salt; |
| | | return new byte[] { |
| | | SALT_CHARS[sb1], |
| | | SALT_CHARS[sb2], |
| | | }; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | |
| | | CryptPasswordStorageSchemeCfg config = |
| | | (CryptPasswordStorageSchemeCfg) configuration; |
| | | return isConfigurationChangeAcceptable(config, unacceptableReasons); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean isConfigurationChangeAcceptable( |
| | | CryptPasswordStorageSchemeCfg configuration, |
| | | List<Message> unacceptableReasons) |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange( |
| | | CryptPasswordStorageSchemeCfg configuration) |
| | | { |
| | | ResultCode resultCode = ResultCode.SUCCESS; |
| | | boolean adminActionRequired = false; |
| | | ArrayList<Message> messages = new ArrayList<Message>(); |
| | | List<Message> messages = new ArrayList<Message>(); |
| | | |
| | | |
| | | currentConfig = configuration; |