Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JniAlternateConfigKmip.java
package com.p6r.kmip;
import org.junit.*;
import sun.security.tools.keytool.CertAndKeyGen;
import sun.security.x509.X500Name;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import java.security.cert.X509Certificate;
public class JniAlternateConfigKmip {
@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_alternateConfigKMIP() {
System.out.println("@Test - JNICall-alternateConfigKMIP");
String uid = null;
TransparentCertificate tc = null;
X509Certificate cert2 = null;
P6KMIPClient kc = new P6KMIPClient();
try {
// -> construct and serialize a certificate to a set of standard ASN.1 bytes
CertAndKeyGen gen = new CertAndKeyGen("RSA", "SHA1WithRSA");
gen.generate(1024);
X509Certificate cert1 = gen.getSelfCertificate(new X500Name("CN=ROOT"), (long) 365 * 24 * 3600);
byte[] certBytes = cert1.getEncoded();
// -> place the cert on the KMIP server
kc.initializeLibrary(P6KMIPClient.FLAGS_NONE);
kc.open("fqdn.com", "p6kmiptool2.conf");
uid = kc.registerCertificate(KMIPConstants.USAGE_MASK_SIGN, certBytes);
System.out.println("Successfully put the cert on alternative config KMIP server: " + uid);
// -> now show that we can get it off of the KMIP server
tc = kc.getCertificate(uid);
assertNotEquals(tc, null);
cert2 = tc.getCert();
System.out.println("Pulled certificate off of alternative config KMIP server: " + cert2.toString());
kc.destroy(uid);
kc.close();
kc.freeLibrary();
} catch (Exception e) {
System.out.println(e.toString());
assertEquals(0, 1);
}
}
}