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");
51 System.out.println(
"@Test - JNICall-GetKMIP");
55 P6KMIPServerLib sl =
new P6KMIPServerLib();
58 byte[] testMessage = {
59 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x01, 0x48, 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x68,
60 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x6a, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x6b, 0x02, 0x00, 0x00, 0x00, 0x04,
61 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0e, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x10, 0x06, 0x00, 0x00, 0x00, 0x08,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x42, 0x00, (byte)0x92, 0x09, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x59, (byte)0xe0, (byte)0xf1, (byte)0xa1, 0x42, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x04,
63 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x00, (byte)0xd0, 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00,
64 0x42, 0x00, (byte)0x93, 0x08, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, (byte)0xa8, 0x42, 0x00, (byte)0x94, 0x07, 0x00, 0x00, 0x00, 0x0f,
65 0x31, 0x31, 0x31, 0x2d, 0x32, 0x32, 0x32, 0x2d, 0x33, 0x33, 0x33, 0x2d, 0x34, 0x34, 0x34, 0x00, 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
66 0x42, 0x00, 0x47, 0x01, 0x00, 0x00, 0x00, 0x78, 0x42, 0x00, (byte)0x9e, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x50,
67 0x42, 0x00, (byte)0x94, 0x07, 0x00, 0x00, 0x00, 0x0c, 0x4b, 0x45, 0x4b, 0x2d, 0x33, 0x34, 0x35, 0x2d, 0x34, 0x34, 0x35, 0x36, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x30,
68 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x5f, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
69 0x42, 0x00, (byte)0xd1, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00 };
72 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
74 String libVersion = sl.getLibraryVersion();
75 System.out.println(libVersion);
79 sl.setMessageBuffer(testMessage, KMIPConstants.FORMAT_TTLV);
82 RequestHeader rh = sl.getRequestHeader();
83 assertEquals(
"1.3", rh.getProtocolVersion());
84 assertEquals(KMIPConstants.BATCHOPTION_UNDO, rh.getBatchErrorOption());
85 assertEquals(
true, rh.getBatchOrderOption());
86 assertEquals(1, rh.getBatchCount());
87 assertEquals(
"Fri Oct 13 10:02:25 PDT 2017", rh.getTimeStamp().toString());
90 for (
int i = 0; i < rh.getBatchCount(); i++) {
92 BatchItem bi = sl.getBatchItem(i + 1);
93 if (bi instanceof GetBatchItem) {
94 GetBatchItem cb = (GetBatchItem) bi;
95 assertEquals(1, cb.getUniqueBatchId()[0]);
96 assertEquals(
"111-222-333-444", cb.getUniqueId());
97 assertEquals(KMIPConstants.KEYFORMAT_PKCS8, cb.getKeyFormatType());
99 KeyWrappingSpecification kws = cb.getWrappingDetails();
100 assertEquals(KMIPConstants.WRAP_ENCRYPT, kws.getMethod());
101 String[] attributeNames = kws.getAttributeNames();
102 assertEquals(
"State", attributeNames[0]);
103 assertEquals(
"KEK-345-4456", kws.getEncryptKeyUID());
105 CryptograhicParameters cyp = kws.getEncryptParams();
106 assertEquals(2, cyp.getInitialCounterValue());
107 assertEquals(KMIPConstants.PAD_PKCS5, cyp.getPaddingMethod());
108 assertEquals(KMIPConstants.MODE_CTR, cyp.getBlockCipherMode());
113 }
catch (Exception e) {
115 System.out.println(e.toString());
static void oneTimeSetUp()
static void oneTimeTearDown()
void JNICall_GetKMIP()
Test: Verify parser can break message into multiple batch items.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.