Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JniRekeyKmip.java
package com.p6r.kmip;
import org.junit.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class JniRekeyKmip {
private static final String _hostName = "kmiptest01.p6r.com";
@BeforeClass
public static void oneTimeSetUp() {
// NOOP
System.out.println("@BeforeClass - oneTimeSetUp");
}
@AfterClass
public static void oneTimeTearDown() {
// NOOP
System.out.println("@AfterClass - oneTimeTearDown");
}
@Before
public void setUp() {
// NOOP
System.out.println("@Before - setUp");
}
@After
public void tearDown() {
// NOOP
System.out.println("@After - tearDown");
}
@Test
public void JNICall_rekeyKMIP() {
System.out.println("@Test - JNICall-reKeyKMIP");
String uid1 = null;
String uid2 = null;
String[] attribute = null;
KeyPairIds pi1 = null;
KeyPairIds pi2 = null;
P6KMIPClient kc = new P6KMIPClient();
try {
kc.initializeLibrary(P6KMIPClient.FLAGS_NONE);
kc.open(_hostName, null);
// -> create a symmetric key and then rekey it
uid1 = kc.createSymmetricKey(KMIPConstants.ALG_AES, 128, (KMIPConstants.USAGE_MASK_ENCRYPT | KMIPConstants.USAGE_MASK_DECRYPT));
System.out.println("UID of new AES key: " + uid1);
uid2 = kc.reKey(uid1);
System.out.println("UID of AES rekey: " + uid2);
// -> create a key pair and then rekey it
pi1 = kc.createKeyPair(KMIPConstants.ALG_RSA, 1024, KMIPConstants.USAGE_MASK_VERIFY, KMIPConstants.USAGE_MASK_SIGN);
System.out.println("\nUID of new RSA public key: " + pi1.getPublicKeyUID());
System.out.println("UID of new RSA private key: " + pi1.getPrivateKeyUID());
pi2 = kc.reKeyKeyPair(pi1.getPrivateKeyUID());
System.out.println("\nUID of RSA public rekey: " + pi2.getPublicKeyUID());
System.out.println("UID of RSA private rekey: " + pi2.getPrivateKeyUID());
// -> what happens when attribute is not present on the object?
attribute = kc.getAttribute(pi2.getPrivateKeyUID(), "Name");
assertEquals(0, attribute.length);
// -> what happens when we mis-spell the attribute name (missing the 't')
attribute = kc.getAttribute(pi2.getPrivateKeyUID(), "Crypographic Algorithm");
assertEquals(0, attribute.length);
kc.destroy(uid1);
kc.destroy(uid2);
kc.destroy(pi1.getPublicKeyUID());
kc.destroy(pi1.getPrivateKeyUID());
kc.destroy(pi2.getPublicKeyUID());
kc.destroy(pi2.getPrivateKeyUID());
kc.close();
kc.freeLibrary();
} catch (Exception e) {
// -> we shoud not get here
System.out.println(e.toString());
assertEquals(0, 1);
}
}
}