8006951: Avoid storing duplicate PKCS12 attributes
authorvinnie
Fri, 25 Jan 2013 17:47:37 +0000
changeset 15308 55742a890b6c
parent 15307 6c19bd915338
child 15309 b585dca79d0b
8006951: Avoid storing duplicate PKCS12 attributes Reviewed-by: mullan
jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
--- a/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Fri Jan 25 16:19:39 2013 +0000
+++ b/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Fri Jan 25 17:47:37 2013 +0000
@@ -136,6 +136,13 @@
         "keystore.PKCS12.keyProtectionAlgorithm"
     };
 
+    // friendlyName, localKeyId, trustedKeyUsage
+    private static final String[] CORE_ATTRIBUTES = {
+        "1.2.840.113549.1.9.20",
+        "1.2.840.113549.1.9.21",
+        "2.16.840.1.113894.746875.1.1"
+    };
+
     private static final Debug debug = Debug.getInstance("pkcs12");
 
     private static final int keyBag[]  = {1, 2, 840, 113549, 1, 12, 10, 1, 2};
@@ -1537,6 +1544,13 @@
 
         if (attributes != null) {
             for (KeyStore.Entry.Attribute attribute : attributes) {
+                String attributeName = attribute.getName();
+                // skip friendlyName, localKeyId and trustedKeyUsage
+                if (CORE_ATTRIBUTES[0].equals(attributeName) ||
+                    CORE_ATTRIBUTES[1].equals(attributeName) ||
+                    CORE_ATTRIBUTES[2].equals(attributeName)) {
+                    continue;
+                }
                 attrs.write(((PKCS12Attribute) attribute).getEncoded());
             }
         }