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-RegisterTransparentECPrivateKeyKMIP");
55 byte[] expectedBytes = { (byte)0xCB, (byte)0xE5, (byte)0xA4, (byte)0xFD, 0x53, (byte)0xE6, (byte)0xC3, 0x02, 0x7D, 0x66, (byte)0xC2, (byte)0xFC, 0x42, 0x40, 0x60, (byte)0x99, 0x41, 0x42, 0x21, 0x04, 0x6A, 0x01, 0x38, (byte)0xD7, 0x21, (byte)0x9D, (byte)0xDB, (byte)0xEE, (byte)0xF4, 0x6A, 0x58, 0x23 };
59 P6KMIPServerLib sl =
new P6KMIPServerLib();
62 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=\"PrivateKey\"/><TemplateAttribute><Attribute><AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/><AttributeValue type=\"Integer\" value=\"0x00000001\"/></Attribute><Attribute><AttributeName type=\"TextString\" value=\"x-ID\"/><AttributeValue type=\"TextString\" value=\"TC-ECC-1-14-privkey1\"/></Attribute></TemplateAttribute><PrivateKey><KeyBlock><KeyFormatType type=\"Enumeration\" value=\"TransparentECPrivateKey\"/><KeyValue><KeyMaterial><RecommendedCurve type=\"Enumeration\" value=\"SECP256K1\"/><D type=\"BigInteger\" value=\"CBE5A4FD53E6C3027D66C2FC42406099414221046A0138D7219DDBEEF46A5823\"/></KeyMaterial></KeyValue><CryptographicAlgorithm type=\"Enumeration\" value=\"EC\"/><CryptographicLength type=\"Integer\" value=\"256\"/></KeyBlock></PrivateKey></RequestPayload></BatchItem></RequestMessage>";
65 String testMessage2 =
"<RequestMessage>\n" +
66 " <RequestHeader>\n" +
67 " <ProtocolVersion>\n" +
68 " <ProtocolVersionMajor type=\"Integer\" value=\"1\"/>\n" +
69 " <ProtocolVersionMinor type=\"Integer\" value=\"4\"/>\n" +
70 " </ProtocolVersion>\n" +
71 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
72 " </RequestHeader>\n" +
74 " <Operation type=\"Enumeration\" value=\"Register\"/>\n" +
75 " <RequestPayload>\n" +
76 " <ObjectType type=\"Enumeration\" value=\"PrivateKey\"/>\n" +
77 " <TemplateAttribute>\n" +
79 " <AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/>\n" +
80 " <AttributeValue type=\"Integer\" value=\"0x00000001\"/>\n" +
83 " <AttributeName type=\"TextString\" value=\"x-ID\"/>\n" +
84 " <AttributeValue type=\"TextString\" value=\"TC-ECC-1-13-pubkey1_C\"/>\n" +
86 " </TemplateAttribute>\n" +
89 " <KeyFormatType type=\"Enumeration\" value=\"ECPrivateKey\"/>\n" +
91 " <KeyMaterial type=\"ByteString\" value=\"3074020101042044A9071D7C9981FF0337FB542325727DA766B4FC045C8FD6063AAD1EAE29CEAFA00706052B8104000AA1440342000460E215293DC0EF43BA410F099F64E52847EBCED098476AC1CF94B9C6F723779E1FC092EDC2645EAEF86F2FA1187E8EE81EEA7D91E2C5EDDD329EC6A89A5ECCCF\"/>\n" +
93 " <CryptographicAlgorithm type=\"Enumeration\" value=\"ECDSA\"/>\n" +
94 " <CryptographicLength type=\"Integer\" value=\"256\"/>\n" +
97 " </RequestPayload>\n" +
99 "</RequestMessage>\n";
102 String testMessage3 =
"<RequestMessage>\n" +
103 " <RequestHeader>\n" +
104 " <ProtocolVersion>\n" +
105 " <ProtocolVersionMajor type=\"Integer\" value=\"1\"/>\n" +
106 " <ProtocolVersionMinor type=\"Integer\" value=\"4\"/>\n" +
107 " </ProtocolVersion>\n" +
108 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
109 " </RequestHeader>\n" +
111 " <Operation type=\"Enumeration\" value=\"Register\"/>\n" +
112 " <RequestPayload>\n" +
113 " <ObjectType type=\"Enumeration\" value=\"PrivateKey\"/>\n" +
114 " <TemplateAttribute>\n" +
116 " <AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/>\n" +
117 " <AttributeValue type=\"Integer\" value=\"0x00000001\"/>\n" +
120 " <AttributeName type=\"TextString\" value=\"x-ID\"/>\n" +
121 " <AttributeValue type=\"TextString\" value=\"TC-ECC-2-14-prikey1\"/>\n" +
123 " </TemplateAttribute>\n" +
126 " <KeyFormatType type=\"Enumeration\" value=\"PKCS_8\"/>\n" +
128 " <KeyMaterial type=\"ByteString\" value=\"308184020100301006072A8648CE3D020106052B8104000A046D306B0201010420EB2F5F5E14EAE9C3A130078B53D2895EE3538F0DBA9223687E49FF5F7E77638BA14403420004425F86FD82B7DC90A00C6711327B926F5D6C1CDB06834FB69D409E8049CE5A7907A091E79A9B1ACBE6A4E9EF84C425860CAA7BB427033E3393678CC7694EF936\"/>\n" +
130 " <CryptographicAlgorithm type=\"Enumeration\" value=\"EC\"/>\n" +
131 " <CryptographicLength type=\"Integer\" value=\"256\"/>\n" +
134 " </RequestPayload>\n" +
139 sl.initializeLibrary(P6KMIPServerLib.FLAGS_ALLLOG);
141 String libVersion = sl.getLibraryVersion();
142 System.out.println(libVersion);
146 sl.setMessageBuffer(testMessage.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
151 RequestHeader rh = sl.getRequestHeader();
152 assertEquals(
"1.4", rh.getProtocolVersion());
155 for (
int i = 0; i < rh.getBatchCount(); i++) {
157 BatchItem bi = sl.getBatchItem(i + 1);
158 if (bi instanceof RegisterTransparentECPrivateKeyBatchItem) {
159 RegisterTransparentECPrivateKeyBatchItem ck = (RegisterTransparentECPrivateKeyBatchItem) bi;
162 byte[] batchId = ck.getUniqueBatchId();
163 assertEquals(null, batchId);
165 int recommendedCurve = ck.getRecommendedCurve();
166 assertEquals(KMIPConstants.CURVE_SECP256K1, recommendedCurve);
168 BigInteger D = ck.getD();
169 assertNotEquals(null, D);
170 byte[] DBytes = D.toByteArray();
171 assertEquals(32, DBytes.length);
172 for(
int j=0; j < DBytes.length; j++ ) {
173 assertEquals(expectedBytes[j], DBytes[j]);
176 String[] attributes = ck.getTemplateAttributes();
177 assertEquals(2, attributes.length);
178 assertEquals(
"Cryptographic Usage Mask: 1", attributes[0]);
179 assertEquals(
"x-ID: TC-ECC-1-14-privkey1", attributes[1]);
184 }
catch (Exception e) {
186 System.out.println(e.toString());
static void oneTimeSetUp()
void JNICall_RegisterTransparentECPrivateKeyKMIP()
Test: Verify parser can handle an XML formated Register Split Key operation.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeTearDown()