1 package com.p6r.kmipserverlib;
5 import java.nio.charset.Charset;
6 import static org.junit.Assert.assertEquals;
22 System.out.println(
"@BeforeClass - oneTimeSetUp");
28 System.out.println(
"@AfterClass - oneTimeTearDown");
34 System.out.println(
"@Before - setUp");
40 System.out.println(
"@After - tearDown");
50 System.out.println(
"@Test - JNICall-DecryptKMIP");
52 byte[] expectedData = { (byte)0xEC, (byte)0x82, 0x0D, (byte)0xDF, (byte)0xA9, 0x62, (byte)0xDE, 0x6C, 0x49, 0x13, 0x6B, (byte)0xAD, 0x1A, (byte)0xE2, 0x71,
53 0x69, 0x77, (byte)0xF1, (byte)0xE1, (byte)0xEA, (byte)0xE6, 0x75, (byte)0x98, 0x51, (byte)0x94, 0x36, 0x5F, (byte)0x81, 0x3C, 0x20,
54 0x41, 0x5F, 0x29, (byte)0xAD, (byte)0xE1, 0x57, (byte)0xD7, (byte)0xA9, (byte)0xFC, (byte)0xA7, 0x03, 0x23, (byte)0x85, 0x3A, 0x54,
55 0x55, (byte)0xFC, 0x45 };
57 byte[] expectedIV = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
61 P6KMIPServerLib sl =
new P6KMIPServerLib();
64 String testMessage =
"{\"tag\":\"RequestMessage\", \"value\":[{\"tag\":\"RequestHeader\", \"value\":[{\"tag\":\"ProtocolVersion\", \"value\":[{\"tag\":\"ProtocolVersionMajor\", \"type\":\"Integer\", \"value\":1}, {\"tag\":\"ProtocolVersionMinor\", \"type\":\"Integer\", \"value\":2}]}, {\"tag\":\"BatchCount\", \"type\":\"Integer\", \"value\":1}]}, {\"tag\":\"BatchItem\", \"value\":[{\"tag\":\"Operation\", \"type\":\"Enumeration\", \"value\":\"Decrypt\"}, {\"tag\":\"RequestPayload\", \"value\":[{\"tag\":\"UniqueIdentifier\", \"type\":\"TextString\", \"value\":\"36af82da-d120-44ef-8dd1-9dd218ab9d4a\"}, {\"tag\":\"CryptographicParameters\", \"value\":[{\"tag\":\"BlockCipherMode\", \"type\":\"Enumeration\", \"value\":\"CBC\"}, {\"tag\":\"PaddingMethod\", \"type\":\"Enumeration\", \"value\":\"PKCS5\"}]}, {\"tag\":\"Data\", \"type\":\"ByteString\", \"value\":\"EC820DDFA962DE6C49136BAD1AE2716977F1E1EAE675985194365F813C20415F29ADE157D7A9FCA70323853A5455FC45\"}, {\"tag\":\"IVCounterNonce\", \"type\":\"ByteString\", \"value\":\"01020304050607080910111213141516\"}]}]}]}";
67 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
69 String libVersion = sl.getLibraryVersion();
70 System.out.println(libVersion);
74 sl.setMessageBuffer(testMessage.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGJSON);
77 RequestHeader rh = sl.getRequestHeader();
78 assertEquals(
"1.2", rh.getProtocolVersion());
81 for (
int i = 0; i < rh.getBatchCount(); i++) {
83 BatchItem bi = sl.getBatchItem(i + 1);
84 if (bi instanceof DecryptBatchItem) {
85 DecryptBatchItem ck = (DecryptBatchItem) bi;
87 String uniqueId = ck.getUniqueId();
88 assertEquals(
"36af82da-d120-44ef-8dd1-9dd218ab9d4a", uniqueId);
90 CryptograhicParameters params = ck.getParams();
91 int mode = params.getBlockCipherMode();
92 assertEquals(mode, KMIPConstants.MODE_CBC);
93 int pad = params.getPaddingMethod();
94 assertEquals(pad, KMIPConstants.PAD_PKCS5);
96 byte[] dataToEncrypt = ck.getData();
97 assertEquals(48, dataToEncrypt.length);
98 for(
int j=0; j < dataToEncrypt.length; j++) {
99 assertEquals( expectedData[j], dataToEncrypt[j]);
102 byte[] IV = ck.getIVCounterNonce();
103 assertEquals(16, IV.length);
104 for(
int k=0; k < IV.length; k++) {
105 assertEquals( expectedIV[k], IV[k]);
111 }
catch (Exception e) {
113 System.out.println(e.toString());
static void oneTimeTearDown()
void JNICall_DecryptKMIP()
Test: Verify parser can handle an JSON formated Encrypt operation.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeSetUp()