Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,17 @@ private byte[] getSalt()
*/
private AlgorithmParameters getPBEAlgorithmParameters(
String algorithm, int iterationCount) throws IOException {
AlgorithmParameters algParams = null;
AlgorithmParameters algParams;

byte[] salt = getSalt();
if (KnownOIDs.findMatch(algorithm) == KnownOIDs.PBEWithMD5AndDES) {
// PBES1 scheme such as PBEWithMD5AndDES requires a 8-byte salt
salt = Arrays.copyOf(salt, 8);
}

// create PBE parameters from salt and iteration count
PBEParameterSpec paramSpec =
new PBEParameterSpec(getSalt(), iterationCount);
new PBEParameterSpec(salt, iterationCount);
try {
algParams = AlgorithmParameters.getInstance(algorithm);
algParams.init(paramSpec);
Expand Down
11 changes: 10 additions & 1 deletion test/jdk/sun/security/pkcs12/ParamsPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

/*
* @test
* @bug 8076190 8242151 8153005
* @bug 8076190 8242151 8153005 8266293
* @library /test/lib
* @modules java.base/sun.security.pkcs
* java.base/sun.security.util
Expand Down Expand Up @@ -193,6 +193,15 @@ public static final void main(String[] args) throws Exception {
PBES2, HmacSHA256, AES_256$CBC$NoPadding, 10000,
PBEWithSHA1AndRC4_40, 10000,
SHA_256, 10000);

// 8266293
test(c++,
Map.of("keystore.pkcs12.keyProtectionAlgorithm", "PBEWithMD5AndDES",
"keystore.pkcs12.certProtectionAlgorithm", "PBEWithMD5AndDES"),
Map.of(),
PBEWithMD5AndDES, 10000,
PBEWithMD5AndDES, 10000,
SHA_256, 10000);
}

/**
Expand Down