1 package com.p6r.kmipserverlib;
5 import java.nio.charset.Charset;
7 import static org.junit.Assert.assertEquals;
23 System.out.println(
"@BeforeClass - oneTimeSetUp");
29 System.out.println(
"@AfterClass - oneTimeTearDown");
35 System.out.println(
"@Before - setUp");
41 System.out.println(
"@After - tearDown");
51 System.out.println(
"@Test - JNICall-MsgExtensionKMIP");
55 P6KMIPServerLib sl =
new P6KMIPServerLib();
59 "<RequestMessage><RequestHeader>\n" +
60 " <ProtocolVersion>\n" +
61 " <ProtocolVersionMajor type=\"Integer\" value=\"1\"/>\n" +
62 " <ProtocolVersionMinor type=\"Integer\" value=\"2\"/>\n" +
63 " </ProtocolVersion>\n" +
64 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
65 " </RequestHeader>\n" +
67 " <Operation type=\"Enumeration\" value=\"Create\"/>\n" +
68 " <RequestPayload>\n" +
69 " <ObjectType type=\"Enumeration\" value=\"SymmetricKey\"/>\n" +
70 " <TemplateAttribute>\n" +
72 " <AttributeName type=\"TextString\" value=\"Cryptographic Length\"/>\n" +
73 " <AttributeValue type=\"Integer\" value=\"128\"/>\n" +
76 " <AttributeName type=\"TextString\" value=\"Cryptographic Algorithm\"/>\n" +
77 " <AttributeValue type=\"Enumeration\" value=\"AES\"/>\n" +
80 " <AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/>\n" +
81 " <AttributeValue type=\"Integer\" value=\"Decrypt Encrypt\"/>\n" +
84 " <AttributeName type=\"TextString\" value=\"x-ID\"/>\n" +
85 " <AttributeValue type=\"TextString\" value=\"TC-71-12\"/>\n" +
87 " </TemplateAttribute>\n" +
88 " </RequestPayload>\n" +
89 " <MessageExtension>\n" +
90 " <VendorIdentification type=\"TextString\" value=\"Acme\"/>\n" +
91 " <CriticalityIndicator type=\"Boolean\" value=\"true\"/>\n" +
92 " <VendorExtension>\n" +
93 " <TTLV tag=\"0x540001\" type=\"TextString\" value=\"na\"/>\n" +
94 " </VendorExtension>\n" +
95 " </MessageExtension>\n" +
101 byte[] testMessage2 = {
102 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x01, (byte)0x88, 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x38, 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x6a, 0x02, 0x00, 0x00, 0x00, 0x04,
103 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x6b, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x04,
104 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x01, 0x40, 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
105 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, (byte)0xe8, 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0x91, 0x01, 0x00, 0x00, 0x00, (byte)0xd0,
106 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x14, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4c, 0x65,
107 0x6e, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
108 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x17, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x00,
109 0x42, 0x00, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x18,
110 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73, 0x61, 0x67, 0x65, 0x20, 0x4d, 0x61, 0x73, 0x6b, 0x42, 0x00, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x04,
111 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x04, 0x78, 0x2d, 0x49, 0x44, 0x00, 0x00, 0x00, 0x00,
112 0x42, 0x00, 0x0b, 0x07, 0x00, 0x00, 0x00, 0x08, 0x54, 0x43, 0x2d, 0x37, 0x31, 0x2d, 0x31, 0x32, 0x42, 0x00, 0x51, 0x01, 0x00, 0x00, 0x00, 0x38, 0x42, 0x00, (byte)0x9d, 0x07, 0x00, 0x00, 0x00, 0x04,
113 0x41, 0x63, 0x6d, 0x65, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x26, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0x9c, 0x01, 0x00, 0x00, 0x00, 0x10,
114 0x54, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x02, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
116 byte expectedExtension[] = { 84, 0, 1, 7, 0, 0, 0, 2, 110, 97, 0, 0, 0, 0, 0, 0 };
119 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
121 String libVersion = sl.getLibraryVersion();
122 System.out.println(libVersion);
126 sl.setMessageBuffer(testMessage1.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
129 RequestHeader rh = sl.getRequestHeader();
130 assertEquals(
"1.2", rh.getProtocolVersion());
133 for (
int i = 0; i < rh.getBatchCount(); i++) {
135 BatchItem bi = sl.getBatchItem(i + 1);
136 if (bi instanceof CreateBatchItem) {
137 CreateBatchItem ck = (CreateBatchItem) bi;
140 byte[] batchId = ck.getUniqueBatchId();
141 assertEquals(null, batchId);
145 MessageExtension me = ck.getExtension();
146 assertEquals(
"Acme", me.getVendorIdentification());
147 assertEquals(
true, me.getCriticalityIndicator());
149 String[] attributes = ck.getAttributes();
150 assertEquals(
"Cryptographic Length: 128", attributes[0]);
151 assertEquals(
"Cryptographic Algorithm: 3", attributes[1]);
152 assertEquals(
"Cryptographic Usage Mask: c", attributes[2]);
153 assertEquals(
"x-ID: TC-71-12", attributes[3]);
159 sl.setMessageBuffer(testMessage2, KMIPConstants.FORMAT_TTLV );
162 rh = sl.getRequestHeader();
163 assertEquals(
"1.2", rh.getProtocolVersion());
166 for (
int i = 0; i < rh.getBatchCount(); i++) {
168 BatchItem bi = sl.getBatchItem(i + 1);
169 if (bi instanceof CreateBatchItem) {
170 CreateBatchItem ck = (CreateBatchItem) bi;
173 byte[] batchId = ck.getUniqueBatchId();
174 assertEquals(null, batchId);
177 MessageExtension me = ck.getExtension();
178 assertEquals(
"Acme", me.getVendorIdentification());
179 assertEquals(
false, me.getCriticalityIndicator());
180 byte[] vendorExtension = me.getVendorExtension();
181 assertEquals(16, vendorExtension.length);
182 for(
int q=0; q < 16; q++ ) {
183 assertEquals(expectedExtension[q], vendorExtension[q]);
186 String[] attributes = ck.getAttributes();
187 assertEquals(
"Cryptographic Length: 128", attributes[0]);
188 assertEquals(
"Cryptographic Algorithm: 3", attributes[1]);
189 assertEquals(
"Cryptographic Usage Mask: c", attributes[2]);
190 assertEquals(
"x-ID: TC-71-12", attributes[3]);
196 }
catch (Exception e) {
198 System.out.println(e.toString());
void JNICall_MsgExtenisonKMIP()
Test: Verify parser can handle an XML formated Create Key Pair operation.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeSetUp()
static void oneTimeTearDown()