Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JniCertificatesKmip.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 JniCertificatesKmip {
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_certificatesKMIP() {
System.out.println("@Test - JNICall-certificateKMIP");
String uid = null;
String[] attribute = 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(_hostName, null);
uid = kc.registerCertificate(KMIPConstants.USAGE_MASK_SIGN, certBytes);
System.out.println("Successfully put the cert on the 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 KMIP server: " + cert2.toString());
System.out.println("\nShow ALL attributes associated with the certificate");
attribute = kc.getAllAttributes(uid);
assertNotEquals(attribute, null);
for( int i=0; i < attribute.length; i++ ) {
System.out.println( "attribute " + i + "> " + attribute[i]);
}
kc.destroy(uid);
kc.close();
kc.freeLibrary();
} catch (Exception e) {
System.out.println(e.toString());
assertEquals(0, 1);
}
}
}