1 package com.p6r.kmipserverlib;
5 import static org.junit.Assert.assertEquals;
21 System.out.println(
"@BeforeClass - oneTimeSetUp");
27 System.out.println(
"@AfterClass - oneTimeTearDown");
33 System.out.println(
"@Before - setUp");
39 System.out.println(
"@After - tearDown");
49 System.out.println(
"@Test - JNICall-RegisterKMIP");
53 P6KMIPServerLib sl =
new P6KMIPServerLib();
56 byte[] testMessage = {
57 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x02, (byte) 0x98, 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x01, 0x30, 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x6a, 0x02, 0x00, 0x00, 0x00, 0x04,
58 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, 0x0c, 0x01, 0x00, 0x00, 0x00, (byte) 0xe0,
59 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x40, 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x28,
60 0x42, 0x00, (byte) 0x99, 0x07, 0x00, 0x00, 0x00, 0x04, 0x46, 0x72, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0xa1, 0x07, 0x00, 0x00, 0x00, 0x09, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64,
61 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, (byte) 0x90, 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
62 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x78, 0x42, 0x00, (byte) 0xb0, 0x07, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x00, 0x00, 0x00, 0x00,
63 0x42, 0x00, (byte) 0xa2, 0x07, 0x00, 0x00, 0x00, 0x09, 0x64, 0x65, 0x76, 0x49, 0x44, 0x32, 0x32, 0x33, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0xab, 0x07, 0x00, 0x00, 0x00, 0x09,
64 0x6e, 0x65, 0x74, 0x49, 0x44, 0x39, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0xa9, 0x07, 0x00, 0x00, 0x00, 0x0a, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49,
65 0x44, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0xaa, 0x07, 0x00, 0x00, 0x00, 0x0a, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x49, 0x44, 0x33, 0x31, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 0x42, 0x00, (byte) 0x92, 0x09, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x59, (byte) 0xe9, 0x77, (byte) 0xa7, 0x42, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
67 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x01, 0x58, 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0x93, 0x08, 0x00, 0x00, 0x00, 0x01,
68 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x01, 0x30, 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
69 0x42, 0x00, (byte) 0x91, 0x01, 0x00, 0x00, 0x00, 0x38, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x04, 0x78, 0x2d, 0x49, 0x44, 0x00, 0x00, 0x00, 0x00,
70 0x42, 0x00, 0x0b, 0x07, 0x00, 0x00, 0x00, 0x11, 0x50, 0x36, 0x52, 0x2d, 0x4d, 0x45, 0x4d, 0x4f, 0x52, 0x59, 0x2d, 0x54, 0x45, 0x53, 0x54, 0x2d, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71 0x42, 0x00, (byte) 0x8f, 0x01, 0x00, 0x00, 0x00, (byte) 0xd8, 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, (byte) 0xd0, 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
72 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, (byte) 0x98, 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0f, 0x10,
73 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x18,
74 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,
75 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x0b, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
76 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0b, 0x07, 0x00, 0x00, 0x00, 0x0b, 0x31, 0x20, 0x32, 0x20, 0x33, 0x20, 0x34, 0x20, 0x35, 0x20, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
81 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
83 String libVersion = sl.getLibraryVersion();
84 System.out.println(libVersion);
88 sl.setMessageBuffer(testMessage, KMIPConstants.FORMAT_TTLV);
91 RequestHeader rh = sl.getRequestHeader();
92 assertEquals(
"1.3", rh.getProtocolVersion());
96 Credential credOne = sl.getCredential(1);
97 if (credOne instanceof PasswordCredential) {
98 PasswordCredential pc = (PasswordCredential) credOne;
99 assertEquals(
"Fred", pc.getUserName());
100 assertEquals(
"password1", pc.getPassword());
101 }
else assertEquals(0, 1);
103 Credential credTwo = sl.getCredential(2);
104 if (credTwo instanceof DeviceCredential) {
105 DeviceCredential dc = (DeviceCredential) credTwo;
106 assertEquals(
"serNum123456", dc.getSerialNumber());
107 assertEquals(null, dc.getPassword());
108 assertEquals(
"devID2233", dc.getDeviceIdentifier());
109 assertEquals(
"netID9000", dc.getNetworkIdentifer());
110 assertEquals(
"machineID1", dc.getMachineIdentifer());
111 assertEquals(
"mediaID313", dc.getMediaIdentifer());
112 }
else assertEquals(1, 2);
114 Credential credThree = sl.getCredential(3);
115 assertEquals(null, credThree);
119 for (
int i = 0; i < rh.getBatchCount(); i++) {
121 BatchItem bi = sl.getBatchItem(i + 1);
122 if (bi instanceof RegisterTransparentSymmetricKeyBatchItem) {
123 RegisterTransparentSymmetricKeyBatchItem rb = (RegisterTransparentSymmetricKeyBatchItem) bi;
124 assertEquals(1, rb.getUniqueBatchId()[0]);
125 assertEquals(KMIPConstants.ALG_AES, rb.getAlgorithm());
126 byte[] keyBytes = rb.getKeyMaterial();
127 assertEquals(32, keyBytes.length);
128 for (
int j = 0; j < keyBytes.length; j++) {
130 assertEquals((byte) j, keyBytes[j]);
131 else assertEquals((byte)j+1, keyBytes[j]);
134 String[] templateAttributes = rb.getTemplateAttributes();
135 assertEquals(1, templateAttributes.length);
136 assertEquals(
"x-ID: P6R-MEMORY-TEST-7", templateAttributes[0]);
138 String[] templateNames = rb.getTemplateNames();
139 if (null != templateNames) assertEquals(0,1);
141 String[] keyAttributes = rb.getKeyValueAttributes();
142 assertEquals(2, keyAttributes.length);
143 assertEquals(
"Cryptographic Usage Mask: c", keyAttributes[0]);
144 assertEquals(
"Description: 1 2 3 4 5 6", keyAttributes[1]);
149 }
catch (Exception e) {
151 System.out.println(e.toString());
void JNICall_RegisterKMIP()
Test: Verify parser can break message into multiple batch items.
static void oneTimeSetUp()
static void oneTimeTearDown()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.