You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2002/07/01 18:33:38 UTC
cvs commit: jakarta-turbine-fulcrum/xdocs/stylesheets project.xml
henning 2002/07/01 09:33:38
Modified: . project.xml
xdocs/stylesheets project.xml
Added: src/java/org/apache/fulcrum/crypto BaseCryptoService.java
CryptoAlgorithm.java CryptoService.java
TurbineCrypto.java TurbineCryptoService.java
src/java/org/apache/fulcrum/crypto/provider ClearCrypt.java
JavaCrypt.java UnixCrypt.java
src/test/org/apache/fulcrum/crypto ClearCryptTest.java
DefaultCryptTest.java JavaCryptTest.java
UnixCryptTest.java
xdocs/howto crypto-service.xml
Log:
This is the Crypto Service implementation as proposed for Turbine 2.2
some while ago. I ported it to Fulcrum and we're using it for about six
months without any problems.
Documentation and Tests included.
Revision Changes Path
1.38 +5 -0 jakarta-turbine-fulcrum/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/project.xml,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- project.xml 22 Jun 2002 16:54:04 -0000 1.37
+++ project.xml 1 Jul 2002 16:33:37 -0000 1.38
@@ -111,6 +111,11 @@
<version>1.0-dev</version>
</dependency>
<dependency>
+ <id>cryptix32</id>
+ <version>3.2.0</version>
+ <jar>cryptix32.jar</jar>
+ </dependency>
+ <dependency>
<id>dom4j</id>
<version>1.3</version>
<url>http://www.dom4j.org/</url>
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/BaseCryptoService.java
Index: BaseCryptoService.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.fulcrum.BaseService;
/**
* Base implementation of the Crypto Service. Should be extended
* for the actual service class.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: BaseCryptoService.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*
*/
public abstract class BaseCryptoService
extends BaseService implements CryptoService
{
}
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/CryptoAlgorithm.java
Index: CryptoAlgorithm.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
* This interface describes the various Crypto Algorithms that are
* handed out by the Crypto Service.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: CryptoAlgorithm.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*/
public interface CryptoAlgorithm
{
/**
* Allows the user to set a salt value whenever the
* algorithm is used. Setting a new salt should invalidate
* all internal state of this object.
* <p>
* Algorithms that do not use a salt are allowed to ignore
* this parameter.
* <p>
* Algorithms must be able to deal with the null value as salt.
* They should treat it as "use a random salt".
*
* @param salt The salt value
*
*/
void setSeed(String salt);
/**
* Performs the actual encryption.
*
* @param value The value to be encrypted
*
* @return The encrypted value
*
* @throws Exception various errors from the underlying ciphers.
* The caller should catch them and report accordingly.
*
*/
String encrypt(String value)
throws Exception;
/**
* Algorithms that perform multiple ciphers get told
* with setCipher, which cipher to use. This should be
* called before any other method call.
*
* If called after any call to encrypt or setSeed, the
* CryptoAlgorithm may choose to ignore this or to reset
* and use the new cipher.
*
* If any other call is used before this, the algorithm
* should use a default cipher and not throw an error.
*
* @param cipher The cipher to use.
*
*/
void setCipher(String cipher);
}
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/CryptoService.java
Index: CryptoService.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.security.NoSuchAlgorithmException;
import org.apache.fulcrum.Service;
/**
* The Crypto Service manages the availability of various crypto
* sources. It provides a consistent interface to things like the
* various java.security Message Digest stuff or the Unix Crypt
* algorithm.
*
* It contains no actual crypto code so it should be fine to import/export
* everywhere.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: CryptoService.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*
*/
public interface CryptoService
extends Service
{
/** The name of the service */
public static final String SERVICE_NAME = "CryptoService";
/**
* Returns a CryptoAlgorithm Object which represents the requested
* crypto algorithm.
*
* @param algorithm Name of the requested algorithm
*
* @return An Object representing the algorithm
*
* @throws NoSuchAlgorithmException Requested algorithm is not available
*
*/
CryptoAlgorithm getCryptoAlgorithm(String algorithm)
throws NoSuchAlgorithmException;
}
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/TurbineCrypto.java
Index: TurbineCrypto.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.fulcrum.TurbineServices;
/**
* This is a facade class for the CryptoService.
*
* Here are the static methods that call related methods of the
* various implementations of the Crypto Security Service, according
* to the settings in TurbineResources.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: TurbineCrypto.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*
*/
public abstract class TurbineCrypto
{
/**
* Retrieves an implementation of the CryptoService, based on
* the settings in TurbineResources.
*
* @return an implementation of the CryptoService
*/
public static CryptoService getService()
{
return (CryptoService) TurbineServices.getInstance()
.getService(CryptoService.SERVICE_NAME);
}
}
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/TurbineCryptoService.java
Index: TurbineCryptoService.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.Hashtable;
import java.util.Iterator;
import java.security.NoSuchAlgorithmException;
import org.apache.fulcrum.InitializationException;
import org.apache.fulcrum.factory.FactoryService;
import org.apache.fulcrum.TurbineServices;
import org.apache.commons.configuration.Configuration;
/**
* An implementation of CryptoService that uses either supplied crypto
* Algorithms (provided in Fulcrum.properties) or tries to get them via
* the normal java mechanisms if this fails.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: TurbineCryptoService.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*
*/
public class TurbineCryptoService
extends BaseCryptoService
{
/** Key Prefix for our algorithms */
private static final String ALGORITHM = "algorithm";
/** Default Key */
private static final String DEFAULT_KEY = "default";
/** Default Encryption Class */
private static final String DEFAULT_CLASS =
"org.apache.fulcrum.crypto.provider.JavaCrypt";
/** Names of the registered algorithms and the wanted classes */
private Hashtable algos = null;
/** A factory to construct CryptoAlgorithm objects */
private FactoryService factoryService = null;
/**
* There is not much to initialize here. This runs
* as early init method.
*
* @throws InitializationException Something went wrong in the init
* stage
*/
public void init()
throws InitializationException
{
this.algos = new Hashtable();
/*
* Set up default (Can be overridden by default key
* from the properties
*/
algos.put(DEFAULT_KEY, DEFAULT_CLASS);
/* get the parts of the configuration relevant to us. */
Configuration conf = getConfiguration().subset(ALGORITHM);
if (conf != null)
{
for (Iterator it = conf.getKeys() ;it.hasNext(); )
{
String key = (String) it.next();
String val = conf.getString(key);
// Log.debug("Registered " + val
// + " for Crypto Algorithm " + key);
algos.put(key, val);
}
}
try
{
factoryService = (FactoryService) TurbineServices.getInstance().
getService(FactoryService.SERVICE_NAME);
}
catch (Exception e)
{
throw new InitializationException(
"TurbineCryptoService.init: Failed to get a Factory object", e);
}
setInit(true);
}
/**
* Returns a CryptoAlgorithm Object which represents the requested
* crypto algorithm.
*
* @param algo Name of the requested algorithm
*
* @return An Object representing the algorithm
*
* @throws NoSuchAlgorithmException Requested algorithm is not available
*
*/
public CryptoAlgorithm getCryptoAlgorithm(String algo)
throws NoSuchAlgorithmException
{
String cryptoClass = (String) algos.get(algo);
CryptoAlgorithm ca = null;
if (cryptoClass == null)
{
cryptoClass = (String) algos.get(DEFAULT_KEY);
}
if (cryptoClass == null || cryptoClass.equalsIgnoreCase("none"))
{
throw new NoSuchAlgorithmException(
"TurbineCryptoService: No Algorithm for "
+ algo + " found");
}
try
{
ca = (CryptoAlgorithm) factoryService.getInstance(cryptoClass);
}
catch (Exception e)
{
throw new NoSuchAlgorithmException(
"TurbineCryptoService: Error instantiating "
+ cryptoClass + " for " + algo);
}
ca.setCipher(algo);
return ca;
}
}
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/provider/ClearCrypt.java
Index: ClearCrypt.java
===================================================================
package org.apache.fulcrum.crypto.provider;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.fulcrum.crypto.CryptoAlgorithm;
/**
* This is a dummy for "cleartext" encryption. It goes through
* the notions of the CryptoAlgorithm interface but actually does
* nothing. It can be used as a replacement for the "encrypt = no"
* setting in TurbineResources.
*
* Can be used as the default crypto algorithm
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: ClearCrypt.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*/
public class ClearCrypt
implements CryptoAlgorithm
{
/**
* C'tor
*
*/
public ClearCrypt()
{
}
/**
* This class never uses an algorithm, so this is
* just a dummy.
*
* @param cipher Cipher (ignored)
*/
public void setCipher(String cipher)
{
/* dummy */
}
/**
* This class never uses a seed, so this is
* just a dummy.
*
* @param seed Seed (ignored)
*/
public void setSeed(String seed)
{
/* dummy */
}
/**
* encrypt the supplied string with the requested cipher
*
* @param value The value to be encrypted
*
* @return The encrypted value
*
* @throws Exception An Exception of the underlying implementation.
*
*/
public String encrypt(String value)
throws Exception
{
/*
* Ultra-clever implementation. ;-)
*/
return value;
}
}
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/provider/JavaCrypt.java
Index: JavaCrypt.java
===================================================================
package org.apache.fulcrum.crypto.provider;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import javax.mail.internet.MimeUtility;
import java.security.MessageDigest;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import org.apache.fulcrum.crypto.CryptoAlgorithm;
/**
* Implements the normal java.security.MessageDigest stream cipers
*
* Can be used as the default crypto algorithm
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: JavaCrypt.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*/
public class JavaCrypt
implements CryptoAlgorithm
{
/** The default cipher */
public static final String DEFAULT_CIPHER = "SHA";
/** The cipher to use for encryption */
private String cipher = null;
/**
* C'tor
*
*/
public JavaCrypt()
{
this.cipher = DEFAULT_CIPHER;
}
/**
* Setting the actual cipher requested. If not
* called, then the default cipher (SHA) is used.
*
* This will never throw an error even if there is no
* provider for this cipher. The error will be thrown
* by encrypt() (Fixme?)
*
* @param cipher The cipher to use.
*
*/
public void setCipher(String cipher)
{
this.cipher = cipher;
}
/**
* This class never uses a seed, so this is
* just a dummy.
*
* @param seed Seed (ignored)
*
*/
public void setSeed(String seed)
{
/* dummy */
}
/**
* encrypt the supplied string with the requested cipher
*
* @param value The value to be encrypted
*
* @return The encrypted value
*
* @throws Exception An Exception of the underlying implementation.
*/
public String encrypt(String value)
throws Exception
{
MessageDigest md = MessageDigest.getInstance(cipher);
// We need to use unicode here, to be independent of platform's
// default encoding. Thanks to SGawin for spotting this.
byte[] digest = md.digest(value.getBytes("UTF-8"));
ByteArrayOutputStream bas =
new ByteArrayOutputStream(digest.length + digest.length / 3 + 1);
OutputStream encodedStream = MimeUtility.encode(bas, "base64");
encodedStream.write(digest);
return bas.toString();
}
}
1.1 jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/crypto/provider/UnixCrypt.java
Index: UnixCrypt.java
===================================================================
package org.apache.fulcrum.crypto.provider;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.fulcrum.crypto.CryptoAlgorithm;
/**
* Implements Standard Unix crypt(3) for use with the Crypto Service.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: UnixCrypt.java,v 1.1 2002/07/01 16:33:37 henning Exp $
*/
public class UnixCrypt
implements CryptoAlgorithm
{
/** The seed to use */
private String seed = null;
/** standard Unix crypt chars (64) */
private static final char[] SALT_CHARS =
(("abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./").toCharArray());
/**
* C'tor
*
*/
public UnixCrypt()
{
}
/**
* This class never uses anything but
* UnixCrypt, so it is just a dummy
* (Fixme: Should we throw an exception if
* something is requested that we don't support?
*
* @param cipher Cipher (ignored)
*/
public void setCipher(String cipher)
{
/* dummy */
}
/**
* Setting the seed for the UnixCrypt
* algorithm. If a null value is supplied,
* or no seed is set, then a random seed is used.
*
* @param seed The seed value to use.
*/
public void setSeed(String seed)
{
this.seed = seed;
}
/**
* encrypt the supplied string with the requested cipher
*
* @param value The value to be encrypted
*
* @return The encrypted value
*
* @throws Exception An Exception of the underlying implementation.
*/
public String encrypt(String value)
throws Exception
{
if (seed == null)
{
java.util.Random randomGenerator = new java.util.Random();
int numSaltChars = SALT_CHARS.length;
seed = (new StringBuffer())
.append(SALT_CHARS[Math.abs(randomGenerator.nextInt())
% numSaltChars])
.append(SALT_CHARS[Math.abs(randomGenerator.nextInt())
% numSaltChars])
.toString();
}
/* UnixCrypt seems to be a really widespread name... */
return new cryptix.tools.UnixCrypt(seed).crypt(value);
}
}
1.1 jakarta-turbine-fulcrum/src/test/org/apache/fulcrum/crypto/ClearCryptTest.java
Index: ClearCryptTest.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import org.apache.fulcrum.ServiceManager;
import org.apache.fulcrum.TurbineServices;
import org.apache.fulcrum.factory.FactoryService;
import org.apache.fulcrum.factory.TurbineFactoryService;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
/**
* Testcase for the CryptoService.
*
* Objective: Checks, whether the supplied "clear" crypto
* provider can be selected and offers "clear" (which is
* unencrypted) Encryption.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: ClearCryptTest.java,v 1.1 2002/07/01 16:33:38 henning Exp $
*
*/
public class ClearCryptTest
extends TestCase
{
private static final String PREFIX = "services." +
CryptoService.SERVICE_NAME + '.';
private String input = "Oeltanks";
private String result = "Oeltanks";
public ClearCryptTest( String name )
{
super(name);
}
public void setUp()
{
}
public void tearDown()
{
}
public void testConstruction()
{
}
public void testSelection()
{
try
{
doit();
}
catch( Exception e )
{
fail( e.getMessage() );
}
}
public void doit()
throws Exception
{
ServiceManager serviceManager = TurbineServices.getInstance();
serviceManager.setApplicationRoot(".");
Configuration cfg = new BaseConfiguration();
cfg.setProperty(PREFIX + "classname",
TurbineCryptoService.class.getName());
cfg.setProperty(PREFIX + "algorithm.unix",
"org.apache.fulcrum.crypto.provider.UnixCrypt");
cfg.setProperty(PREFIX + "algorithm.clear",
"org.apache.fulcrum.crypto.provider.ClearCrypt");
/* Ugh */
cfg.setProperty("services." + FactoryService.SERVICE_NAME + ".classname",
TurbineFactoryService.class.getName());
serviceManager.setConfiguration(cfg);
serviceManager.init();
CryptoAlgorithm ca = TurbineCrypto.getService().getCryptoAlgorithm("clear");
String output = ca.encrypt(input);
if(!output.equals(result))
{
fail("Encryption failed, expected "+result+", got "+output);
}
}
}
1.1 jakarta-turbine-fulcrum/src/test/org/apache/fulcrum/crypto/DefaultCryptTest.java
Index: DefaultCryptTest.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import org.apache.fulcrum.ServiceManager;
import org.apache.fulcrum.TurbineServices;
import org.apache.fulcrum.factory.FactoryService;
import org.apache.fulcrum.factory.TurbineFactoryService;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
/**
* Testcase for the CryptoService.
*
* Objective: Checks, whether the supplied "default" crypto
* provider is the JavaCrypt Provider.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: DefaultCryptTest.java,v 1.1 2002/07/01 16:33:38 henning Exp $
*
*/
public class DefaultCryptTest
extends TestCase
{
private static final String PREFIX = "services." +
CryptoService.SERVICE_NAME + '.';
private String input = "Oeltanks";
private String md5result = "XSop0mncK19Ii2r2CUe2";
public DefaultCryptTest( String name )
{
super(name);
}
public void setUp()
{
}
public void tearDown()
{
}
public void testConstruction()
{
}
public void testSelection()
{
try
{
doit();
}
catch( Exception e )
{
fail( e.getMessage() );
}
}
public void doit()
throws Exception
{
ServiceManager serviceManager = TurbineServices.getInstance();
serviceManager.setApplicationRoot(".");
Configuration cfg = new BaseConfiguration();
cfg.setProperty(PREFIX + "classname",
TurbineCryptoService.class.getName());
/* Ugh */
cfg.setProperty("services." + FactoryService.SERVICE_NAME + ".classname",
TurbineFactoryService.class.getName());
serviceManager.setConfiguration(cfg);
serviceManager.init();
CryptoAlgorithm ca = TurbineCrypto.getService().getCryptoAlgorithm("default");
ca.setCipher("MD5");
String output = ca.encrypt(input);
if(!output.equals(md5result))
{
fail("MD5 Encryption failed, expected "+md5result+", got "+output);
}
}
}
1.1 jakarta-turbine-fulcrum/src/test/org/apache/fulcrum/crypto/JavaCryptTest.java
Index: JavaCryptTest.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import org.apache.fulcrum.ServiceManager;
import org.apache.fulcrum.TurbineServices;
import org.apache.fulcrum.factory.FactoryService;
import org.apache.fulcrum.factory.TurbineFactoryService;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
/**
* Testcase for the CryptoService.
*
* Objective: Checks, whether the supplied "java" crypto
* provider can be selected and offers MD5 and SHA1
* algorithms.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: JavaCryptTest.java,v 1.1 2002/07/01 16:33:38 henning Exp $
*
*/
public class JavaCryptTest
extends TestCase
{
private static final String PREFIX = "services." +
CryptoService.SERVICE_NAME + '.';
private String input = "Oeltanks";
private String md5result = "XSop0mncK19Ii2r2CUe2";
private String sha1result = "uVDiJHaavRYX8oWt5ctkaa7j";
public JavaCryptTest( String name )
{
super(name);
}
public void setUp()
{
}
public void tearDown()
{
}
public void testConstruction()
{
}
public void testSelection()
{
try
{
doit();
}
catch( Exception e )
{
fail( e.getMessage() );
}
}
public void doit()
throws Exception
{
ServiceManager serviceManager = TurbineServices.getInstance();
serviceManager.setApplicationRoot(".");
Configuration cfg = new BaseConfiguration();
cfg.setProperty(PREFIX + "classname",
TurbineCryptoService.class.getName());
cfg.setProperty(PREFIX + "algorithm.unix",
"org.apache.fulcrum.crypto.provider.UnixCrypt");
cfg.setProperty(PREFIX + "algorithm.clear",
"org.apache.fulcrum.crypto.provider.ClearCrypt");
cfg.setProperty(PREFIX + "algorithm.java",
"org.apache.fulcrum.crypto.provider.JavaCrypt");
/* Ugh */
cfg.setProperty("services." + FactoryService.SERVICE_NAME + ".classname",
TurbineFactoryService.class.getName());
serviceManager.setConfiguration(cfg);
serviceManager.init();
CryptoAlgorithm ca = TurbineCrypto.getService().getCryptoAlgorithm("java");
ca.setCipher("MD5");
String output = ca.encrypt(input);
if(!output.equals(md5result))
{
fail("MD5 Encryption failed, expected "+sha1result+", got "+output);
}
ca.setCipher("SHA1");
output = ca.encrypt(input);
if(!output.equals(sha1result))
{
fail("SHA1 Encryption failed, expected "+sha1result+", got "+output);
}
}
}
1.1 jakarta-turbine-fulcrum/src/test/org/apache/fulcrum/crypto/UnixCryptTest.java
Index: UnixCryptTest.java
===================================================================
package org.apache.fulcrum.crypto;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import org.apache.fulcrum.ServiceManager;
import org.apache.fulcrum.TurbineServices;
import org.apache.fulcrum.factory.FactoryService;
import org.apache.fulcrum.factory.TurbineFactoryService;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
/**
* Testcase for the CryptoService.
*
* Objective: Checks, whether the supplied "unix" crypto
* provider can be selected and offers the unix encryption
* algorithm.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: UnixCryptTest.java,v 1.1 2002/07/01 16:33:38 henning Exp $
*
*/
public class UnixCryptTest
extends TestCase
{
private static final String PREFIX = "services." +
CryptoService.SERVICE_NAME + '.';
private String input = "Oeltanks";
private String result = "z5EQaXpuu059c";
public UnixCryptTest( String name )
{
super(name);
}
public void setUp()
{
}
public void tearDown()
{
}
public void testConstruction()
{
}
public void testSelection()
{
try
{
doit();
}
catch( Exception e )
{
fail( e.getMessage() );
}
}
public void doit()
throws Exception
{
ServiceManager serviceManager = TurbineServices.getInstance();
serviceManager.setApplicationRoot(".");
Configuration cfg = new BaseConfiguration();
cfg.setProperty(PREFIX + "classname",
TurbineCryptoService.class.getName());
cfg.setProperty(PREFIX + "algorithm.unix",
"org.apache.fulcrum.crypto.provider.UnixCrypt");
cfg.setProperty(PREFIX + "algorithm.clear",
"org.apache.fulcrum.crypto.provider.ClearCrypt");
/* Ugh */
cfg.setProperty("services." + FactoryService.SERVICE_NAME + ".classname",
TurbineFactoryService.class.getName());
serviceManager.setConfiguration(cfg);
serviceManager.init();
CryptoAlgorithm ca = TurbineCrypto.getService().getCryptoAlgorithm("unix");
/*
* Test predefined Seed
*/
ca.setSeed(result);
String output = ca.encrypt(input);
if(!output.equals(result))
{
fail("Encryption failed, expected "+result+", got "+output);
}
/*
* Test random Seed
*
*/
ca.setSeed(null);
result = ca.encrypt(input);
ca.setSeed(result);
output = ca.encrypt(input);
if(!output.equals(result))
{
fail("Encryption failed, expected "+result+", got "+output);
}
}
}
1.1 jakarta-turbine-fulcrum/xdocs/howto/crypto-service.xml
Index: crypto-service.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Fulcrum Services - Crypto Service</title>
<author email="hps@intermeta.de">Henning P. Schmiedehausen</author>
</properties>
<body>
<section name="Crypto Service">
<p>
The Crypto Service allows an application to request various encryption
algorithms provided by the normal Java crypto providers and 3rd party
providers such as <a href="http://www.cryptix.org/">Cryptix</a>.
</p>
</section>
<section name="Configuration">
<source><![CDATA[
# -------------------------------------------------------------------
#
# S E R V I C E S
#
# -------------------------------------------------------------------
# Classes for Turbine Services should be defined here.
# Format: services.[name].classname=[implementing class]
#
# To specify properties of a service use the following syntax:
# service.[name].[property]=[value]
services.CryptoService.classname=org.apache.fulcrum.crypto.TurbineCryptoService
.
.
.
# -------------------------------------------------------------------
#
# C R Y P T O S E R V I C E
#
# -------------------------------------------------------------------
#
# Uncomment the following line if you want to use UnixCrypt and have
# compiled the Fulcrum jar in the presence of the cryptix32.jar.
#
#services.CryptoService.algorithm.unix = org.apache.fulcrum.crypto.provider.UnixCrypt
#
# This is a simple, cleartext "encryption" provider.
#
services.CryptoService.algorithm.cleartext = org.apache.fulcrum.crypto.provider.ClearCrypt
#
# This is the default crypto provider. It implements the normal Java MessageDigest ciphers
# You need not to have this, it is the default if no algorithms are given. The default
# provider gives you all the Java MessageDigest Ciphers
#
services.CryptoService.algorithm.default = org.apache.fulcrum.crypto.provider.JavaCrypt
]]></source>
</section>
<section name="Usage">
<p>
If you want to encrypt a clear text with a MessageDigest Cipher, you can
do it like this:
</p>
<source><![CDATA[
import org.apache.fulcrum.crypto.CryptoAlgorithm;
import org.apache.fulcrum.crypto.TurbineCrypto;
public class CryptoExample
{
public String doMD5Encryption(String input)
{
CryptoAlgorithm ca = TurbineCrypto.getService().getCryptoAlgorithm("default");
ca.setCipher("MD5");
return ca.encrypt(input);
}
}
]]></source>
</section>
<section name="Default Provider">
<p>
In the source code and the example above, there is talk about a
"default" provider which is used if no encryption algorithm is
specifically requested. The reason for this comes from the first user
of the crypto service, the <a href="security-service.html">Security
Service</a>. It gives you the ability to select an encryption
algorithm like MD5 or SHA1 which is in turn used with the normal java
crypto providers. As we just wanted to "add" new algorithms and still
be able to use the old java.security names like MD5 and SHA1, we
decided to add a "catchall" algorithm to the crypto service.
</p>
<p>
If you don't set the default provider explicitly, the
org.apache.fulcrum.crypto.provider.JavaCrypt class is used. If you
don't set the Cipher of this class explicitly, then SHA is used.
</p>
</section>
<section name="Included Providers">
<p>The following algorithm providers are included in the Cryptoservice:</p>
<p>
<ol>
<li>
<b>ClearCrypt</b> (org.apache.fulcrum.crypto.provider.ClearCrypt). This is
the simplest algorithm which does nothing. It is still useful because
you can use the Crypto Service all the time even if you don't want to
actually encrypt something. Just request the "cleartext" algorithm.
</li>
<li>
<b>UnixCrypt</b> (org.apache.fulcrum.crypto.provider.UnixCrypt). This is an
implementation of the Unix crypt(3) algorithm. Its main use is when
you need to access legacy information or databases which already
contain crypted passwords. UnixCrypt needs the cryptix32.jar from <a
href="http://www.cryptix.org/">Cryptix</a>.
</li>
<li>
<b>JavaCrypt</b> (org.apache.fulcrum.crypto.provider.JavaCrypt). This is a
wrapper around the java.security Message Digest functions which give
you MD5, SHA1 and more algorithms.
</li>
</ol>
</p>
</section>
</body>
</document>
1.8 +1 -0 jakarta-turbine-fulcrum/xdocs/stylesheets/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/xdocs/stylesheets/project.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- project.xml 19 Apr 2002 09:23:31 -0000 1.7
+++ project.xml 1 Jul 2002 16:33:38 -0000 1.8
@@ -25,6 +25,7 @@
<menu name="Howtos">
<item name="Cache Service" href="/howto/cache-service.html"/>
+ <item name="Crypto Service" href="/howto/crypto-service.html"/>
<item name="Factory Service" href="/howto/factory-service.html"/>
<item name="Intake Service" href="/howto/intake-service.html"/>
<item name="JSP Service" href="/howto/jsp-service.html"/>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>