1 package com.p6r.kmipserverlib;
5 import java.text.DateFormat;
6 import java.text.SimpleDateFormat;
8 import java.util.TimeZone;
10 import static org.junit.Assert.assertEquals;
26 System.out.println(
"@BeforeClass - oneTimeSetUp");
32 System.out.println(
"@AfterClass - oneTimeTearDown");
38 System.out.println(
"@Before - setUp");
44 System.out.println(
"@After - tearDown");
54 System.out.println(
"@Test - JNICall-Respnse3KMIP");
58 P6KMIPServerLib sl =
new P6KMIPServerLib();
61 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
64 sl.startResponseMessage(6, KMIPConstants.FORMAT_TTLV, 1);
66 byte[] batchId1 = {0x01, 0x02, 0x03, 0x04};
67 byte[] batchId2 = {(byte) 0xFF, (byte) 0xFB, (byte) 0xFC, (byte) 0xFD};
68 byte[] batchId3 = { 0x07, 0x09 };
69 byte[] batchId4 = { 0x15 };
70 byte[] batchId5 = { 0x00, 0x00, 0x00, 0x20 };
71 byte[] batchId6 = { 0x11, 0x07, 0x00, 0x20 };
73 String[] attributeNames =
new String[5];
74 attributeNames[0] =
new String(
"Cryptographic Usage Mask");
75 attributeNames[1] =
new String(
"Cryptographic Algorithm");
76 attributeNames[2] =
new String(
"Cryptographic Length");
77 attributeNames[3] =
new String(
"y-ServerSpecific1");
78 attributeNames[4] =
new String(
"Digest");
80 GetAttributeListResponse gal =
new GetAttributeListResponse(batchId1,
"1111-2222-3333-4444-5555", attributeNames);
83 String[] locatedObjects =
new String[3];
84 locatedObjects[0] =
new String(
"aaa-bbb-ccc-ddd-eee-fff");
85 locatedObjects[1] =
new String(
"1111-222-7777-3333-9696969");
86 locatedObjects[2] =
new String(
"aklfakjakieiei-oioioioioi");
87 LocateResponse lr =
new LocateResponse(batchId2, locatedObjects);
91 LocateResponse lr2 =
new LocateResponse(batchId6, null);
94 String[] versions =
new String[3];
98 VersionResponse vr =
new VersionResponse(batchId3, versions);
101 CheckResponse cr =
new CheckResponse(batchId4,
"UID-3939393939", (KMIPConstants.USAGE_MASK_DECRYPT | KMIPConstants.USAGE_MASK_ENCRYPT),
new Integer(300));
104 int[] operations =
new int[5];
105 operations[0] = KMIPConstants.OP_CREATE;
106 operations[1] = KMIPConstants.OP_REGISTER;
107 operations[2] = KMIPConstants.OP_REKEY;
108 operations[3] = KMIPConstants.OP_LOCATE;
109 operations[4] = KMIPConstants.OP_GET;
111 int[] objectTypes =
new int[5];
112 objectTypes[0] = KMIPConstants.OBJECT_CERTIFICATE;
113 objectTypes[1] = KMIPConstants.OBJECT_SYMMETRICKEY;
114 objectTypes[2] = KMIPConstants.OBJECT_SECRETDATA;
115 objectTypes[3] = KMIPConstants.OBJECT_SPLITKEY;
116 objectTypes[4] = KMIPConstants.OBJECT_OPAQUE;
118 RNGParameters[] RNGs =
new RNGParameters[2];
119 RNGs[0] =
new RNGParameters(KMIPConstants.RNGALG_FIPS186_2, KMIPConstants.ALG_AES, 256, KMIPConstants.HASH_SHA256, -1, -1, KMIPConstants.FIPS186_GPXCHANGENOTICE, 1 );
120 RNGs[1] =
new RNGParameters(KMIPConstants.RNGALG_UNSPECIFIED, -1, -1, -1, -1, -1, -1, -1 );
122 CapabilityInformation[] Caps =
new CapabilityInformation[2];
123 Caps[0] =
new CapabilityInformation(-1, 1, 2, 1, 1, KMIPConstants.UNWRAPMODE_PROCESSED, KMIPConstants.ONDESTROY_METADATA_SHREDDED, KMIPConstants.SHREDALG_UNSUPPORTED, KMIPConstants.RNGMODE_SHARED);
124 Caps[1] =
new CapabilityInformation(1, 1, 1, KMIPConstants.UNWRAPMODE_PROCESSED, KMIPConstants.ONDESTROY_METADATA_SHREDDED, KMIPConstants.SHREDALG_CRYPTOGRAPHIC, KMIPConstants.RNGMODE_SHARED);
126 ProfileInformation[] profiles =
new ProfileInformation[4];
127 profiles[0] =
new ProfileInformation(ProfileConstants.PN_28_SERVER_V12 );
128 profiles[1] =
new ProfileInformation(ProfileConstants.PN_5_SERVER_V12,
"/kmip/abc", 6423);
129 profiles[2] =
new ProfileInformation(ProfileConstants.PN_10_SERVER_V10, null, 7834);
130 profiles[3] =
new ProfileInformation(ProfileConstants.PN_40_SERVER_V10,
"/kmip2", -1);
132 String[] profileNames =
new String[2];
133 profileNames[0] =
new String(
"Profile1");
134 profileNames[1] =
new String(
"Profile2");
135 ValidationInformation[] validations =
new ValidationInformation[2];
136 validations[0] =
new ValidationInformation(KMIPConstants.VALAUTH_NISTCMVP, 2, KMIPConstants.VALTYPE_HYBRID, 3 );
137 validations[1] =
new ValidationInformation(KMIPConstants.VALAUTH_UNSPECIFIED,
"US",
"http://us.export.gov/v", 2, 0, KMIPConstants.VALTYPE_SOFTWARE, 1,
"ABCD13874",
"http://us.export.gov/certs",
"https://www.p6r.com/val1", profileNames );
139 ExtensionInformation[] extensions =
new ExtensionInformation[4];
140 extensions[0] =
new ExtensionInformation(
"Extension1");
141 extensions[1] =
new ExtensionInformation(
"Extension2", 0x80000010, KMIPConstants.TYPE_BIGINTEGER );
142 extensions[2] =
new ExtensionInformation(
"Extension3", 0x80000001, -1);
143 extensions[3] =
new ExtensionInformation(
"Extension4", -1, KMIPConstants.TYPE_ENUMERATION);
145 String[] namespaces =
new String[2];
146 namespaces[0] =
new String(
"Namespace 1");
147 namespaces[1] =
new String(
"Namespace 2");
149 int[] attestationTypes =
new int[2];
150 attestationTypes[0] = KMIPConstants.ATTEST_SAML_ASSERTION;
151 attestationTypes[1] = KMIPConstants.ATTEST_TPM_QUOTE;
158 byte[] fakeServerInfo = { (byte)0x80, 0x01, 0x02, 0x08, 0x00, 0x00, 0x00, 0x04, (byte)0xFF, (byte)0xFE, (byte)0xFD, (byte)0xFE, 0x00, 0x00, 0x00, 0x00 };
159 QueryResponse qr =
new QueryResponse(batchId5, operations, objectTypes,
"Project6Research, Inc", fakeServerInfo, null );
160 qr.setRNGParameters(RNGs);
161 qr.setCapabilities(Caps);
162 qr.setProfiles(profiles);
163 qr.setValidations(validations);
164 qr.setExtensions(extensions);
165 qr.setAppNamespace(namespaces);
166 qr.setAttestation(attestationTypes);
169 byte[] responseBuffer = sl.endResponseMessage(0);
170 for (
int j = 0; j < responseBuffer.length; j++) {
171 System.out.print(responseBuffer[j]);
173 System.out.println(
"\n");
177 sl.startResponseMessage(6, KMIPConstants.FORMAT_MSGXML, 4);
179 sl.addBatchItem(gal);
181 sl.addBatchItem(lr2);
186 byte[] responseBuffer2 = sl.endResponseMessage(0);
187 System.out.println(
new String(responseBuffer2));
188 System.out.println(
"\n");
192 sl.startResponseMessage(6, KMIPConstants.FORMAT_MSGJSON, 4);
194 sl.addBatchItem(gal);
196 sl.addBatchItem(lr2);
201 byte[] responseBuffer3 = sl.endResponseMessage(0);
202 System.out.println(
new String(responseBuffer3));
203 System.out.println(
"\n");
208 }
catch (Exception e) {
210 System.out.println(e.toString());
static void oneTimeSetUp()
static void oneTimeTearDown()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
void JNICall_Response3KMIP()
Test: Generate a message with multiple batch items.