Support for PBMAC1 algorithms#1485
Conversation
|
Did you by any chance make a build and put openjceplus on the top of the order and create a PKCS12 keystore file with keytool command? e.g. by specifying |
|
Since, the need here is for use in keystore. I would like to see some keystore tests that test this functionality. First to make sure this work, but also to make sure the keystores created using our impliementation work when Sun's implementation is used. |
This update adds support for PBMAC1 algorithms. The algorithms are supported for OpenJCEPlus and OpenJCEPlusFIPS provider. The PBMAC1Core class extends the regular HmacCore class overriding engineInit method as PBMAC1 uses PBKDF2 key derivation. PBMAC1 tests have also been added. Signed-off-by: Dev Agarwal <dev.agarwal@ibm.com>
…them as strings within the test, updated readme, some formatting updated to PBMAC1Core class
I am reading P12 files using PKCS12 KeyStore after adding OpenJCEPlus to the top the security provider list. |
It might be fine than. However, sometimes keytool does things a little differently than our code and that causes issues. So, at the bare minimum I think it is best to verify the code using keytool. Even if the test is a one off and not added to our tests. |
| void testPBMACFunctionality(String alg) throws Exception { | ||
| if (getProviderName().equalsIgnoreCase("OpenJCEPlusFIPS") && (alg.equalsIgnoreCase("PBEWithHmacSHA1") || | ||
| alg.equalsIgnoreCase("PBEWithHmacSHA224") || alg.equalsIgnoreCase("PBEWithHmacSHA256"))) { | ||
| return; |
There was a problem hiding this comment.
Instead of returning and assuming that the test was run we instead have been using assume statements. Something like the following would assume we are not using OpenJCEPlusFIPS for example and record it as skipped in Junit. Similar comment to other places where you check for fips provider and excute return.
assumeFalse("OpenJCEPlusFIPS".equals(getProviderName()) && ... .... ... );
| mac.init(key, new PBEParameterSpec(smallSalt, iterationCount)); | ||
| fail("Expected InvalidKeyException not thrown, small salt length"); | ||
| } catch (InvalidKeyException e) { | ||
| assertTrue(true); |
There was a problem hiding this comment.
No reason to assert true. You could however assert that the exception message is as expected in all these locations where we are doing an assertTrue(true);
| private byte[] salt = new byte[20]; | ||
| private int iterationCount = 300000; | ||
|
|
||
| private String p12file1 = "MIIKigIBAzCCCgUGCSqGSIb3DQEHAaCCCfYEggnyMIIJ7jCCBGIGCSqGSIb3DQEH" + |
There was a problem hiding this comment.
Can you please add some comments here as to where these pkcs12 file values were found. I believe that these were found in an RFC as a known answer test? Besides a comment saying where we obtained these values ideally we would add a comment showing the human readable asn1 breakdown of the value so we can easily know what is within these pcks12 files in terms of crypto.
Also my understanding is that these are not really PKCS12 standard files. They are RFC 9579 (and its successor, RFC 9879) format files correct?
There was a problem hiding this comment.
The decoded value is extremely long and on directly copying pasting as text there is no indentation making it hard to read.
can still add it if preferred.
| try { | ||
| ks.load(new ByteArrayInputStream(decodedBytes), "1234".toCharArray()); | ||
| } catch (Exception e) { | ||
| fail(e.getMessage()); |
There was a problem hiding this comment.
No need to strip out all the stack trace information or even to catch the exception. The try catch can be removed and just allow the exception to be thrown in the case of a failure. Similar comment for the rest of the checks being done here.
Maybe the test should also be parameterized such that there is not so much duplicate cod here taking in a pkcs12 file instead?
There was a problem hiding this comment.
Updated.
Now using a helper method and letting the exception get thrown.
| try { | ||
| ks.load(new ByteArrayInputStream(decodedBytes), "1234".toCharArray()); | ||
| } catch (java.io.IOException e) { | ||
| // Expected error (Incorrect iteration count) |
There was a problem hiding this comment.
Should we assert the error message? Seems checking we are are getting a reasonable error message would be better then accepting any IOException that occurs. Similar comment on line 561 and 569.
There was a problem hiding this comment.
WARNING: OpenJCEPlusFIPS is running in developer mode. Non production workload assumed. This environment is not certified for FIPS 140-3: Mac OS X:aarch64
WARNING: OpenJCEPlusFIPS is running in developer mode. Non production workload assumed. This environment is not certified for FIPS 140-3: Mac OS X:aarch64
Integrity check failed: java.security.UnrecoverableKeyException: Failed PKCS12 integrity checking
This is the exception message not sure if asserting the message provides much value.


This update adds support for PBMAC1 algorithms. The algorithms are supported for OpenJCEPlus and OpenJCEPlusFIPS provider. The PBMAC1Core class extends the regular HmacCore class overriding engineInit method as PBMAC1 uses PBKDF2 key derivation.
PBMAC1 tests have also been added.
Signed-off-by: Dev Agarwal dev.agarwal@ibm.com