changeset 2107:117b245b5bb9

6763530: Cannot decode PublicKey (Proider SunPKCS11, curve prime256v1) Reviewed-by: andrew
author vinnie
date Thu, 21 Jan 2010 23:59:41 +0000
parents 8339fd49bf6b
children c94ac5522d01
files src/share/classes/sun/security/pkcs11/P11ECKeyFactory.java src/share/classes/sun/security/pkcs11/P11Key.java
diffstat 2 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/pkcs11/P11ECKeyFactory.java	Tue Jan 19 11:43:45 2010 +0800
+++ b/src/share/classes/sun/security/pkcs11/P11ECKeyFactory.java	Thu Jan 21 23:59:41 2010 +0000
@@ -40,6 +40,8 @@
 import sun.security.pkcs11.wrapper.*;
 import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
 
+import sun.security.util.DerValue;
+
 /**
  * EC KeyFactory implemenation.
  *
@@ -201,7 +203,16 @@
 
     private PublicKey generatePublic(ECPoint point, ECParameterSpec params) throws PKCS11Exception {
         byte[] encodedParams = ECParameters.encodeParameters(params);
-        byte[] encodedPoint = ECParameters.encodePoint(point, params.getCurve());
+        byte[] encodedPoint = null;
+        DerValue pkECPoint = new DerValue(DerValue.tag_OctetString,
+            ECParameters.encodePoint(point, params.getCurve()));
+
+        try {
+            encodedPoint = pkECPoint.toByteArray();
+        } catch (IOException e) {
+            throw new IllegalArgumentException("Could not DER encode point", e);
+        }
+
         CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
             new CK_ATTRIBUTE(CKA_CLASS, CKO_PUBLIC_KEY),
             new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_EC),
--- a/src/share/classes/sun/security/pkcs11/P11Key.java	Tue Jan 19 11:43:45 2010 +0800
+++ b/src/share/classes/sun/security/pkcs11/P11Key.java	Thu Jan 21 23:59:41 2010 +0000
@@ -45,6 +45,8 @@
 import sun.security.pkcs11.wrapper.*;
 import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
 
+import sun.security.util.DerValue;
+
 /**
  * Key implementation classes.
  *
@@ -1000,8 +1002,16 @@
             try {
                 params = P11ECKeyFactory.decodeParameters
                             (attributes[1].getByteArray());
+                DerValue wECPoint = new DerValue(attributes[0].getByteArray());
+                if (wECPoint.getTag() != DerValue.tag_OctetString)
+                    throw new IOException("Unexpected tag: " +
+                        wECPoint.getTag());
+                params = P11ECKeyFactory.decodeParameters
+                            (attributes[1].getByteArray());
                 w = P11ECKeyFactory.decodePoint
-                            (attributes[0].getByteArray(), params.getCurve());
+                    (wECPoint.getDataBytes(), params.getCurve());
+
+
             } catch (Exception e) {
                 throw new RuntimeException("Could not parse key values", e);
             }