RFR: 8343232: PKCS#12 KeyStore support for RFC 9879: Use of Password-Based Message Authentication Code 1 (PBMAC1) [v3]
Weijun Wang
weijun at openjdk.org
Mon Sep 22 20:44:18 UTC 2025
On Thu, 18 Sep 2025 17:44:07 GMT, Mark Powers <mpowers at openjdk.org> wrote:
>> src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java line 1490:
>>
>>> 1488:
>>> 1489: if (macAlgorithm.equals("PBMAC1") ||
>>> 1490: defaultMacAlgorithm().startsWith("PBEWith")) {
>>
>> `calculateMac` is called when keystore is read from an existing file and `defaultMacAlgorithm` should not be used. Otherwise, algorithm will be modified. Try these:
>>
>> keytool -keystore ks -keyalg ec -storepass changeit -genkeypair -alias a -dname CN=a -J-Dkeystore.pkcs12.macAlgorithm=PBEWithHmacSHA512
>> keytool -keystore ks -keyalg ec -storepass changeit -genkeypair -alias b -dname CN=b -J-Dkeystore.pkcs12.macAlgorithm=PBEWithHmacSHA256
>
> If the keystore.pkcs12.macAlgorithm security property starts with PBE then shouldn't an old MAC protected keystore be written with PBMAC1 protection?
>
> I tried those two commands and they work as expected. I did fix a few problems in the last two days so maybe I need to push those changes.
No, `keystore.pkcs12.macAlgorithm` should only be used when a new keystore is created. In this example, the keystore is created in the first command, and the system property provided in the second command should be ignored. This means `defaultMacAlgorithm` should only be called on line 1248 when `macAlgorithm` is null.
*Update*: since you've already removed `macAlgorithm.equals("PBMAC1")`, `kdfHmac` can be read from `macAlgorithm` now. Same at lines 1947-1953.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24429#discussion_r2370251718
More information about the security-dev
mailing list