Blame SOURCES/pki-core-omit-parameter-field-from-ECDSA-certs-Alg-IDs.patch

2555cf
commit ee6b7ede62f62c6ea4da7fbb88176762a0c1cbc2
2555cf
Author: Christina Fu <cfu@dhcp-16-189.sjc.redhat.com>
2555cf
Date:   Fri Jan 20 16:01:17 2017 -0800
2555cf
2555cf
    Ticket #1741 ECDSA certs Alg IDs contian parameter field
2555cf
    Per rfc5758, When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or ecdsa-with-SHA512 algorithm identifier appears in the algorithm field as an AlgorithmIdentifier, the encoding MUST omit the parameters field.
2555cf
    Note: Since we do not support DSA, this patch does not attempt to address them.
2555cf
    Also, while we do not claim to support sha224, the patch adds enough code to process the OID just for completeness.  However, it does not attempt to offer it as part of the signing algorithms.
2555cf
    
2555cf
    (cherry picked from commit 76ca6d1691e56274945b6f03760273208fafd791)
2555cf
    (cherry picked from commit 1e567854e643f50a7ca1f24daac0e92359eafe81)
2555cf
2555cf
diff --git a/base/util/src/netscape/security/x509/AlgorithmId.java b/base/util/src/netscape/security/x509/AlgorithmId.java
2555cf
index 08c9c4f..a89843e 100644
2555cf
--- a/base/util/src/netscape/security/x509/AlgorithmId.java
2555cf
+++ b/base/util/src/netscape/security/x509/AlgorithmId.java
2555cf
@@ -230,10 +230,18 @@ public class AlgorithmId implements Serializable, DerEncoder {
2555cf
         try (DerOutputStream tmp = new DerOutputStream()) {
2555cf
             DerOutputStream bytes = new DerOutputStream();
2555cf
             bytes.putOID(algid);
2555cf
-            if (params == null)
2555cf
-                bytes.putNull();
2555cf
-            else
2555cf
-                bytes.putDerValue(params);
2555cf
+
2555cf
+            // omit parameter field for ECDSA
2555cf
+            if (!algid.equals(sha224WithEC_oid) &&
2555cf
+                    !algid.equals(sha256WithEC_oid) &&
2555cf
+                    !algid.equals(sha384WithEC_oid) &&
2555cf
+                    !algid.equals(sha512WithEC_oid)) {
2555cf
+                if (params == null) {
2555cf
+                    bytes.putNull();
2555cf
+                } else
2555cf
+                    bytes.putDerValue(params);
2555cf
+            }
2555cf
+
2555cf
             tmp.write(DerValue.tag_Sequence, bytes);
2555cf
             out.write(tmp.toByteArray());
2555cf
         }
2555cf
@@ -246,12 +254,19 @@ public class AlgorithmId implements Serializable, DerEncoder {
2555cf
     public final byte[] encode() throws IOException {
2555cf
         try (DerOutputStream out = new DerOutputStream()) {
2555cf
             DerOutputStream bytes = new DerOutputStream();
2555cf
-
2555cf
             bytes.putOID(algid);
2555cf
-            if (params == null)
2555cf
-                bytes.putNull();
2555cf
-            else
2555cf
-                bytes.putDerValue(params);
2555cf
+
2555cf
+            // omit parameter field for ECDSA
2555cf
+            if (!algid.equals(sha224WithEC_oid) &&
2555cf
+                    !algid.equals(sha256WithEC_oid) &&
2555cf
+                    !algid.equals(sha384WithEC_oid) &&
2555cf
+                    !algid.equals(sha512WithEC_oid)) {
2555cf
+                if (params == null) {
2555cf
+                    bytes.putNull();
2555cf
+                } else
2555cf
+                    bytes.putDerValue(params);
2555cf
+            }
2555cf
+
2555cf
             out.write(DerValue.tag_Sequence, bytes);
2555cf
             return out.toByteArray();
2555cf
         }
2555cf
@@ -314,6 +329,9 @@ public class AlgorithmId implements Serializable, DerEncoder {
2555cf
         if (name.equals("SHA1withEC") || name.equals("SHA1/EC")
2555cf
                 || name.equals("1.2.840.10045.4.1"))
2555cf
             return AlgorithmId.sha1WithEC_oid;
2555cf
+        if (name.equals("SHA224withEC") || name.equals("SHA224/EC")
2555cf
+                || name.equals("1.2.840.10045.4.3.1"))
2555cf
+            return AlgorithmId.sha224WithEC_oid;
2555cf
         if (name.equals("SHA256withEC") || name.equals("SHA256/EC")
2555cf
                 || name.equals("1.2.840.10045.4.3.2"))
2555cf
             return AlgorithmId.sha256WithEC_oid;
2555cf
@@ -646,6 +664,8 @@ public class AlgorithmId implements Serializable, DerEncoder {
2555cf
      */
2555cf
     private static final int sha1WithEC_data[] =
2555cf
                                    { 1, 2, 840, 10045, 4, 1 };
2555cf
+    private static final int sha224WithEC_data[] =
2555cf
+                                   { 1, 2, 840, 10045, 4, 3, 1 };
2555cf
     private static final int sha256WithEC_data[] =
2555cf
                                    { 1, 2, 840, 10045, 4, 3, 2 };
2555cf
     private static final int sha384WithEC_data[] =
2555cf
@@ -676,6 +696,9 @@ public class AlgorithmId implements Serializable, DerEncoder {
2555cf
     public static final ObjectIdentifier sha1WithEC_oid = new
2555cf
             ObjectIdentifier(sha1WithEC_data);
2555cf
 
2555cf
+    public static final ObjectIdentifier sha224WithEC_oid = new
2555cf
+            ObjectIdentifier(sha224WithEC_data);
2555cf
+
2555cf
     public static final ObjectIdentifier sha256WithEC_oid = new
2555cf
             ObjectIdentifier(sha256WithEC_data);
2555cf