CryptPasswordStorageScheme.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2010-2015 ForgeRock AS
* Portions Copyright 2012 Dariusz Janny <dariusz.janny@gmail.com>
*/
/**
* This class defines a Directory Server password storage scheme based on the
* UNIX Crypt algorithm. This is a legacy one-way digest algorithm
* intended only for situations where passwords have not yet been
* updated to modern hashes such as SHA-1 and friends. This
* implementation does perform weak salting, which means that it is more
* vulnerable to dictionary attacks than schemes with larger salts.
*/
public class CryptPasswordStorageScheme
{
/**
* The fully-qualified name of this class for debugging purposes.
*/
private static final String CLASS_NAME =
"org.opends.server.extensions.CryptPasswordStorageScheme";
/**
* The current configuration for the CryptPasswordStorageScheme.
*/
/**
* 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();
/**
* Creates a new instance of this password storage scheme. Note that no
* initialization should be performed here, as all initialization should be
* done in the <CODE>initializePasswordStorageScheme</CODE> method.
*/
public CryptPasswordStorageScheme()
{
super();
}
/**
* {@inheritDoc}
*/
public void initializePasswordStorageScheme(
throws ConfigException, InitializationException {
}
/**
* {@inheritDoc}
*/
public String getStorageSchemeName()
{
return STORAGE_SCHEME_NAME_CRYPT;
}
/**
* Encrypt plaintext password with the Unix Crypt algorithm.
*/
throws DirectoryException
{
byte[] plaintextBytes = null;
byte[] digestBytes;
try
{
// TODO: can we avoid this copy?
}
catch (Exception e)
{
message, e);
}
finally
{
if (plaintextBytes != null)
}
}
/**
* Return a random 2-byte salt.
*
* @return a random 2-byte salt
*/
private byte[] randomSalt() {
synchronized (saltLock)
{
return new byte[] {
};
}
}
throws DirectoryException
{
try
{
}
catch (Exception e)
{
message, e);
}
}
throws DirectoryException {
byte[] plaintextBytes = null;
try
{
}
catch (Exception e)
{
throw new DirectoryException(
}
finally
{
if (plaintextBytes != null)
}
}
throws DirectoryException {
byte[] plaintextBytes = null;
try
{
}
catch (Exception e)
{
throw new DirectoryException(
}
finally
{
if (plaintextBytes != null)
}
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
{
case UNIX:
break;
case MD5:
break;
case SHA256:
break;
case SHA512:
break;
}
return bytes;
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
}
/**
* Matches passwords encrypted with the Unix Crypt algorithm.
*/
{
// TODO: Can we avoid this copy?
byte[] plaintextPasswordBytes = null;
try
{
// 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.
}
catch (Exception e)
{
return false;
}
finally
{
if (plaintextPasswordBytes != null)
}
}
{
try
{
}
catch (Exception e)
{
return false;
}
}
byte[] plaintextPasswordBytes = null;
try
{
}
catch (Exception e)
{
return false;
}
finally
{
if (plaintextPasswordBytes != null)
}
}
byte[] plaintextPasswordBytes = null;
try
{
}
catch (Exception e)
{
return false;
}
finally
{
if (plaintextPasswordBytes != null)
}
}
/**
* {@inheritDoc}
*/
{
{
}
{
}
{
}
else
{
}
}
/**
* {@inheritDoc}
*/
public boolean supportsAuthPasswordSyntax()
{
// This storage scheme does not support the authentication password syntax.
return false;
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
}
/**
* {@inheritDoc}
*/
{
// This storage scheme does not support the authentication password syntax.
return false;
}
/**
* {@inheritDoc}
*/
public boolean isReversible()
{
return false;
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
}
/**
* {@inheritDoc}
*/
public boolean isStorageSchemeSecure()
{
// FIXME:
// Technically, this isn't quite in keeping with the original spirit of
// this method, since the point was to determine whether the scheme could
// be trivially reversed. I'm not sure I would put crypt into that
// category, but it's certainly a lot more vulnerable to lookup tables
// than most other algorithms. I'd say we can keep it this way for now,
// but it might be something to reconsider later.
//
// Currently, this method is unused. However, the intended purpose is
// eventually for use in issue #321, where we could do things like prevent
// even authorized users from seeing the password value over an insecure
// connection if it isn't considered secure.
return false;
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationAcceptable(
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
// If we've gotten this far, then we'll accept the change.
return true;
}
/** {@inheritDoc} */
{
return new ConfigChangeResult();
}
}