1 package com.p6r.kmipserverlib;
5 import static org.junit.Assert.assertEquals;
6 import static org.junit.Assert.assertNotEquals;
23 System.out.println(
"@BeforeClass - oneTimeSetUp");
29 System.out.println(
"@AfterClass - oneTimeTearDown");
35 System.out.println(
"@Before - setUp");
41 System.out.println(
"@After - tearDown");
53 System.out.println(
"@Test - JNICall-BasicKMIP");
57 P6KMIPServerLib sl =
new P6KMIPServerLib();
60 byte[] testMessage = {
61 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x03, (byte) 0x98, 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, (byte) 0x88, 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x6a, 0x02, 0x00, 0x00, 0x00, 0x04,
62 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x6b, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x50, 0x02, 0x00, 0x00, 0x00, 0x04,
63 0x00, 0x00, 0x01, (byte) 0xf4, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x07, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x42, 0x00, 0x0e, 0x05, 0x00, 0x00, 0x00, 0x04,
64 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x10, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x42, 0x00, (byte) 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
65 0x00, 0x00, 0x00, 0x00, 0x59, (byte) 0xdc, 0x27, 0x66, 0x42, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x00, (byte) 0xe8,
66 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0x93, 0x08, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, (byte) 0xc0, 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) 0xa8,
68 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x17, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6c,
69 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x00, 0x42, 0x00, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
70 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x14, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
71 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, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x18,
72 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,
73 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x01, 0x20, 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
74 0x42, 0x00, (byte) 0x93, 0x08, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, (byte) 0xf8, 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
75 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0x91, 0x01, 0x00, 0x00, 0x00, (byte) 0xe0, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x17,
76 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x00, 0x42, 0x00, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x04,
77 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x14, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72,
78 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x18, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
80 0x61, 0x67, 0x65, 0x20, 0x4d, 0x61, 0x73, 0x6b, 0x42, 0x00, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
81 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x0b, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0b, 0x07, 0x00, 0x00, 0x00, 0x0b,
82 0x31, 0x20, 0x32, 0x20, 0x33, 0x20, 0x34, 0x20, 0x35, 0x20, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x00, (byte) 0xb8, 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04,
83 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0x93, 0x08, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, (byte) 0x90,
84 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
85 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
86 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00,
87 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
88 0x42, 0x00, 0x74, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x28, 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04,
89 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0x93, 0x08, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x00};
92 byte[] testMessageBroken = {
93 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x00, (byte)0xc0, 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x78,
94 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x6a, 0x02, 0x00, 0x00, 0x00, 0x04,
95 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x6b, 0x02, 0x00, 0x00, 0x00, 0x04,
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x38,
97 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
98 (byte)0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x25, 0x08, 0x00, 0x00, 0x00, 0x18,
99 0x54, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x10, 0x54, 0x00, 0x04, 0x07, 0x00, 0x00, 0x00, 0x03,
100 0x44, 0x42, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x04,
101 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x38,
102 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00,
103 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, (byte)0x94, 0x07, 0x00, 0x00, 0x00, 0x18,
104 0x41, 0x57, 0x4d, 0x6b, 0x73, 0x65, 0x70, 0x69, 0x4a, 0x54, 0x62, 0x5a, 0x49, 0x73, 0x6f, 0x5f,
105 0x30, 0x58, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00
109 sl.initializeLibrary(P6KMIPServerLib.FLAGS_ALLLOG);
111 String libVersion = sl.getLibraryVersion();
112 System.out.println(libVersion);
116 sl.setMessageBuffer(testMessage, KMIPConstants.FORMAT_TTLV);
119 RequestHeader rh = sl.getRequestHeader();
120 assertEquals(
true, rh.getAsynchIndicator());
121 assertEquals(500, rh.getMaxResponseSize());
122 assertEquals(
"1.3", rh.getProtocolVersion());
123 assertEquals(KMIPConstants.BATCHOPTION_UNDO, rh.getBatchErrorOption());
124 assertEquals(
true, rh.getBatchOrderOption());
125 assertEquals(4, rh.getBatchCount());
126 String msgDate = rh.getTimeStamp().toString();
127 assertEquals(
"Mon Oct 09 18:50:30 PDT 2017", msgDate );
130 for (
int i = 0; i < rh.getBatchCount(); i++) {
132 BatchItem bi = sl.getBatchItem(i + 1);
133 if (bi instanceof CreateBatchItem) {
134 CreateBatchItem cb = (CreateBatchItem) bi;
135 assertEquals(KMIPConstants.OBJECT_SYMMETRICKEY, cb.getObjectType());
136 assertEquals(i + 1, cb.getUniqueBatchId()[0]);
138 String[] attributes = cb.getAttributes();
139 if (3 == attributes.length) {
140 assertEquals(
"Cryptographic Algorithm: 3", attributes[0]);
141 assertEquals(
"Cryptographic Length: 128", attributes[1]);
142 assertEquals(
"Cryptographic Usage Mask: c", attributes[2]);
144 }
else if (4 == attributes.length) {
145 assertEquals(
"Cryptographic Algorithm: 26", attributes[0]);
146 assertEquals(
"Cryptographic Length: 256", attributes[1]);
147 assertEquals(
"Cryptographic Usage Mask: 3", attributes[2]);
148 assertEquals(
"Description: 1 2 3 4 5 6", attributes[3]);
151 assertEquals(0, attributes.length);
154 }
else if (bi instanceof QueryBatchItem) {
155 QueryBatchItem qb = (QueryBatchItem) bi;
156 assertEquals(3, qb.getUniqueBatchId()[0]);
158 int[] queryFunctions = qb.getQueryFunctions();
159 assertEquals(9, queryFunctions.length);
160 assertEquals(KMIPConstants.QUERY_OPERATIIONS, queryFunctions[0]);
161 assertEquals(KMIPConstants.QUERY_OBJECTS, queryFunctions[1]);
162 assertEquals(KMIPConstants.QUERY_SERVERINFORMATION, queryFunctions[2]);
163 assertEquals(KMIPConstants.QUERY_ATTENSTATIONTYPES, queryFunctions[3]);
164 assertEquals(KMIPConstants.QUERY_CAPABILITIES, queryFunctions[4]);
165 assertEquals(KMIPConstants.QUERY_PROFILES, queryFunctions[5]);
166 assertEquals(KMIPConstants.QUERY_VALIDATIONS, queryFunctions[6]);
167 assertEquals(KMIPConstants.QUERY_EXTENSIONLIST, queryFunctions[7]);
168 assertEquals(KMIPConstants.QUERY_REGMETHODS, queryFunctions[8]);
170 }
else if (bi instanceof VersionBatchItem) {
172 VersionBatchItem vb = (VersionBatchItem) bi;
173 assertEquals(4, vb.getUniqueBatchId()[0]);
174 ProtocolVersion[] versions = vb.getProtocolVersions();
175 if (null != versions) assertEquals(0,1);
180 }
catch (Exception e) {
182 System.out.println(e.toString());
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeTearDown()
void JNICall_BasicKMIP()
Test: Verify parser can break message into multiple batch items.
static void oneTimeSetUp()