changeset 8792:b968a7cf967f

8006951: Avoid storing duplicate PKCS12 attributes Reviewed-by: mullan
author vinnie
date Tue, 21 Nov 2017 07:17:36 +0000
parents 141b4c3ce4c2
children c92db09aed60
files src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Fri Jan 25 16:19:39 2013 +0000
+++ b/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Tue Nov 21 07:17:36 2017 +0000
@@ -129,6 +129,13 @@
 
     public static final int VERSION_3 = 3;
 
+    // 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};
@@ -1479,7 +1486,14 @@
 
         if (attributes != null) {
             for (PKCS12Attribute attribute : attributes) {
-                attrs.write(((PKCS12Attribute) attribute).getEncoded());
+                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(attribute.getEncoded());
             }
         }