CryptoManagerTestCase.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 2013-2015 ForgeRock AS
*/
/**
This class tests the CryptoManager.
*/
@SuppressWarnings("javadoc")
public class CryptoManagerTestCase extends CryptoTestCase {
public void setUp()
throws Exception {
}
// 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.
"ldaps://" + "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
private class CipherParameters {
private final String fAlgorithm;
private final int fKeyLength;
}
public String getTransformation() {
if (null != fAlgorithm)
{
: fAlgorithm;
}
return null;
}
public int getKeyLength() {
return fKeyLength;
}
}
/**
Cipher parameter data set.
@return The set of Cipher parameters with which to test.
*/
public Object[][] cipherParametersData() {
return new Object[][] {
// default (preferred) AES/CBC/PKCS5Padding 128bit key.
// custom
// TODO: { new CipherParameters("Blowfish", "CFB", "NoPadding", 448) },
// TODO: { new CipherParameters("AES", "CBC", "PKCS5Padding", 256) },
};
}
/**
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
// 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 SearchRequest request = newSearchRequest(baseDN, SearchScope.SINGLE_LEVEL, searchFilter).addAttribute("dn");
"dn: " + e.getName(),
"changetype: modify",
"replace: " + ATTR_CRYPTO_KEY_COMPROMISED_TIME,
}
//Wait so the above asynchronous modification can be applied. The crypto
//manager's cipherKeyEntryCache needs to be updated before the encrypt()
//method is called below.
// 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 shared secret key wrapping (various wrapping ciphers, if configurable).
*/
/**
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.
*/
}