Can't decrypt email using PIV Card with Thunderbird and OpenSC 0.12.0
|Reported by:||dcooper||Owned by:||opensc-devel@…|
When I try to decrypt an email with a PIV Card using OpenSC 0.12.0 with Thunderbird, C_DecryptInit() returns an error of CKR_KEY_TYPE_INCONSISTENT. The problem appears to be that C_DecryptInit() tries to verify that the key can be used to decrypt (CKA_DECRYPT) whereas RSA key management private keys on PIV Cards are only specified to support unwrapping (SC_PKCS15_PRKEY_USAGE_WRAP). However, decryption does work with OpenSC 0.11.13 and I cannot understand why the results are different between the two versions.
As a quick fix, I have been able to solve the problem by indicating that the key management keys on PIV Cards may be used to both decrypt and unwrap (see the attached patch file). This does not seem to be the "correct" fix since Table 2 in PKCS #15 indicates that SC_PKCS15_PRKEY_USAGE_ENCRYPT and SC_PKCS15_PRKEY_USAGE_DECRYPT are only consistent with the dataEncipherment keyUsage bit (which is not set in any of the certificates on PIV Cards) whereas SC_PKCS15_PRKEY_USAGE_WRAP and SC_PKCS15_PRKEY_USAGE_UNWRAP are consistent with the keyEncipherment keyUsage bit (which is he only bit set in the keyUsage extension of RSA key management certificates on PIV Cards).