8185934: keytool shows "Signature algorithm: SHA1withECDSA, -1-bit key"
authorweijun
Tue, 08 Aug 2017 21:37:38 +0800
changeset 46139 5196af754957
parent 46138 5982afcbf9dc
child 46140 3abb2959292f
child 46882 e9cb1640cbd6
8185934: keytool shows "Signature algorithm: SHA1withECDSA, -1-bit key" Reviewed-by: mullan
jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java
jdk/src/java.base/share/classes/sun/security/tools/keytool/Resources.java
jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java
jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java
--- a/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java	Tue Aug 08 12:32:41 2017 +0100
+++ b/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java	Tue Aug 08 21:37:38 2017 +0800
@@ -3071,8 +3071,14 @@
 
     private String withWeak(PublicKey key) {
         if (DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, key)) {
-            return String.format(rb.getString("key.bit"),
-                    KeyUtil.getKeySize(key), key.getAlgorithm());
+            int kLen = KeyUtil.getKeySize(key);
+            if (kLen >= 0) {
+                return String.format(rb.getString("key.bit"),
+                        kLen, key.getAlgorithm());
+            } else {
+                return String.format(
+                        rb.getString("unknown.size.1"), key.getAlgorithm());
+            }
         } else {
             return String.format(rb.getString("key.bit.weak"),
                     KeyUtil.getKeySize(key), key.getAlgorithm());
--- a/jdk/src/java.base/share/classes/sun/security/tools/keytool/Resources.java	Tue Aug 08 12:32:41 2017 +0100
+++ b/jdk/src/java.base/share/classes/sun/security/tools/keytool/Resources.java	Tue Aug 08 21:37:38 2017 +0800
@@ -462,6 +462,7 @@
         {"with.weak", "%s (weak)"},
         {"key.bit", "%d-bit %s key"},
         {"key.bit.weak", "%d-bit %s key (weak)"},
+        {"unknown.size.1", "unknown size %s key"},
         {".PATTERN.printX509Cert.with.weak",
                 "Owner: {0}\nIssuer: {1}\nSerial number: {2}\nValid from: {3} until: {4}\nCertificate fingerprints:\n\t SHA1: {5}\n\t SHA256: {6}\nSignature algorithm name: {7}\nSubject Public Key Algorithm: {8}\nVersion: {9}"},
         {"PKCS.10.with.weak",
--- a/jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java	Tue Aug 08 12:32:41 2017 +0100
+++ b/jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java	Tue Aug 08 21:37:38 2017 +0800
@@ -1088,8 +1088,12 @@
 
     private String withWeak(PublicKey key) {
         if (DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, key)) {
-            return String.format(
-                    rb.getString("key.bit"), KeyUtil.getKeySize(key));
+            int kLen = KeyUtil.getKeySize(key);
+            if (kLen >= 0) {
+                return String.format(rb.getString("key.bit"), kLen);
+            } else {
+                return rb.getString("unknown.size");
+            }
         } else {
             seeWeak = true;
             return String.format(
--- a/jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java	Tue Aug 08 12:32:41 2017 +0100
+++ b/jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java	Tue Aug 08 21:37:38 2017 +0800
@@ -164,6 +164,7 @@
         {"with.weak", "%s (weak)"},
         {"key.bit", "%d-bit key"},
         {"key.bit.weak", "%d-bit key (weak)"},
+        {"unknown.size", "unknown size"},
 
         {"jarsigner.", "jarsigner: "},
         {"signature.filename.must.consist.of.the.following.characters.A.Z.0.9.or.",