diff -r b18db2d63e3b -r f8a00c400655 jdk/src/share/classes/sun/security/pkcs11/P11Key.java --- a/jdk/src/share/classes/sun/security/pkcs11/P11Key.java Wed Oct 12 12:12:25 2011 -0700 +++ b/jdk/src/share/classes/sun/security/pkcs11/P11Key.java Thu Oct 13 12:00:51 2011 +0100 @@ -1028,28 +1028,21 @@ try { params = P11ECKeyFactory.decodeParameters (attributes[1].getByteArray()); - - /* - * An uncompressed EC point may be in either of two formats. - * First try the OCTET STRING encoding: - * 04 04 - * - * Otherwise try the raw encoding: - * 04 - */ byte[] ecKey = attributes[0].getByteArray(); - try { + // Check whether the X9.63 encoding of an EC point is wrapped + // in an ASN.1 OCTET STRING + if (!token.config.getUseEcX963Encoding()) { DerValue wECPoint = new DerValue(ecKey); - if (wECPoint.getTag() != DerValue.tag_OctetString) - throw new IOException("Unexpected tag: " + - wECPoint.getTag()); + if (wECPoint.getTag() != DerValue.tag_OctetString) { + throw new IOException("Could not DER decode EC point." + + " Unexpected tag: " + wECPoint.getTag()); + } w = P11ECKeyFactory.decodePoint (wECPoint.getDataBytes(), params.getCurve()); - } catch (IOException e) { - // Failover + } else { w = P11ECKeyFactory.decodePoint(ecKey, params.getCurve()); }