1 package com.p6r.kmipserverlib;
5 import java.math.BigInteger;
6 import java.nio.charset.Charset;
8 import static org.junit.Assert.assertEquals;
9 import static org.junit.Assert.assertNotEquals;
25 System.out.println(
"@BeforeClass - oneTimeSetUp");
31 System.out.println(
"@AfterClass - oneTimeTearDown");
37 System.out.println(
"@Before - setUp");
43 System.out.println(
"@After - tearDown");
53 System.out.println(
"@Test - JNICall-RegisterTransparentECPrublicKeyKMIP");
55 byte[] expectedBytes = { 0x04, 0x4D, (byte)0xAD, (byte)0x9B, 0x5C, (byte)0x8E, 0x4F, 0x1C, 0x55, 0x3A, (byte)0xFF, 0x3C, 0x0E, 0x17, (byte)0x83, (byte)0x94, (byte)0xC4, 0x64, (byte)0xC2, 0x18, (byte)0xC3, 0x2D,
56 (byte)0xEA, (byte)0xAC, (byte)0x8A, 0x7B, 0x2A, (byte)0xF5, 0x05, (byte)0xA3, 0x10, 0x3C, (byte)0x8F, 0x03, (byte)0xBC, (byte)0xAD, (byte)0xD4, 0x78, 0x6A, (byte)0xDB, 0x1A, (byte)0x88, (byte)0xBA, 0x7B,
57 0x5A, 0x48, 0x2E, 0x49, (byte)0xAC, 0x7B, 0x07, (byte)0xC7, 0x6B, 0x4C, 0x19, (byte)0xCA, 0x1E, (byte)0xB1, (byte)0xBE, (byte)0xD1, (byte)0x8B, (byte)0xBB, 0x3A, (byte)0xC3, (byte)0xF5 };
61 P6KMIPServerLib sl =
new P6KMIPServerLib();
64 String testMessage =
"<RequestMessage><RequestHeader><ProtocolVersion><ProtocolVersionMajor type=\"Integer\" value=\"1\"/><ProtocolVersionMinor type=\"Integer\" value=\"4\"/></ProtocolVersion><BatchCount type=\"Integer\" value=\"1\"/></RequestHeader><BatchItem><Operation type=\"Enumeration\" value=\"Register\"/><RequestPayload><ObjectType type=\"Enumeration\" value=\"PublicKey\"/><TemplateAttribute><Attribute><AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/><AttributeValue type=\"Integer\" value=\"0x00000002\"/></Attribute><Attribute><AttributeName type=\"TextString\" value=\"x-ID\"/><AttributeValue type=\"TextString\" value=\"TC-ECC-1-14-pubkey\"/></Attribute></TemplateAttribute><PublicKey><KeyBlock><KeyFormatType type=\"Enumeration\" value=\"TransparentECPublicKey\"/><KeyValue><KeyMaterial><RecommendedCurve type=\"Enumeration\" value=\"SECP256K1\"/><QString type=\"BigInteger\" value=\"044DAD9B5C8E4F1C553AFF3C0E178394C464C218C32DEAAC8A7B2AF505A3103C8F03BCADD4786ADB1A88BA7B5A482E49AC7B07C76B4C19CA1EB1BED18BBB3AC3F5\"/></KeyMaterial></KeyValue><CryptographicAlgorithm type=\"Enumeration\" value=\"EC\"/><CryptographicLength type=\"Integer\" value=\"256\"/></KeyBlock></PublicKey></RequestPayload></BatchItem></RequestMessage>";
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_MSGXML);
77 RequestHeader rh = sl.getRequestHeader();
78 assertEquals(
"1.4", rh.getProtocolVersion());
81 for (
int i = 0; i < rh.getBatchCount(); i++) {
83 BatchItem bi = sl.getBatchItem(i + 1);
84 if (bi instanceof RegisterTransparentECPublicKeyBatchItem) {
85 RegisterTransparentECPublicKeyBatchItem ck = (RegisterTransparentECPublicKeyBatchItem) bi;
88 byte[] batchId = ck.getUniqueBatchId();
89 assertEquals(null, batchId);
91 int recommendedCurve = ck.getRecommendedCurve();
92 assertEquals(KMIPConstants.CURVE_SECP256K1, recommendedCurve);
94 byte[] QBytes = ck.getQ();
95 assertEquals(65, QBytes.length);
96 for(
int j=0; j < QBytes.length; j++ ) {
97 assertEquals(expectedBytes[j], QBytes[j]);
100 String[] attributes = ck.getTemplateAttributes();
101 assertEquals(2, attributes.length);
102 assertEquals(
"Cryptographic Usage Mask: 2", attributes[0]);
103 assertEquals(
"x-ID: TC-ECC-1-14-pubkey", attributes[1]);
108 }
catch (Exception e) {
110 System.out.println(e.toString());
void JNICall_RegisterTransparentECPublicKeyKMIP()
Test: Verify parser can handle an XML formated Register Split Key operation.
static void oneTimeTearDown()
static void oneTimeSetUp()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.