Skip to content

Commit b00b70c

Browse files
author
Hai-May Chao
committed
8286907: keytool should warn about weak PBE algorithms
Reviewed-by: mullan, weijun
1 parent ee0f5b5 commit b00b70c

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/java.base/share/classes/sun/security/tools/keytool/Main.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1837,6 +1837,11 @@ private void doGenSecretKey(String alias, String keyAlgName,
18371837
useDefaultPBEAlgorithm = false;
18381838
}
18391839

1840+
SecretKeyConstraintsParameters skcp =
1841+
new SecretKeyConstraintsParameters(secKey);
1842+
checkWeakConstraint(rb.getString("the.generated.secretkey"),
1843+
keyAlgName, skcp);
1844+
18401845
if (verbose) {
18411846
MessageFormat form = new MessageFormat(rb.getString(
18421847
"Generated.keyAlgName.secret.key"));
@@ -5068,6 +5073,16 @@ private void checkWeakConstraint(String label, CRL crl, Key key,
50685073
}
50695074
}
50705075

5076+
private void checkWeakConstraint(String label, String keyAlg,
5077+
SecretKeyConstraintsParameters skcp) {
5078+
try {
5079+
LEGACY_CHECK.permits(keyAlg, skcp, false);
5080+
} catch (CertPathValidatorException e) {
5081+
weakWarnings.add(String.format(
5082+
rb.getString("key.algorithm.weak"), label, keyAlg));
5083+
}
5084+
}
5085+
50715086
private void checkWeak(String label, CRL crl, Key key) {
50725087
if (crl instanceof X509CRLImpl impl) {
50735088
checkWeak(label, impl.getSigAlgName(), key);

test/jdk/sun/security/tools/keytool/WeakSecretKeyTest.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8255552 8286090
26+
* @bug 8255552 8286090 8286907
2727
* @summary Test keytool commands associated with secret key entries which use weak algorithms
2828
* @library /test/lib
2929
*/
@@ -108,5 +108,24 @@ public static void main(String[] args) throws Exception {
108108
.shouldContain("Warning")
109109
.shouldMatch("The generated secret key uses a 128-bit AES key.*considered a security risk")
110110
.shouldHaveExitValue(0);
111+
112+
SecurityTools.keytool("-keystore ks.p12 -storepass changeit " +
113+
"-genseckey -keyalg PBEWithMD5AndDES -alias pbekey1")
114+
.shouldContain("Warning")
115+
.shouldMatch("The generated secret key uses the PBEWithMD5AndDES algorithm.*considered a security risk")
116+
.shouldHaveExitValue(0);
117+
118+
SecurityTools.keytool("-keystore ks.p12 -storepass changeit " +
119+
"-genseckey -keyalg PBEWithSHA1AndDESede -alias pbekey2")
120+
.shouldContain("Warning")
121+
.shouldMatch("The generated secret key uses the PBEWithSHA1AndDESede algorithm.*considered a security risk")
122+
.shouldHaveExitValue(0);
123+
124+
SecurityTools.setResponse("changeit", "changeit");
125+
SecurityTools.keytool("-keystore ks.p12 -storepass changeit " +
126+
"-importpass -keyalg PBEWithMD5AndDES -alias newentry")
127+
.shouldContain("Warning")
128+
.shouldMatch("The generated secret key uses the PBEWithMD5AndDES algorithm.*considered a security risk")
129+
.shouldHaveExitValue(0);
111130
}
112131
}

0 commit comments

Comments
 (0)