Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JniCertifyKmip.java
Go to the documentation of this file.
1 package com.p6r.kmipserverlib;
2 
3 import org.junit.*;
4 
5 import java.nio.charset.Charset;
6 
7 import static org.junit.Assert.assertEquals;
8 
18 public class JniCertifyKmip {
19 
20  @BeforeClass
21  public static void oneTimeSetUp() {
22  // NOOP
23  System.out.println("@BeforeClass - oneTimeSetUp");
24  }
25 
26  @AfterClass
27  public static void oneTimeTearDown() {
28  // NOOP
29  System.out.println("@AfterClass - oneTimeTearDown");
30  }
31 
32  @Before
33  public void setUp() {
34  // NOOP
35  System.out.println("@Before - setUp");
36  }
37 
38  @After
39  public void tearDown() {
40  // NOOP
41  System.out.println("@After - tearDown");
42  }
43 
49  @Test
50  public void JniCertifyKmip() {
51  System.out.println("@Test - JNICall-CertifyKMIP");
52 
53  byte[] expectedBytes = {
54  (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x81, (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x69, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30, (byte)0x3c, (byte)0x31, (byte)0x0b, (byte)0x30, (byte)0x09, (byte)0x06, (byte)0x03, (byte)0x55, (byte)0x04, (byte)0x06, (byte)0x13, (byte)0x02, (byte)0x55, (byte)0x53, (byte)0x31, (byte)0x0d, (byte)0x30, (byte)0x0b, (byte)0x06, (byte)0x03, (byte)0x55, (byte)0x04, (byte)0x0a, (byte)0x13, (byte)0x04, (byte)0x41,
55  (byte)0x43, (byte)0x4d, (byte)0x45, (byte)0x31, (byte)0x0d, (byte)0x30, (byte)0x0b, (byte)0x06, (byte)0x03, (byte)0x55, (byte)0x04, (byte)0x0b, (byte)0x13, (byte)0x04, (byte)0x4b, (byte)0x4d, (byte)0x49, (byte)0x50, (byte)0x31, (byte)0x0f, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x03, (byte)0x55, (byte)0x04, (byte)0x03, (byte)0x13, (byte)0x06, (byte)0x43, (byte)0x6c, (byte)0x69, (byte)0x65, (byte)0x6e, (byte)0x74, (byte)0x30, (byte)0x82, (byte)0x01,
56  (byte)0x22, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x03, (byte)0x82, (byte)0x01, (byte)0x0f, (byte)0x00, (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x0a, (byte)0x02, (byte)0x82, (byte)0x01, (byte)0x01, (byte)0x00, (byte)0xab, (byte)0x7f, (byte)0x16, (byte)0x1c, (byte)0x00, (byte)0x42, (byte)0x49, (byte)0x6c,
57  (byte)0xcd, (byte)0x6c, (byte)0x6d, (byte)0x4d, (byte)0xad, (byte)0xb9, (byte)0x19, (byte)0x97, (byte)0x34, (byte)0x35, (byte)0x35, (byte)0x77, (byte)0x76, (byte)0x00, (byte)0x3a, (byte)0xcf, (byte)0x54, (byte)0xb7, (byte)0xaf, (byte)0x1e, (byte)0x44, (byte)0x0a, (byte)0xfb, (byte)0x80, (byte)0xb6, (byte)0x4a, (byte)0x87, (byte)0x55, (byte)0xf8, (byte)0x00, (byte)0x2c, (byte)0xfe, (byte)0xba, (byte)0x6b, (byte)0x18, (byte)0x45, (byte)0x40, (byte)0xa2,
58  (byte)0xd6, (byte)0x60, (byte)0x86, (byte)0xd7, (byte)0x46, (byte)0x48, (byte)0x34, (byte)0x6d, (byte)0x75, (byte)0xb8, (byte)0xd7, (byte)0x18, (byte)0x12, (byte)0xb2, (byte)0x05, (byte)0x38, (byte)0x7c, (byte)0x0f, (byte)0x65, (byte)0x83, (byte)0xbc, (byte)0x4d, (byte)0x7d, (byte)0xc7, (byte)0xec, (byte)0x11, (byte)0x4f, (byte)0x3b, (byte)0x17, (byte)0x6b, (byte)0x79, (byte)0x57, (byte)0xc4, (byte)0x22, (byte)0xe7, (byte)0xd0, (byte)0x3f, (byte)0xc6,
59  (byte)0x26, (byte)0x7f, (byte)0xa2, (byte)0xa6, (byte)0xf8, (byte)0x9b, (byte)0x9b, (byte)0xee, (byte)0x9e, (byte)0x60, (byte)0xa1, (byte)0xd7, (byte)0xc2, (byte)0xd8, (byte)0x33, (byte)0xe5, (byte)0xa5, (byte)0xf4, (byte)0xbb, (byte)0x0b, (byte)0x14, (byte)0x34, (byte)0xf4, (byte)0xe7, (byte)0x95, (byte)0xa4, (byte)0x11, (byte)0x00, (byte)0xf8, (byte)0xaa, (byte)0x21, (byte)0x49, (byte)0x00, (byte)0xdf, (byte)0x8b, (byte)0x65, (byte)0x08, (byte)0x9f,
60  (byte)0x98, (byte)0x13, (byte)0x5b, (byte)0x1c, (byte)0x67, (byte)0xb7, (byte)0x01, (byte)0x67, (byte)0x5a, (byte)0xbd, (byte)0xbc, (byte)0x7d, (byte)0x57, (byte)0x21, (byte)0xaa, (byte)0xc9, (byte)0xd1, (byte)0x4a, (byte)0x7f, (byte)0x08, (byte)0x1f, (byte)0xce, (byte)0xc8, (byte)0x0b, (byte)0x64, (byte)0xe8, (byte)0xa0, (byte)0xec, (byte)0xc8, (byte)0x29, (byte)0x53, (byte)0x53, (byte)0xc7, (byte)0x95, (byte)0x32, (byte)0x8a, (byte)0xbf, (byte)0x70,
61  (byte)0xe1, (byte)0xb4, (byte)0x2e, (byte)0x7b, (byte)0xb8, (byte)0xb7, (byte)0xf4, (byte)0xe8, (byte)0xac, (byte)0x8c, (byte)0x81, (byte)0x0c, (byte)0xdb, (byte)0x66, (byte)0xe3, (byte)0xd2, (byte)0x11, (byte)0x26, (byte)0xeb, (byte)0xa8, (byte)0xda, (byte)0x7d, (byte)0x0c, (byte)0xa3, (byte)0x41, (byte)0x42, (byte)0xcb, (byte)0x76, (byte)0xf9, (byte)0x1f, (byte)0x01, (byte)0x3d, (byte)0xa8, (byte)0x09, (byte)0xe9, (byte)0xc1, (byte)0xb7, (byte)0xae,
62  (byte)0x64, (byte)0xc5, (byte)0x41, (byte)0x30, (byte)0xfb, (byte)0xc2, (byte)0x1d, (byte)0x80, (byte)0xe9, (byte)0xc2, (byte)0xcb, (byte)0x06, (byte)0xc5, (byte)0xc8, (byte)0xd7, (byte)0xcc, (byte)0xe8, (byte)0x94, (byte)0x6a, (byte)0x9a, (byte)0xc9, (byte)0x9b, (byte)0x1c, (byte)0x28, (byte)0x15, (byte)0xc3, (byte)0x61, (byte)0x2a, (byte)0x29, (byte)0xa8, (byte)0x2d, (byte)0x73, (byte)0xa1, (byte)0xf9, (byte)0x93, (byte)0x74, (byte)0xfe, (byte)0x30,
63  (byte)0xe5, (byte)0x49, (byte)0x51, (byte)0x66, (byte)0x2a, (byte)0x6e, (byte)0xda, (byte)0x29, (byte)0xc6, (byte)0xfc, (byte)0x41, (byte)0x13, (byte)0x35, (byte)0xd5, (byte)0xdc, (byte)0x74, (byte)0x26, (byte)0xb0, (byte)0xf6, (byte)0x05, (byte)0x02, (byte)0x03, (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xa0, (byte)0x00, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01,
64  (byte)0x01, (byte)0x05, (byte)0x05, (byte)0x00, (byte)0x03, (byte)0x82, (byte)0x01, (byte)0x01, (byte)0x00, (byte)0x2d, (byte)0x90, (byte)0xf5, (byte)0x49, (byte)0x2c, (byte)0x3d, (byte)0xf1, (byte)0x77, (byte)0x1d, (byte)0xf4, (byte)0xe8, (byte)0x7e, (byte)0x10, (byte)0x87, (byte)0xcb, (byte)0x95, (byte)0x21, (byte)0x97, (byte)0x31, (byte)0x9a, (byte)0x96, (byte)0x96, (byte)0xe2, (byte)0xd5, (byte)0x88, (byte)0xef, (byte)0xda, (byte)0x58, (byte)0x0d,
65  (byte)0x8d, (byte)0x33, (byte)0x04, (byte)0x42, (byte)0x7b, (byte)0x99, (byte)0x7c, (byte)0xd9, (byte)0x21, (byte)0xad, (byte)0x7c, (byte)0x67, (byte)0x4a, (byte)0xea, (byte)0x41, (byte)0x3f, (byte)0xba, (byte)0x85, (byte)0xfd, (byte)0x61, (byte)0xe6, (byte)0xa4, (byte)0x81, (byte)0xde, (byte)0x9a, (byte)0xb2, (byte)0xe8, (byte)0xa4, (byte)0xff, (byte)0x43, (byte)0xc0, (byte)0x26, (byte)0x55, (byte)0x01, (byte)0x5d, (byte)0x34, (byte)0x37, (byte)0xf7,
66  (byte)0x83, (byte)0xfe, (byte)0x0c, (byte)0x78, (byte)0x15, (byte)0x19, (byte)0xcd, (byte)0x08, (byte)0xff, (byte)0xd3, (byte)0xc0, (byte)0x07, (byte)0xc7, (byte)0xfa, (byte)0xde, (byte)0x96, (byte)0x32, (byte)0xfe, (byte)0x56, (byte)0x59, (byte)0xe2, (byte)0xca, (byte)0xc3, (byte)0x5b, (byte)0xd6, (byte)0xaa, (byte)0xf3, (byte)0xe1, (byte)0x3d, (byte)0xc1, (byte)0x80, (byte)0x97, (byte)0xd9, (byte)0x96, (byte)0xdf, (byte)0x01, (byte)0xb6, (byte)0x6f,
67  (byte)0xc5, (byte)0xe2, (byte)0x6c, (byte)0xa1, (byte)0x09, (byte)0x38, (byte)0x08, (byte)0x63, (byte)0xa2, (byte)0x09, (byte)0x12, (byte)0x5c, (byte)0xc0, (byte)0xfd, (byte)0x79, (byte)0x53, (byte)0x3f, (byte)0x32, (byte)0x7f, (byte)0xa1, (byte)0xca, (byte)0xd4, (byte)0x44, (byte)0xd8, (byte)0x9d, (byte)0x3f, (byte)0xf8, (byte)0x1b, (byte)0x92, (byte)0xa9, (byte)0x14, (byte)0x28, (byte)0xc4, (byte)0x69, (byte)0xc8, (byte)0x46, (byte)0x09, (byte)0x0f,
68  (byte)0xd1, (byte)0x32, (byte)0x48, (byte)0x46, (byte)0xe1, (byte)0x2d, (byte)0x01, (byte)0x67, (byte)0x19, (byte)0x62, (byte)0xc3, (byte)0x32, (byte)0xa7, (byte)0x82, (byte)0x61, (byte)0x52, (byte)0xda, (byte)0xaf, (byte)0x48, (byte)0x6c, (byte)0xc8, (byte)0x67, (byte)0x18, (byte)0x5c, (byte)0x2e, (byte)0x27, (byte)0xca, (byte)0xf2, (byte)0xf0, (byte)0x09, (byte)0x89, (byte)0x8d, (byte)0xb0, (byte)0x7f, (byte)0xe4, (byte)0xb4, (byte)0x5c, (byte)0x51,
69  (byte)0x81, (byte)0x92, (byte)0xaa, (byte)0x49, (byte)0x3d, (byte)0x8f, (byte)0x8c, (byte)0x01, (byte)0x98, (byte)0xdb, (byte)0x67, (byte)0xf9, (byte)0x06, (byte)0x72, (byte)0xab, (byte)0x6d, (byte)0xe0, (byte)0x5a, (byte)0x08, (byte)0x03, (byte)0x29, (byte)0x41, (byte)0x37, (byte)0x7f, (byte)0x47, (byte)0x3d, (byte)0x80, (byte)0x71, (byte)0x6d, (byte)0x85, (byte)0xad, (byte)0xc6, (byte)0x18, (byte)0x20, (byte)0x03, (byte)0xab, (byte)0x34, (byte)0x94,
70  (byte)0x23, (byte)0x02, (byte)0x21, (byte)0x4e, (byte)0xb3, (byte)0x89, (byte)0x5f, (byte)0x15, (byte)0x40, (byte)0x3f, (byte)0x26, (byte)0x16, (byte)0xad, (byte)0xfd, (byte)0x6b, (byte)0xb5, (byte)0xe6, (byte)0xaa, (byte)0x47, (byte)0xfa, (byte)0x38, (byte)0xc9, (byte)0xdf, (byte)0xc7, (byte)0x3f, (byte)0x4d, (byte)0xe8, (byte)0x0d, (byte)0xdb, (byte)0x91, (byte)0xbd, (byte)0xb0, (byte)0x4d, (byte)0x21, (byte)0xc8, (byte)0x2b, (byte)0xa6
71  };
72 
73  // -> this parser is multi-thread safe by using JNI monitor locking
74  // -> use one parser object per server thread is recommended
75  P6KMIPServerLib sl = new P6KMIPServerLib();
76 
77  // -> KMIP 1.1 XML message with 1 batch item generated by P6R's Secure KMIP Client (SKC)
78  String testMessage1_1 = "<RequestMessage>\n" +
79  " <RequestHeader>\n" +
80  " <ProtocolVersion>\n" +
81  " <ProtocolVersionMajor type=\"Integer\" value=\"1\"/>\n" +
82  " <ProtocolVersionMinor type=\"Integer\" value=\"1\"/>\n" +
83  " </ProtocolVersion>\n" +
84  " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
85  " </RequestHeader>\n" +
86  " <BatchItem>\n" +
87  " <Operation type=\"Enumeration\" value=\"Certify\"/>\n" +
88  " <RequestPayload>\n" +
89  " <UniqueIdentifier type=\"TextString\" value=\"1111-22222-33333-44444\"/>\n" +
90  " <CertificateRequestType type=\"Enumeration\" value=\"PKCS_10\"/>\n" +
91  " <CertificateRequest type=\"ByteString\" value=\"3082028130820169020100303c310b3009060355040613025553310d300b060355040a130441434d45310d300b060355040b13044b4d4950310f300d06035504031306436c69656e7430820122300d06092a864886f70d01010105000382010f003082010a0282010100ab7f161c0042496ccd6c6d4dadb919973435357776003acf54b7af1e440afb80b64a8755f8002cfeba6b184540a2d66086d74648346d75b8d71812b205387c0f6583bc4d7dc7ec114f3b176b7957c422e7d03fc6267fa2a6f89b9bee9e60a1d7c2d833e5a5f4bb0b1434f4e795a41100f8aa214900df8b65089f98135b1c67b701675abdbc7d5721aac9d14a7f081fcec80b64e8a0ecc8295353c795328abf70e1b42e7bb8b7f4e8ac8c810cdb66e3d21126eba8da7d0ca34142cb76f91f013da809e9c1b7ae64c54130fbc21d80e9c2cb06c5c8d7cce8946a9ac99b1c2815c3612a29a82d73a1f99374fe30e54951662a6eda29c6fc411335d5dc7426b0f6050203010001a000300d06092a864886f70d010105050003820101002d90f5492c3df1771df4e87e1087cb952197319a9696e2d588efda580d8d3304427b997cd921ad7c674aea413fba85fd61e6a481de9ab2e8a4ff43c02655015d3437f783fe0c781519cd08ffd3c007c7fade9632fe5659e2cac35bd6aaf3e13dc18097d996df01b66fc5e26ca109380863a209125cc0fd79533f327fa1cad444d89d3ff81b92a91428c469c846090fd1324846e12d01671962c332a7826152daaf486cc867185c2e27caf2f009898db07fe4b45c518192aa493d8f8c0198db67f90672ab6de05a08032941377f473d80716d85adc6182003ab34942302214eb3895f15403f2616adfd6bb5e6aa47fa38c9dfc73f4de80ddb91bdb04d21c82ba6\"/>\n" +
92  " <TemplateAttribute>\n" +
93  " <Attribute>\n" +
94  " <AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/>\n" +
95  " <AttributeValue type=\"Integer\" value=\"Verify Sign\"/>\n" +
96  " </Attribute>\n" +
97  " <Attribute>\n" +
98  " <AttributeName type=\"TextString\" value=\"Name\"/>\n" +
99  " <AttributeValue>\n" +
100  " <NameValue type=\"TextString\" value=\"TC-134-11-certificate1\"/>\n" +
101  " <NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/>\n" +
102  " </AttributeValue>\n" +
103  " </Attribute>\n" +
104  " </TemplateAttribute>\n" +
105  " </RequestPayload>\n" +
106  " </BatchItem>\n" +
107  "</RequestMessage>";
108 
109  String testMessage1_2 ="<RequestMessage>\n" +
110  " <RequestHeader>\n" +
111  " <ProtocolVersion>\n" +
112  " <ProtocolVersionMajor type=\"Integer\" value=\"1\"/>\n" +
113  " <ProtocolVersionMinor type=\"Integer\" value=\"4\"/>\n" +
114  " </ProtocolVersion>\n" +
115  " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
116  " </RequestHeader>\n" +
117  " <BatchItem>\n" +
118  " <Operation type=\"Enumeration\" value=\"ReCertify\"/>\n" +
119  " <RequestPayload>\n" +
120  " <UniqueIdentifier type=\"TextString\" value=\"11001-22222-33333-ABABABAB\"/>\n" +
121  " <CertificateRequestType type=\"Enumeration\" value=\"PKCS_10\"/>\n" +
122  " <CertificateRequest type=\"ByteString\" value=\"3082028130820169020100303c310b3009060355040613025553310d300b060355040a130441434d45310d300b060355040b13044b4d4950310f300d06035504031306436c69656e7430820122300d06092a864886f70d01010105000382010f003082010a0282010100ab7f161c0042496ccd6c6d4dadb919973435357776003acf54b7af1e440afb80b64a8755f8002cfeba6b184540a2d66086d74648346d75b8d71812b205387c0f6583bc4d7dc7ec114f3b176b7957c422e7d03fc6267fa2a6f89b9bee9e60a1d7c2d833e5a5f4bb0b1434f4e795a41100f8aa214900df8b65089f98135b1c67b701675abdbc7d5721aac9d14a7f081fcec80b64e8a0ecc8295353c795328abf70e1b42e7bb8b7f4e8ac8c810cdb66e3d21126eba8da7d0ca34142cb76f91f013da809e9c1b7ae64c54130fbc21d80e9c2cb06c5c8d7cce8946a9ac99b1c2815c3612a29a82d73a1f99374fe30e54951662a6eda29c6fc411335d5dc7426b0f6050203010001a000300d06092a864886f70d010105050003820101002d90f5492c3df1771df4e87e1087cb952197319a9696e2d588efda580d8d3304427b997cd921ad7c674aea413fba85fd61e6a481de9ab2e8a4ff43c02655015d3437f783fe0c781519cd08ffd3c007c7fade9632fe5659e2cac35bd6aaf3e13dc18097d996df01b66fc5e26ca109380863a209125cc0fd79533f327fa1cad444d89d3ff81b92a91428c469c846090fd1324846e12d01671962c332a7826152daaf486cc867185c2e27caf2f009898db07fe4b45c518192aa493d8f8c0198db67f90672ab6de05a08032941377f473d80716d85adc6182003ab34942302214eb3895f15403f2616adfd6bb5e6aa47fa38c9dfc73f4de80ddb91bdb04d21c82ba6\"/>\n" +
123  " <Offset type=\"Interval\" value=\"300\"/>\n" +
124  " <TemplateAttribute>\n" +
125  " <Attribute>\n" +
126  " <AttributeName type=\"TextString\" value=\"Cryptographic Usage Mask\"/>\n" +
127  " <AttributeValue type=\"Integer\" value=\"Verify Sign\"/>\n" +
128  " </Attribute>\n" +
129  " <Attribute>\n" +
130  " <AttributeName type=\"TextString\" value=\"Name\"/>\n" +
131  " <AttributeValue>\n" +
132  " <NameValue type=\"TextString\" value=\"TC-134-14-certificate2\"/>\n" +
133  " <NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/>\n" +
134  " </AttributeValue>\n" +
135  " </Attribute>\n" +
136  " </TemplateAttribute>\n" +
137  " </RequestPayload>\n" +
138  " </BatchItem>\n" +
139  "</RequestMessage>";
140 
141  // -> KMIP 2.0 adds the Certificate Request Unique Identifier
142  String testMessage20_1 ="<RequestMessage>\n" +
143  " <RequestHeader>\n" +
144  " <ProtocolVersion>\n" +
145  " <ProtocolVersionMajor type=\"Integer\" value=\"2\"/>\n" +
146  " <ProtocolVersionMinor type=\"Integer\" value=\"0\"/>\n" +
147  " </ProtocolVersion>\n" +
148  " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
149  " </RequestHeader>\n" +
150  " <BatchItem>\n" +
151  " <Operation type=\"Enumeration\" value=\"ReCertify\"/>\n" +
152  " <RequestPayload>\n" +
153  " <UniqueIdentifier type=\"TextString\" value=\"11001-22222-33333-ABABABAB\"/>\n" +
154  " <CertificateRequestUniqueIdentifier type=\"TextString\" value=\"BBBBBF-22222-33333-ABABABAB\"/>\n" +
155  " <CertificateRequestType type=\"Enumeration\" value=\"PKCS_10\"/>\n" +
156  " <CertificateRequest type=\"ByteString\" value=\"3082028130820169020100303c310b3009060355040613025553310d300b060355040a130441434d45310d300b060355040b13044b4d4950310f300d06035504031306436c69656e7430820122300d06092a864886f70d01010105000382010f003082010a0282010100ab7f161c0042496ccd6c6d4dadb919973435357776003acf54b7af1e440afb80b64a8755f8002cfeba6b184540a2d66086d74648346d75b8d71812b205387c0f6583bc4d7dc7ec114f3b176b7957c422e7d03fc6267fa2a6f89b9bee9e60a1d7c2d833e5a5f4bb0b1434f4e795a41100f8aa214900df8b65089f98135b1c67b701675abdbc7d5721aac9d14a7f081fcec80b64e8a0ecc8295353c795328abf70e1b42e7bb8b7f4e8ac8c810cdb66e3d21126eba8da7d0ca34142cb76f91f013da809e9c1b7ae64c54130fbc21d80e9c2cb06c5c8d7cce8946a9ac99b1c2815c3612a29a82d73a1f99374fe30e54951662a6eda29c6fc411335d5dc7426b0f6050203010001a000300d06092a864886f70d010105050003820101002d90f5492c3df1771df4e87e1087cb952197319a9696e2d588efda580d8d3304427b997cd921ad7c674aea413fba85fd61e6a481de9ab2e8a4ff43c02655015d3437f783fe0c781519cd08ffd3c007c7fade9632fe5659e2cac35bd6aaf3e13dc18097d996df01b66fc5e26ca109380863a209125cc0fd79533f327fa1cad444d89d3ff81b92a91428c469c846090fd1324846e12d01671962c332a7826152daaf486cc867185c2e27caf2f009898db07fe4b45c518192aa493d8f8c0198db67f90672ab6de05a08032941377f473d80716d85adc6182003ab34942302214eb3895f15403f2616adfd6bb5e6aa47fa38c9dfc73f4de80ddb91bdb04d21c82ba6\"/>\n" +
157  " <Offset type=\"Interval\" value=\"3000\"/>\n" +
158  " <Attributes>\n" +
159  " <CryptographicUsageMask type=\"Integer\" value=\"Sign\" />\n" +
160  " </Attributes>\n" +
161  " </RequestPayload>\n" +
162  " </BatchItem>\n" +
163  "</RequestMessage>";
164 
165  try {
166  sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
167 
168  String libVersion = sl.getLibraryVersion();
169  System.out.println(libVersion);
170 
171  // -> server read incoming KMIP request message from a socket and loaded those bytes (e.g., TTLV, XML, JSON) into the parser)
172  // -> the type of message: TTLC, XML, JSON can be determine by the mime type passed in the HTTP request, or lack of one if just using SSL connection
173  sl.setMessageBuffer(testMessage1_1.getBytes(Charset.forName("UTF-8")), KMIPConstants.FORMAT_MSGXML);
174 
175  // -> test certify KMIP 1.x
176  RequestHeader rh = sl.getRequestHeader();
177  assertEquals("1.1", rh.getProtocolVersion());
178 
179  // -> parsed message is maintained in parser until another call to setMessageBuffer() of freeLibrary() is called
180  for (int i = 0; i < rh.getBatchCount(); i++) {
181 
182  BatchItem bi = sl.getBatchItem(i + 1);
183  if (bi instanceof CertifyBatchItem) {
184  CertifyBatchItem rb = (CertifyBatchItem) bi;
185 
186  String uniqueId = rb.getUniqueId();
187  assertEquals("1111-22222-33333-44444", uniqueId);
188 
189  int certificateRequestType = rb.getRequestType();
190  assertEquals(KMIPConstants.CERTREQUEST_PKCS10, certificateRequestType);
191 
192  byte[] requestValue = rb.getCertificateRequestValue();
193  assertEquals(requestValue.length, expectedBytes.length);
194  for( int j=0; j < expectedBytes.length; j++ ) {
195  assertEquals( requestValue[j], expectedBytes[j]);
196  }
197 
198  String[] attributes = rb.getAttributes();
199  assertEquals(2, attributes.length);
200  assertEquals("Cryptographic Usage Mask: 3", attributes[0]);
201  assertEquals("Name: TC-134-11-certificate1 - text_string", attributes[1]);
202  }
203  }
204 
205  // -> test re-certify KMIP 1.x
206  sl.setMessageBuffer(testMessage1_2.getBytes(Charset.forName("UTF-8")), KMIPConstants.FORMAT_MSGXML);
207  rh = sl.getRequestHeader();
208  assertEquals("1.4", rh.getProtocolVersion());
209 
210  for (int i = 0; i < rh.getBatchCount(); i++) {
211 
212  BatchItem bi = sl.getBatchItem(i + 1);
213  if (bi instanceof ReCertifyBatchItem) {
214  ReCertifyBatchItem rb = (ReCertifyBatchItem) bi;
215 
216  String uniqueId = rb.getUniqueId();
217  assertEquals("11001-22222-33333-ABABABAB", uniqueId);
218 
219  int certificateRequestType = rb.getRequestType();
220  assertEquals(KMIPConstants.CERTREQUEST_PKCS10, certificateRequestType);
221 
222  int offset = rb.getOffset();
223  assertEquals(offset, 300);
224 
225  byte[] requestValue = rb.getCertificateRequestValue();
226  assertEquals(requestValue.length, expectedBytes.length);
227  for( int j=0; j < expectedBytes.length; j++ ) {
228  assertEquals( requestValue[j], expectedBytes[j]);
229  }
230 
231  String[] attributes = rb.getAttributes();
232  assertEquals(2, attributes.length);
233  assertEquals("Cryptographic Usage Mask: 3", attributes[0]);
234  assertEquals("Name: TC-134-14-certificate2 - text_string", attributes[1]);
235  }
236  }
237 
238  // -> test re-certify KMIP 2.0
239  sl.setMessageBuffer(testMessage20_1.getBytes(Charset.forName("UTF-8")), KMIPConstants.FORMAT_MSGXML);
240  rh = sl.getRequestHeader();
241  assertEquals("2.0", rh.getProtocolVersion());
242 
243  for (int i = 0; i < rh.getBatchCount(); i++) {
244 
245  BatchItem bi = sl.getBatchItem(i + 1);
246  if (bi instanceof ReCertifyBatchItem) {
247  ReCertifyBatchItem rb = (ReCertifyBatchItem) bi;
248 
249  String uniqueId = rb.getUniqueId();
250  assertEquals("11001-22222-33333-ABABABAB", uniqueId);
251 
252  String requestUID = rb.getCertificateRequestUniqueId();
253  assertEquals("BBBBBF-22222-33333-ABABABAB", requestUID);
254 
255  int certificateRequestType = rb.getRequestType();
256  assertEquals(KMIPConstants.CERTREQUEST_PKCS10, certificateRequestType);
257 
258  int offset = rb.getOffset();
259  assertEquals(offset, 3000);
260 
261  byte[] requestValue = rb.getCertificateRequestValue();
262  assertEquals(requestValue.length, expectedBytes.length);
263  for( int j=0; j < expectedBytes.length; j++ ) {
264  assertEquals( requestValue[j], expectedBytes[j]);
265  }
266 
267  String[] attributes = rb.getAttributes();
268  assertEquals(1, attributes.length);
269  assertEquals("Cryptographic Usage Mask: 1", attributes[0]);
270  }
271  }
272 
273  sl.freeLibrary();
274 
275  } catch (Exception e) {
276  // -> we shoud not get here
277  System.out.println(e.toString());
278  assertEquals(0, 1);
279  }
280  }
281 }
void JniCertifyKmip()
Test: Certify and Re-Certify operations.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.