1 package com.p6r.kmipserverlib;
5 import java.math.BigInteger;
6 import java.nio.charset.Charset;
7 import java.text.DateFormat;
8 import java.text.SimpleDateFormat;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
28 System.out.println(
"@BeforeClass - oneTimeSetUp");
34 System.out.println(
"@AfterClass - oneTimeTearDown");
40 System.out.println(
"@Before - setUp");
46 System.out.println(
"@After - tearDown");
56 System.out.println(
"@Test - JNICall-RegisterTransparentRSAKeyKMIP");
58 byte[] batchId0 = {0x01, 0x02, 0x03, 0x04};
59 byte[] batchId1 = {0x51, 0x52, 0x53, 0x54};
60 byte[] batchId2 = {0x71, 0x72, 0x73, 0x74};
62 byte[] N_value = { (byte)0x9b,(byte)0xcc,(byte)0xc7,(byte)0x73,(byte)0x38,(byte)0x70,(byte)0x5d,(byte)0xe3,(byte)0x0f,(byte)0xae,(byte)0x34,(byte)0x3f,(byte)0xd0,(byte)0x2f,(byte)0x8f,(byte)0x94,(byte)0xec,(byte)0x46,(byte)0x57,(byte)0xa8,(byte)0xc2,(byte)0x4a,(byte)0x0e,(byte)0x56,(byte)0x10,(byte)0x3b,(byte)0xc4,
63 (byte)0x5d,(byte)0xb6,(byte)0xd7,(byte)0x40,(byte)0x86,(byte)0x8b,(byte)0x9a,(byte)0xc3,
64 (byte)0xfb,(byte)0xcc,(byte)0x0e,(byte)0xba,(byte)0xc6,(byte)0xe1,(byte)0xe8,(byte)0xa9,(byte)0x54,(byte)0xa8,(byte)0x50,(byte)0x50,(byte)0xd6,(byte)0xaa,(byte)0xe7,(byte)0x60,(byte)0x09,(byte)0x34,(byte)0xb8,(byte)0xeb,(byte)0xe8,(byte)0xb0,(byte)0x3d,(byte)0xb6,(byte)0xba,(byte)0x08,(byte)0x84,(byte)0xb1,(byte)0xae,(byte)0xe6,(byte)0x9e,(byte)0x4f,(byte)0xc3,(byte)0xa1,(byte)0xbd,
65 (byte)0x11,(byte)0xfc,(byte)0xbf,(byte)0xef,(byte)0x68,(byte)0xde,(byte)0x0b,(byte)0xaa,(byte)0x88,(byte)0x8d,(byte)0x1f,(byte)0x5c,(byte)0xbc,(byte)0xa2,(byte)0xd8,(byte)0x1a,(byte)0x31,(byte)0x68,(byte)0xb2,(byte)0xa9,(byte)0x01,(byte)0xe9,(byte)0xf8,(byte)0x4d,(byte)0x38,(byte)0x54,(byte)0xee,(byte)0x10,(byte)0xaa,(byte)0x72,(byte)0x35,(byte)0xdf,(byte)0xef,(byte)0x06,(byte)0x84,
66 (byte)0xf5,(byte)0x8d,(byte)0x98,(byte)0x87,(byte)0x9c,(byte)0x93,(byte)0x63,(byte)0x72,(byte)0x43,(byte)0x5f,(byte)0x2c,(byte)0xb1,(byte)0x02,(byte)0x78,(byte)0x2d,(byte)0x38,(byte)0x84,(byte)0xf9,(byte)0xab,(byte)0xb8,(byte)0x18,(byte)0x81,(byte)0x7d };
70 P6KMIPServerLib sl =
new P6KMIPServerLib();
73 String testMessage =
"<RequestMessage><RequestHeader><ProtocolVersion><ProtocolVersionMajor type=\"Integer\" value=\"1\"/><ProtocolVersionMinor type=\"Integer\" value=\"3\"/></ProtocolVersion><TimeStamp type=\"DateTime\" value=\"2018-03-03T18:10:58Z\"/><BatchCount type=\"Integer\" value=\"3\"/></RequestHeader><BatchItem><Operation type=\"Enumeration\" value=\"Register\"/><UniqueBatchItemID type=\"ByteString\" value=\"01020304\"/><RequestPayload><ObjectType type=\"Enumeration\" value=\"SymmetricKey\"/><SymmetricKey><KeyBlock><KeyFormatType type=\"Enumeration\" value=\"TransparentSymmetricKey\"/><KeyValue><KeyMaterial><Key type=\"ByteString\" value=\"7F0102030405060708090A0B0C0D0E0F\"/></KeyMaterial></KeyValue><CryptographicAlgorithm type=\"Enumeration\" value=\"AES\"/><CryptographicLength type=\"Integer\" value=\"128\"/></KeyBlock></SymmetricKey></RequestPayload></BatchItem><BatchItem><Operation type=\"Enumeration\" value=\"Register\"/><UniqueBatchItemID type=\"ByteString\" value=\"51525354\"/><RequestPayload><ObjectType type=\"Enumeration\" value=\"PrivateKey\"/><UniqueIdentifier type=\"TextString\" value=\"AAAA-BBBB-CCCC-4444-5555\"/><PrivateKey><KeyBlock><KeyFormatType type=\"Enumeration\" value=\"TransparentRSAPrivateKey\"/><KeyValue><KeyMaterial><Modulus type=\"BigInteger\" value=\"9BCCC77338705DE30FAE343FD02F8F94EC4657A8C24A0E56103BC45DB6D740868B9AC3FBCC0EBAC6E1E8A954A85050D6AAE7600934B8EBE8B03DB6BA0884B1AEE69E4FC3A1BD11FCBFEF68DE0BAA888D1F5CBCA2D81A3168B2A901E9F84D3854EE10AA7235DFEF0684F58D98879C936372435F2CB102782D3884F9ABB818817D\"/><PrivateExponent type=\"BigInteger\" value=\"663FD00A23594394D85EA8F5D468D25F976D56EC6F8E70B834F1349F9876CE673EC9F4A3953979853B1019C970A93D5495574264E85010AB66B729EC0FD91E4EB2ADB3C7DB9C45335AF14AE697D11F4C9EFAF12C201011541BE7416DAB856F7E65939F1EB6746D2916106717C870A0A260B5240C9A432C5E194C16B5E9E23541\"/><PublicExponent type=\"BigInteger\" value=\"0000000000010001\"/><P type=\"BigInteger\" value=\"F3F5B19EDF657AAA4DC25167C69A725117C7F8EC7B77AB2B18E07B051D520470771661CCB7156575F61A1665210FD86A4277331B1B50F822BC51FA8D2334FF6D\"/><Q type=\"BigInteger\" value=\"A37D3B2BC4AB29ED59DBC6DDFA7F9104E51791E7E91B2689B505F60DA6851F1EFEF7D3D1BD2011C433B0287F309329FBC490582C9DE0EEFEF23FD74256647051\"/><PrimeExponentP type=\"BigInteger\" value=\"33C794399A44D9B247EAD4886838E3C69E7B8D33F448C405D3B3E1A8863EA03E96A8237DE5E61EB0D8D954A3864EECAA310D47C59B18A67208F285716B659649\"/><PrimeExponentQ type=\"BigInteger\" value=\"983BC73A553250A33BD6235295ABED7C925A2539BE5CD2C0CDB8544A97B143AE581AAAB99592E4183F4D1C187B41BD893B9A7110729E7DCD16040E4C2E27EE51\"/><CRTCoefficient type=\"BigInteger\" value=\"548AD39760B4F5FABCD6D5E7BBDCBF7954F9F32256FBA159D6B138C4FB3AD9FF078041F53AF2C6AAD9B8847279FEB576B4F016C3F39DAFE4B817ED4F09E95DA1\"/></KeyMaterial></KeyValue><CryptographicAlgorithm type=\"Enumeration\" value=\"RSA\"/><CryptographicLength type=\"Integer\" value=\"1024\"/></KeyBlock></PrivateKey></RequestPayload></BatchItem><BatchItem><Operation type=\"Enumeration\" value=\"Register\"/><UniqueBatchItemID type=\"ByteString\" value=\"71727374\"/><RequestPayload><ObjectType type=\"Enumeration\" value=\"PublicKey\"/><PublicKey><KeyBlock><KeyFormatType type=\"Enumeration\" value=\"TransparentRSAPublicKey\"/><KeyValue><KeyMaterial><Modulus type=\"BigInteger\" value=\"9BCCC77338705DE30FAE343FD02F8F94EC4657A8C24A0E56103BC45DB6D740868B9AC3FBCC0EBAC6E1E8A954A85050D6AAE7600934B8EBE8B03DB6BA0884B1AEE69E4FC3A1BD11FCBFEF68DE0BAA888D1F5CBCA2D81A3168B2A901E9F84D3854EE10AA7235DFEF0684F58D98879C936372435F2CB102782D3884F9ABB818817D\"/><PublicExponent type=\"BigInteger\" value=\"0000000000010001\"/></KeyMaterial></KeyValue><CryptographicAlgorithm type=\"Enumeration\" value=\"RSA\"/><CryptographicLength type=\"Integer\" value=\"1024\"/></KeyBlock></PublicKey></RequestPayload></BatchItem></RequestMessage>";
76 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
78 String libVersion = sl.getLibraryVersion();
79 System.out.println(libVersion);
83 sl.setMessageBuffer(testMessage.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
86 RequestHeader rh = sl.getRequestHeader();
87 assertEquals(
"1.3", rh.getProtocolVersion());
89 DateFormat dateFormat =
new SimpleDateFormat(
"yyyy-mm-dd hh:mm:ssZ");
90 Date msgTime = rh.getTimeStamp();
91 String strDate = dateFormat.format(msgTime);
92 System.out.println(
"Time of message request: " + strDate);
96 for (
int i = 0; i < rh.getBatchCount(); i++) {
98 BatchItem bi = sl.getBatchItem(i + 1);
99 if (bi instanceof RegisterTransparentRSAPrivateKeyBatchItem) {
100 RegisterTransparentRSAPrivateKeyBatchItem RSAprivate = (RegisterTransparentRSAPrivateKeyBatchItem) bi;
102 byte[] batchId = RSAprivate.getUniqueBatchId();
103 assertEquals(4, batchId.length);
104 for(
int j=0; j < batchId.length; j++ ) {
105 assertEquals(batchId1[j], batchId[j]);
108 BigInteger Modulus = RSAprivate.getModulus();
109 byte[] modBytes = Modulus.toByteArray();
110 assertEquals(N_value.length, modBytes.length);
111 for(
int j=0; j < N_value.length; j++ ) {
112 assertEquals(N_value[j], modBytes[j]);
116 else if (bi instanceof RegisterTransparentRSAPublicKeyBatchItem) {
117 RegisterTransparentRSAPublicKeyBatchItem RSApublic = (RegisterTransparentRSAPublicKeyBatchItem) bi;
119 byte[] batchId = RSApublic.getUniqueBatchId();
120 assertEquals(4, batchId.length);
121 for(
int j=0; j < batchId.length; j++ ) {
122 assertEquals(batchId2[j], batchId[j]);
125 BigInteger Modulus = RSApublic.getModulus();
126 byte[] modBytes = Modulus.toByteArray();
127 assertEquals(N_value.length, modBytes.length);
128 for(
int j=0; j < N_value.length; j++ ) {
129 assertEquals(N_value[j], modBytes[j]);
133 else if (bi instanceof RegisterTransparentSymmetricKeyBatchItem) {
134 RegisterTransparentSymmetricKeyBatchItem symm = (RegisterTransparentSymmetricKeyBatchItem) bi;
136 byte[] batchId = symm.getUniqueBatchId();
137 assertEquals(4, batchId.length);
138 for(
int j=0; j < batchId.length; j++ ) {
139 assertEquals(batchId0[j], batchId[j]);
145 }
catch (Exception e) {
147 System.out.println(e.toString());
static void oneTimeTearDown()
void JNICall_RegisterTransparentRSAKeyKMIP()
Test: Verify parser can handle an XML formated Register Split Key operation.
static void oneTimeSetUp()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.