6763530: Cannot decode PublicKey (Proider SunPKCS11, curve prime256v1)

Reviewed-by: andrew
This commit is contained in:
Vinnie Ryan 2010-01-21 23:59:41 +00:00
parent 9645beba5c
commit 50b83fe62f
2 changed files with 23 additions and 2 deletions

View File

@ -40,6 +40,8 @@ import static sun.security.pkcs11.TemplateManager.*;
import sun.security.pkcs11.wrapper.*;
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
import sun.security.util.DerValue;
/**
* EC KeyFactory implemenation.
*
@ -201,7 +203,16 @@ final class P11ECKeyFactory extends P11KeyFactory {
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),

View File

@ -45,6 +45,8 @@ import sun.security.internal.interfaces.TlsMasterSecret;
import sun.security.pkcs11.wrapper.*;
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
import sun.security.util.DerValue;
/**
* Key implementation classes.
*
@ -998,10 +1000,18 @@ abstract class P11Key implements Key {
};
fetchAttributes(attributes);
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);
}