|
1 | 1 | /* |
2 | | - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
31 | 31 | * its usages, please look through the README. |
32 | 32 | * |
33 | 33 | * @library /test/lib ../warnings |
34 | | - * @compile -source 1.7 -target 1.7 JdkUtils.java |
| 34 | + * @compile -source 1.8 -target 1.8 JdkUtils.java |
35 | 35 | * @run main/manual/othervm Compatibility |
36 | 36 | */ |
37 | 37 |
|
|
67 | 67 | import java.util.stream.Collectors; |
68 | 68 | import java.util.stream.IntStream; |
69 | 69 |
|
70 | | -import jdk.test.lib.Platform; |
71 | 70 | import jdk.test.lib.process.OutputAnalyzer; |
72 | 71 | import jdk.test.lib.process.ProcessTools; |
73 | 72 | import jdk.test.lib.util.JarUtils; |
@@ -460,7 +459,7 @@ private static int[] keySizes(String keyAlgorithm) throws IOException { |
460 | 459 | if (RSA.equals(keyAlgorithm) || DSA.equals(keyAlgorithm)) { |
461 | 460 | return new int[] { 1024, 2048, 0 }; // 0 is no keysize specified |
462 | 461 | } else if (EC.equals(keyAlgorithm)) { |
463 | | - return new int[] { 384, 571, 0 }; // 0 is no keysize specified |
| 462 | + return new int[] { 384, 521, 0 }; // 0 is no keysize specified |
464 | 463 | } else { |
465 | 464 | throw new RuntimeException("problem determining key sizes"); |
466 | 465 | } |
@@ -717,7 +716,7 @@ private static void verifying(SignItem signItem, VerifyItem verifyItem) |
717 | 716 | try { |
718 | 717 | String match = "^ (" |
719 | 718 | + " Signature algorithm: " + signItem.certInfo. |
720 | | - expectedSigalg() + ", " + signItem.certInfo. |
| 719 | + expectedSigalg(signItem) + ", " + signItem.certInfo. |
721 | 720 | expectedKeySize() + "-bit key" |
722 | 721 | + ")|(" |
723 | 722 | + " Digest algorithm: " + signItem.expectedDigestAlg() |
@@ -845,6 +844,7 @@ private static Status verifyingStatus(SignItem signItem, VerifyItem |
845 | 844 |
|
846 | 845 | if (isWeakAlg(signItem.expectedDigestAlg()) |
847 | 846 | && line.contains(Test.WEAK_ALGORITHM_WARNING)) continue; |
| 847 | + if (line.contains(Test.WEAK_KEY_WARNING)) continue; |
848 | 848 | if (Test.CERTIFICATE_SELF_SIGNED.equals(line)) continue; |
849 | 849 | if (Test.HAS_EXPIRED_CERT_VERIFYING_WARNING.equals(line) |
850 | 850 | && signItem.certInfo.expired) continue; |
@@ -1183,19 +1183,56 @@ private String sigalg() { |
1183 | 1183 | } |
1184 | 1184 |
|
1185 | 1185 | private String expectedSigalg() { |
1186 | | - return (DEFAULT.equals(this.digestAlgorithm) ? this.digestAlgorithm |
1187 | | - : "SHA-256").replace("-", "") + "with" + |
1188 | | - keyAlgorithm + (EC.equals(keyAlgorithm) ? "DSA" : ""); |
| 1186 | + return "SHA256with" + keyAlgorithm + (EC.equals(keyAlgorithm) ? "DSA" : ""); |
| 1187 | + } |
| 1188 | + |
| 1189 | + private String expectedSigalg(SignItem signer) { |
| 1190 | + if (!DEFAULT.equals(digestAlgorithm)) { |
| 1191 | + return "SHA256with" + keyAlgorithm + (EC.equals(keyAlgorithm) ? "DSA" : ""); |
| 1192 | + |
| 1193 | + } else { |
| 1194 | + // default algorithms documented for jarsigner here: |
| 1195 | + // https://docs.oracle.com/en/java/javase/17/docs/specs/man/jarsigner.html#supported-algorithms |
| 1196 | + // https://docs.oracle.com/en/java/javase/20/docs/specs/man/jarsigner.html#supported-algorithms |
| 1197 | + int expectedKeySize = expectedKeySize(); |
| 1198 | + switch (keyAlgorithm) { |
| 1199 | + case DSA: |
| 1200 | + return "SHA256withDSA"; |
| 1201 | + case RSA: { |
| 1202 | + if ((signer.jdkInfo.majorVersion >= 20 && expectedKeySize < 624) |
| 1203 | + || (signer.jdkInfo.majorVersion < 20 && expectedKeySize <= 3072)) { |
| 1204 | + return "SHA256withRSA"; |
| 1205 | + } else if (expectedKeySize <= 7680) { |
| 1206 | + return "SHA384withRSA"; |
| 1207 | + } else { |
| 1208 | + return "SHA512withRSA"; |
| 1209 | + } |
| 1210 | + } |
| 1211 | + case EC: { |
| 1212 | + if (signer.jdkInfo.majorVersion < 20 && expectedKeySize < 384) { |
| 1213 | + return "SHA256withECDSA"; |
| 1214 | + } else if (expectedKeySize < 512) { |
| 1215 | + return "SHA384withECDSA"; |
| 1216 | + } else { |
| 1217 | + return "SHA512withECDSA"; |
| 1218 | + } |
| 1219 | + } |
| 1220 | + default: |
| 1221 | + throw new RuntimeException("Unsupported/expected key algorithm: " + keyAlgorithm); |
| 1222 | + } |
| 1223 | + } |
1189 | 1224 | } |
1190 | 1225 |
|
1191 | 1226 | private int expectedKeySize() { |
1192 | 1227 | if (keySize != 0) return keySize; |
1193 | 1228 |
|
1194 | 1229 | // defaults |
1195 | | - if (RSA.equals(keyAlgorithm) || DSA.equals(keyAlgorithm)) { |
| 1230 | + if (RSA.equals(keyAlgorithm)) { |
| 1231 | + return jdkInfo.majorVersion >= 20 ? 3072 : 2048; |
| 1232 | + } else if (DSA.equals(keyAlgorithm)) { |
1196 | 1233 | return 2048; |
1197 | 1234 | } else if (EC.equals(keyAlgorithm)) { |
1198 | | - return 256; |
| 1235 | + return jdkInfo.majorVersion >= 20 ? 384 : 256; |
1199 | 1236 | } else { |
1200 | 1237 | throw new RuntimeException("problem determining key size"); |
1201 | 1238 | } |
@@ -1391,7 +1428,9 @@ private SignItem digestAlgorithm(String digestAlgorithm) { |
1391 | 1428 | } |
1392 | 1429 |
|
1393 | 1430 | String expectedDigestAlg() { |
1394 | | - return digestAlgorithm != null ? digestAlgorithm : "SHA-256"; |
| 1431 | + return digestAlgorithm != null |
| 1432 | + ? digestAlgorithm |
| 1433 | + : jdkInfo.majorVersion >= 20 ? "SHA-384" : "SHA-256"; |
1395 | 1434 | } |
1396 | 1435 |
|
1397 | 1436 | private SignItem tsaDigestAlgorithm(String tsaDigestAlgorithm) { |
@@ -1540,7 +1579,7 @@ private static String reportRow(SignItem signItem, VerifyItem verifyItem) { |
1540 | 1579 | s_values_add.accept(i -> i.unsignedJar + " -> " + i.signedJar); |
1541 | 1580 | s_values_add.accept(i -> i.certInfo.toString()); |
1542 | 1581 | s_values_add.accept(i -> i.jdkInfo.version); |
1543 | | - s_values_add.accept(i -> i.certInfo.expectedSigalg()); |
| 1582 | + s_values_add.accept(i -> i.certInfo.expectedSigalg(i)); |
1544 | 1583 | s_values_add.accept(i -> |
1545 | 1584 | null2Default(i.digestAlgorithm, i.expectedDigestAlg())); |
1546 | 1585 | s_values_add.accept(i -> i.tsaIndex == -1 ? "" : |
|
0 commit comments