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-WrappedRegisterKMIP");
53 P6KMIPServerLib sl =
new P6KMIPServerLib();
56 byte[] testMessage = {
57 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x02, 0x50, 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x48, 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, (byte)0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
59 0x00, 0x00, 0x00, 0x00, 0x59, (byte)0xee, 0x0d, (byte)0xe8, 0x42, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x01, (byte)0xf8,
60 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, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x01, (byte)0xd0, 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0x91, 0x01, 0x00, 0x00, 0x00, 0x38,
62 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x04, 0x78, 0x2d, 0x49, 0x44, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0b, 0x07, 0x00, 0x00, 0x00, 0x11,
63 0x50, 0x36, 0x52, 0x2d, 0x4d, 0x45, 0x4d, 0x4f, 0x52, 0x59, 0x2d, 0x54, 0x45, 0x53, 0x54, 0x2d, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0x8f, 0x01, 0x00, 0x00, 0x01, 0x78,
64 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x01, 0x70, 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x30,
65 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
66 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
67 0x42, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x46, 0x01, 0x00, 0x00, 0x01, 0x00, 0x42, 0x00, (byte)0x9e, 0x05, 0x00, 0x00, 0x00, 0x04,
68 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x78, 0x42, 0x00, (byte)0x94, 0x07, 0x00, 0x00, 0x00, 0x11, 0x31, 0x31, 0x31, 0x2d, 0x32, 0x32, 0x32, 0x2d,
69 0x64, 0x68, 0x64, 0x68, 0x64, 0x2d, 0x64, 0x64, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x50, 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
70 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x5f, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0x83, 0x05, 0x00, 0x00, 0x00, 0x04,
71 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0xc5, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0xcd, 0x02, 0x00, 0x00, 0x00, 0x04,
72 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x4e, 0x01, 0x00, 0x00, 0x00, 0x38, 0x42, 0x00, (byte)0x94, 0x07, 0x00, 0x00, 0x00, 0x07, 0x34, 0x35, 0x2d, 0x33, 0x33, 0x34, 0x34, 0x00,
73 0x42, 0x00, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x38, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0xae, 0x05, 0x00, 0x00, 0x00, 0x04,
74 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x4d, 0x08, 0x00, 0x00, 0x00, 0x08, (byte)0xab, (byte)0xbc, 0x34, (byte)0xff, (byte)0xf3, (byte)0xd3, 0x5a, 0x0c, 0x42, 0x00, 0x3d, 0x08, 0x00, 0x00, 0x00, 0x04,
75 0x11, 0x22, 0x33, 0x44, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte)0xa3, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
79 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
81 String libVersion = sl.getLibraryVersion();
82 System.out.println(libVersion);
86 sl.setMessageBuffer(testMessage, KMIPConstants.FORMAT_TTLV);
89 RequestHeader rh = sl.getRequestHeader();
90 assertEquals(
"1.3", rh.getProtocolVersion());
93 for (
int i = 0; i < rh.getBatchCount(); i++) {
95 BatchItem bi = sl.getBatchItem(i + 1);
96 if (bi instanceof RegisterWrappedKeyBatchItem) {
97 RegisterWrappedKeyBatchItem rb = (RegisterWrappedKeyBatchItem) bi;
98 assertEquals(1, rb.getUniqueBatchId()[0]);
99 assertEquals(KMIPConstants.OBJECT_SYMMETRICKEY, rb.getObjectType());
100 assertEquals(KMIPConstants.ALG_AES, rb.getAlgorithm());
101 assertEquals(KMIPConstants.KEYFORMAT_TRANSYMKEY, rb.getKeyFromatType());
102 assertEquals(256, rb.getKeyLength());
104 byte[] keyBytes = rb.getWrappedBytes();
105 assertEquals(40, keyBytes.length);
106 for (
int j = 0; j < keyBytes.length; j++) {
108 assertEquals((byte) j, keyBytes[j]);
109 else assertEquals((byte)j+1, keyBytes[j]);
117 String[] templateAttributes = rb.getTemplateAttributes();
118 assertEquals(1, templateAttributes.length);
119 assertEquals(
"x-ID: P6R-MEMORY-TEST-7", templateAttributes[0]);
121 String[] templateNames = rb.getTemplateNames();
122 if (null != templateNames) assertEquals(0,1);
127 }
catch (Exception e) {
129 System.out.println(e.toString());
static void oneTimeTearDown()
static void oneTimeSetUp()
void JNICall_WrappedRegisterKMIP()
Test: Verify parser can break message into multiple batch items.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.