1 package com.p6r.kmipserverlib;
5 import java.nio.charset.Charset;
7 import static org.junit.Assert.assertEquals;
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-RegisterEcKeyKMIP");
53 byte[] expectedKeyBytes = { 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, (byte)0x91, 0x2a, 0x0e, 0x20, (byte)0x8f, 0x5d, (byte)0xd7, 0x34, (byte)0xb1, (byte)0x85, 0x18, 0x47,
54 (byte)0xe4, 0x65, (byte)0x9c, 0x45, (byte)0x88, (byte)0xb1, 0x6d, (byte)0x9f, 0x3b, (byte)0xc1, (byte)0xad, (byte)0xa5, 0x10, (byte)0xea, 0x2c, (byte)0x96, (byte)0x9d, (byte)0xaf, (byte)0x9e,
55 (byte)0xf4, (byte)0xa0, 0x0a, 0x06, 0x08, 0x2a, (byte)0x86, 0x48, (byte)0xce, 0x3d, 0x03, 0x01, 0x07, (byte)0xa1, 0x44, 0x03, 0x42, 0x00, 0x04,
56 (byte)0xb3, 0x44, 0x39, 0x2f, (byte)0xb7, 0x2a, (byte)0xa2, 0x67, (byte)0xf8, 0x6d, 0x7d, (byte)0x83, 0x7d, (byte)0xe1, (byte)0xd9, 0x6c, (byte)0xe9, 0x60, (byte)0xff,
57 (byte)0xc0, 0x5c, (byte)0xee, (byte)0xf3, (byte)0xf1, (byte)0xfa, 0x26, (byte)0xd8, 0x54, 0x6a, 0x64, 0x42, (byte)0xf3, (byte)0xc1, 0x39, 0x7e, (byte)0x92, (byte)0x9a, (byte)0xad,
58 (byte)0x8d, (byte)0xca, (byte)0xb2, 0x5b, 0x28, 0x2c, (byte)0xa8, (byte)0xa1, (byte)0xcf, 0x00, (byte)0xbe, (byte)0xf7, (byte)0xcb, 0x18, (byte)0xa0, (byte)0xf5, (byte)0xea, 0x44, 0x49,
59 0x3a, 0x30, (byte)0xa6, (byte)0xd2, 0x23, (byte)0xb2, 0x5b };
63 P6KMIPServerLib sl =
new P6KMIPServerLib();
67 =
"<RequestMessage>" +
70 "<ProtocolVersionMajor type=\"Integer\" value=\"1\" />" +
71 "<ProtocolVersionMinor type=\"Integer\" value=\"0\" />" +
72 "</ProtocolVersion>" +
73 "<BatchCount type=\"Integer\" value=\"1\" />" +
76 "<Operation type=\"Enumeration\" value=\"Register\" />" +
78 "<ObjectType type=\"Enumeration\" value=\"PrivateKey\" />" +
79 "<TemplateAttribute>" +
81 "<AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\" />" +
82 "<AttributeValue type=\"Integer\" value=\"Sign\" />" +
85 "<AttributeName type=\"TextString\" value=\"x-ID\" />" +
86 "<AttributeValue type=\"TextString\" value=\"TC-ECC-1-10-prikey1\" />" +
88 "<Attribute><AttributeName type=\"TextString\" value=\"Name\"/><AttributeValue><NameValue type=\"TextString\" value=\"App-123-jdh-3432-X\"/><NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/></AttributeValue></Attribute>" +
89 "</TemplateAttribute>" +
92 "<KeyFormatType type=\"Enumeration\" value=\"ECPrivateKey\" />" +
94 "<KeyMaterial type=\"ByteString\" value=\"30770201010420912a0e208f5dd734b1851847e4659c4588b16d9f3bc1ada510ea2c969daf9ef4a00a06082a8648ce3d030107a14403420004b344392fb72aa267f86d7d837de1d96ce960ffc05ceef3f1fa26d8546a6442f3c1397e929aad8dcab25b282ca8a1cf00bef7cb18a0f5ea44493a30a6d223b25b\" />" +
96 "<CryptographicAlgorithm type=\"Enumeration\" value=\"ECDSA\" />" +
97 "<CryptographicLength type=\"Integer\" value=\"256\" />" +
100 "</RequestPayload>" +
105 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
107 String libVersion = sl.getLibraryVersion();
108 System.out.println(libVersion);
112 sl.setMessageBuffer(testMessage.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
115 RequestHeader rh = sl.getRequestHeader();
116 assertEquals(
"1.0", rh.getProtocolVersion());
119 for (
int i = 0; i < rh.getBatchCount(); i++) {
121 BatchItem bi = sl.getBatchItem(i + 1);
122 if (bi instanceof RegisterPrivateKeyBatchItem) {
123 RegisterPrivateKeyBatchItem rb = (RegisterPrivateKeyBatchItem) bi;
124 assertEquals(null, rb.getUniqueBatchId());
125 assertEquals(KMIPConstants.ALG_ECDSA, rb.getCryptoAlgorithm());
126 byte[] keyBytes = rb.getKeyMaterial();
127 assertEquals( 121, keyBytes.length );
128 for (
int j = 0; j < keyBytes.length; j++) {
129 assertEquals(keyBytes[j], expectedKeyBytes[j]);
132 String[] templateAttributes = rb.getTemplateAttributes();
133 assertEquals(3, templateAttributes.length);
134 assertEquals(
"Cryptographic Usage Mask: 1", templateAttributes[0]);
135 assertEquals(
"x-ID: TC-ECC-1-10-prikey1", templateAttributes[1]);
136 assertEquals(
"Name: App-123-jdh-3432-X - text_string", templateAttributes[2]);
138 String[] templateNames = rb.getTemplateNames();
139 if (null != templateNames) assertEquals(0,1);
141 String[] keyAttributes = rb.getKeyValueAttributes();
142 if (null != templateNames) assertEquals(0,1);
147 }
catch (Exception e) {
149 System.out.println(e.toString());
static void oneTimeSetUp()
void JNICall_RegisterECKeyKMIP()
Test: Verify parser can break message into multiple batch items.
static void oneTimeTearDown()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.