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-EncryptKMIP");
52 byte[] expectedData = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
56 P6KMIPServerLib sl =
new P6KMIPServerLib();
59 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\":\"Encrypt\"}, {\"tag\":\"RequestPayload\", \"value\":[{\"tag\":\"UniqueIdentifier\", \"type\":\"TextString\", \"value\":\"c031edb5-fc17-4f1d-a0a7-35ff29fbf130\"}, {\"tag\":\"CryptographicParameters\", \"value\":[{\"tag\":\"BlockCipherMode\", \"type\":\"Enumeration\", \"value\":\"ECB\"}]}, {\"tag\":\"Data\", \"type\":\"ByteString\", \"value\":\"01020304050607080910111213141516\"}]}]}]}";
62 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
64 String libVersion = sl.getLibraryVersion();
65 System.out.println(libVersion);
69 sl.setMessageBuffer(testMessage.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGJSON);
72 RequestHeader rh = sl.getRequestHeader();
73 assertEquals(
"1.2", rh.getProtocolVersion());
76 for (
int i = 0; i < rh.getBatchCount(); i++) {
78 BatchItem bi = sl.getBatchItem(i + 1);
79 if (bi instanceof EncryptBatchItem) {
80 EncryptBatchItem ck = (EncryptBatchItem) bi;
82 String uniqueId = ck.getUniqueId();
83 assertEquals(
"c031edb5-fc17-4f1d-a0a7-35ff29fbf130", uniqueId);
85 CryptograhicParameters params = ck.getParams();
86 int mode = params.getBlockCipherMode();
87 assertEquals(mode, KMIPConstants.MODE_ECB);
89 byte[] dataToEncrypt = ck.getData();
90 assertEquals(16, dataToEncrypt.length);
91 for(
int j=0; j < dataToEncrypt.length; j++) {
92 assertEquals( expectedData[j], dataToEncrypt[j]);
95 byte[] IV = ck.getIVCounterNonce();
96 assertEquals(null, IV);
101 }
catch (Exception e) {
103 System.out.println(e.toString());
static void oneTimeTearDown()
static void oneTimeSetUp()
void JNICall_EncryptKMIP()
Test: Verify parser can handle an JSON formated Encrypt operation.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.