Skip to content

OpenSC pkcs11-tool fails to sign #1130

@mouse07410

Description

@mouse07410

Problem Description

pkcs11-tool from 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-509 or -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-tool must accept -M RSA-XXX parameter together with -s.

Steps to reproduce

  1. Insert a PIV token with RSA keys.
  2. Attempt any of the following:
  • $ 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.sig
  1. Observe the failure, as shown below.

Note that adding --id 02 did not help.

Logs

$ 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.
$ 

Update
My fault: should've used -m XXX instead of -M.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions