1 package com.p6r.kmipserverlib;
5 import java.nio.charset.Charset;
6 import static org.junit.Assert.assertEquals;
22 System.out.println(
"@BeforeClass - oneTimeSetUp");
28 System.out.println(
"@AfterClass - oneTimeTearDown");
34 System.out.println(
"@Before - setUp");
40 System.out.println(
"@After - tearDown");
50 System.out.println(
"@Test - JNICall-CreateKeyPairKMIP");
54 P6KMIPServerLib sl =
new P6KMIPServerLib();
58 "<RequestMessage><RequestHeader>" +
59 "<ProtocolVersion> " +
60 "<ProtocolVersionMajor type=\"Integer\" value=\"1\"/> " +
61 "<ProtocolVersionMinor type=\"Integer\" value=\"3\"/> " +
62 "</ProtocolVersion> " +
63 "<BatchCount type=\"Integer\" value=\"1\"/> " +
66 "<Operation type=\"Enumeration\" value=\"CreateKeyPair\"/> " +
68 "<CommonTemplateAttribute> " +
70 "<AttributeName type=\"TextString\" value=\"Cryptographic Algorithm\"/> " +
71 "<AttributeValue type=\"Enumeration\" value=\"RSA\"/> " +
74 "<AttributeName type=\"TextString\" value=\"Cryptographic Length\"/> " +
75 "<AttributeValue type=\"Integer\" value=\"1024\"/> " +
77 "</CommonTemplateAttribute> " +
78 "<PrivateKeyTemplateAttribute> " +
80 "<AttributeName type=\"TextString\" value=\"Name\"/> " +
82 "<NameValue type=\"TextString\" value=\"TC-81-13-privatekey1\"/> " +
83 "<NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/> " +
84 "</AttributeValue> " +
87 "<AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/> " +
88 "<AttributeValue type=\"Integer\" value=\"0x00000001\"/> " +
90 "</PrivateKeyTemplateAttribute> " +
91 "<PublicKeyTemplateAttribute> " +
93 "<AttributeName type=\"TextString\" value=\"Name\"/> " +
95 "<NameValue type=\"TextString\" value=\"TC-81-13-publickey1\"/> " +
96 "<NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/> " +
97 "</AttributeValue> " +
100 "<AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/> " +
101 "<AttributeValue type=\"Integer\" value=\"0x00000002\"/> " +
103 "</PublicKeyTemplateAttribute> " +
104 "</RequestPayload> " +
105 "</BatchItem></RequestMessage>";
108 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
110 String libVersion = sl.getLibraryVersion();
111 System.out.println(libVersion);
115 sl.setMessageBuffer(testMessage.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
118 RequestHeader rh = sl.getRequestHeader();
119 assertEquals(
"1.3", rh.getProtocolVersion());
122 for (
int i = 0; i < rh.getBatchCount(); i++) {
124 BatchItem bi = sl.getBatchItem(i + 1);
125 if (bi instanceof CreateKeyPairBatchItem) {
126 CreateKeyPairBatchItem ck = (CreateKeyPairBatchItem) bi;
129 byte[] batchId = ck.getUniqueBatchId();
130 assertEquals(null, batchId);
133 String[] commonAttribs = ck.getCommonAttributes();
134 assertEquals(2, commonAttribs.length);
135 assertEquals(
"Cryptographic Algorithm: 4", commonAttribs[0]);
136 assertEquals(
"Cryptographic Length: 1024", commonAttribs[1]);
138 String[] commonNames = ck.getCommonNames();
139 assertEquals(null, commonNames);
141 String[] privateAttribs = ck.getPrivateAttributes();
142 assertEquals(2, privateAttribs.length);
143 assertEquals(
"Name: TC-81-13-privatekey1 - text_string", privateAttribs[0]);
144 assertEquals(
"Cryptographic Usage Mask: 1", privateAttribs[1]);
146 String[] publicAttribs = ck.getPublicAttributes();
147 assertEquals(2, publicAttribs.length);
148 assertEquals(
"Name: TC-81-13-publickey1 - text_string", publicAttribs[0]);
149 assertEquals(
"Cryptographic Usage Mask: 2", publicAttribs[1]);
154 }
catch (Exception e) {
156 System.out.println(e.toString());
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeSetUp()
void JNICall_CreateKeyPairKMIP()
Test: Verify parser can handle an XML formated Create Key Pair operation.
static void oneTimeTearDown()