OpenSC/OpenSC — pull request #288 by philipWendland (2014-09-25 15:38:23+00:00)
Title: add the possibility to store public ECC keys encoded according to SPKI

When using "standard means" to store public ECC keys to the filesystem, the key is encoded as RAW containing only the ecPointQ. This is problematic, because when extracting the key from the EF again (pkcs15-tool --read-public-key), there is no information about the curve.
The extracted keys (.pem) are unusable because they lack information about the curve.

This code path is apparently not used by any card-driver at the moment. However, I discovered this while developing a new Java Card applet with OpenSC read/write support.

PKCS#15 (section 6.4.3) specifies two possible encodings for EC keys: RAW or SPKI
The proposed change adds the possibility to specify in the profile which ECC encoding should be used. The default is the RAW encoding as used before - I don't want to mess things up with existing drivers.

pkcs15-pubkey.c: When reading the key, I use the ASN1 constructed sequence tag (0x30) to identify the SPKI encoding. RAW encoded public keys begin with 0x04. The profile->key_encoding_flags can't be used here, because there is no access to the profile from this function.

profile: I decided to use flags rather than a definite value because the key encodings might have to be extended at some point (e.g. for different key types, or: "ECC-RAW-with-parameters")

With this change and SPKI in the profile of my applet, I can verify ECDSA signatures using OpenSSL with the extracted key.
Please let me know if I should correct something.