$ pkcs11-tool -M
Using slot 0 with a present token (0x0)
Supported mechanisms:
SHA-1, digest
SHA256, digest
SHA384, digest
SHA512, digest
MD5, digest
RIPEMD160, digest
GOSTR3411, digest
ECDSA, keySize={256,384}, hw, sign, other flags=0x1800000
ECDH1-COFACTOR-DERIVE, keySize={256,384}, hw, derive, other flags=0x1800000
ECDH1-DERIVE, keySize={256,384}, hw, derive, other flags=0x1800000
RSA-X-509, keySize={1024,3072}, hw, decrypt, sign, verify
RSA-PKCS, keySize={1024,3072}, hw, decrypt, sign, verify
SHA1-RSA-PKCS, keySize={1024,3072}, sign, verify
SHA256-RSA-PKCS, keySize={1024,3072}, sign, verify
SHA384-RSA-PKCS, keySize={1024,3072}, sign, verify
SHA512-RSA-PKCS, keySize={1024,3072}, sign, verify
MD5-RSA-PKCS, keySize={1024,3072}, sign, verify
RIPEMD160-RSA-PKCS, keySize={1024,3072}, sign, verify
$ pkcs11-tool -l -M RSA-PKCS -s -i t2048.dat -o t2048.dat.sig
error: invalid option(s) given
Aborting.
$ pkcs11-tool -s -M RSA-PKCS -i t2048.dat -o t2048.dat.sig
error: invalid option(s) given
Aborting.
$ pkcs11-tool -s -M SHA256-RSA-PKCS -i t2048.dat -o t2048.dat.sig
error: invalid option(s) given
Aborting.
$ pkcs11-tool -s -M RSA-X-509 -i t2048.dat -o t2048.dat.sig
error: invalid option(s) given
Aborting.
$ OPENSC_DEBUG=9 pkcs11-tool -s -M RSA-X-509 -i t2048.dat -o t2048.dat.sig
error: invalid option(s) given
Aborting.
$ OPENSC_DEBUG=9 pkcs11-tool -s -i t2048.dat -o t2048.dat.sig
Using slot 0 with a present token (0x0)
Logging in to "PIV Card Holder pin (PIV_II)".
Please enter User PIN:
Using signature algorithm ECDSA
error: PKCS11 function C_SignInit failed: rv = CKR_KEY_TYPE_INCONSISTENT (0x63)
Aborting.
$
Problem Description
pkcs11-toolfrom the current OpenSC master by default chooses ECDSA as the signature algorithm, regardless of the presented key type. To make things worse, it refuses parameters like-M RSA-X-509or-M RSA-PKCS.Proposed Resolution
Ideally, make
do_sign()actually look at the key type and decide upon the signature algorithm accordingly. As a minimum -pkcs11-toolmust accept-M RSA-XXXparameter together with-s.Steps to reproduce
$ pkcs11-tool -s -M RSA-X-509 -i t2048.dat -o t2048.dat.sig$ pkcs11-tool -s -M RSA-PKCS -i t2048.dat -o t2048.dat.sig$ OPENSC_DEBUG=9 pkcs11-tool -s -i t2048.dat -o t2048.dat.sigNote that adding
--id 02did not help.Logs
Update
My fault: should've used
-m XXXinstead of-M.