CryptoManagerTestCase.java revision 2720
/*
* 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
* 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
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. 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
*
*
* Portions Copyright 2007 Sun Microsystems, Inc.
*/
/**
This class tests the CryptoManager.
*/
public class CryptoManagerTestCase extends CryptoTestCase {
/**
Setup..
@throws Exception If an unexpected problem occurs.
*/
@BeforeClass()
public void setUp()
throws Exception {
}
/**
Cleanup.
@throws Exception If an exceptional condition arises.
*/
@AfterClass()
// Removes at least secret keys added in this test case.
}
@Test
public void testGetInstanceKeyCertificate()
throws Exception {
final byte[] cert
// The certificate should now be accessible in the truststore backend via LDAP.
"ldap://" + "127.0.0.1" + ":"
"cn=Directory Manager", "password",
// TODO: should the below dn be in ConfigConstants?
/* attribute ds-cfg-public-key-certificate is a MUST in the schema */
// Compare the certificate values.
// Compare the MD5 hash of the LDAP attribute with the one
// retrieved from the CryptoManager.
// Call twice to ensure idempotent.
}
@Test
public void testMacSuccess()
throws Exception {
}
// TODO: other-than-default MAC
/**
Cipher parameters
*/
private class CipherParameters {
private final String fAlgorithm;
private final int fKeyLength;
private final int fIVLength;
final int ivLength) {
}
public String getTransformation() {
}
public int getKeyLength() {
return fKeyLength;
}
public int getIVLength() {
return fIVLength;
}
}
/**
Cipher parameter data set.
@return The set of Cipher parameters with which to test.
*/
public Object[][] cipherParametersData() {
// default (preferred) AES/CBC/PKCS5Padding 128bit key.
// custom
// TODO: paramList.add(new CipherParameters("Blowfish", "CFB", "NoPadding", 448, 64));
{
}
return cipherParameters;
}
/**
Tests a simple encryption-decryption cycle using the supplied cipher
parameters.
@param cp Cipher parameters to use for this test iteration.
@throws Exception If an exceptional condition arises.
*/
throws Exception {
}
/**
Tests a simple cipher stream encryption-decryption cycle using the supplied
cipher parameters.
@param cp Cipher parameters to use for this test iteration.
@throws Exception If an exceptional condition arises.
*/
throws Exception {
// TODO: check tempfile for plaintext.
}
/**
Tests to ensure the same key identifier (and hence, key) is used for
successive encryptions specifying the same algorithm and key length.
<p>
The default encryption cipher requires an initialization vector. Confirm
successive uses of a key produces distinct ciphertext.
@throws Exception In case an error occurs in the encryption routine.
*/
@Test
public void testKeyEntryReuse()
throws Exception {
// test cycle
// test for identical keys
try {
}
catch (NoSuchMethodException ex) {
// skip this test - requires at least Java 6
}
// test for distinct ciphertext
}
/**
Test that secret keys are persisted: Encrypt some data using a
variety of transformations, restart the instance, and decrypt the
retained ciphertext.
@throws Exception In case an error occurs in the encryption routine.
*/
@Test()
public void testKeyPersistence()
throws Exception {
}
/**
Mark a key compromised; ensure 1) subsequent encryption requests use a
new key; 2) ciphertext produced using the compromised key can still be
decrypted; 3) once the compromised key entry is removed, confirm ciphertext
produced using the compromised key can no longer be decrypted.
@throws Exception In case something exceptional happens.
*/
@Test()
public void testCompromisedKey() throws Exception {
final int cipherKeyLength = 128;
// Initial encryption ensures a cipher key entry is in ADS.
// Retrieve all uncompromised cipher key entries corresponding to the
// specified transformation and key length. Mark each entry compromised.
final String FILTER_OC_INSTANCE_KEY
= new StringBuilder("(objectclass=")
= new LinkedHashSet<String>();
final InternalClientConnection icc
/* size limit */ 0, /* time limit */ 0,
/* types only */ false,
"changetype: modify",
+ compromisedTime);
}
// Use the transformation and key length again. A new cipher key
// should be produced.
// 1. Test for distinct keys.
final byte[] keyID = new byte[16];
final byte[] keyID2 = new byte[16];
// 2. Confirm ciphertext produced using the compromised key can still be
// decrypted.
// 3. Delete the compromised entry(ies) and ensure ciphertext produced
// using a compromised key can no longer be decrypted.
}
try {
}
catch (CryptoManagerException ex) {
// TODO: if reasons are added to CryptoManagerException, check for
// expected cause.
}
}
/**
TODO: Test key wrapping
Trying OAEPWITHSHA-512ANDMGF1PADDING throws an exception "Key too small...".
*/
/**
TODO: Test the secret key synchronization protocol.
1. Create the first instance; add reversible password storage scheme
to password policy; add entry using explicit password policy; confirm
secret key entry has been produced.
2. Create and initialize the second instance into the existing ADS domain.
The secret key entries should be propagated to the second instance via
replication. Then the new instance should detect that the secret key
entries are missing ds-cfg-symmetric-key attribute values for that
instance, inducing the key synchronization protocol.
3. Confirm the second instance can decrypt the password of the entry
added in step 1; e.g., bind as that user.
4. Stop the second instance. At the first instance, enable a different
reversible password storage scheme (different cipher transformation,
and hence secret key entry); add another entry using that password
storage scheme; start the second instance; ensure the password can
be decrypted at the second instance.
*/
}