Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible key types values #1928

Closed
mat813 opened this issue Feb 3, 2020 · 5 comments
Closed

possible key types values #1928

mat813 opened this issue Feb 3, 2020 · 5 comments

Comments

@mat813
Copy link

mat813 commented Feb 3, 2020

Problem Description

I have a Nitrokey HSM and I wanted to generate an ECDSA key. By chance, pkcs11-tool's man page told me that I needed to write EC:something, with one example, prime256v1. I looked through all the man pages, and ended up looking at src/tools/pkcs11-tool.c where there is a list of possible values for something.

Proposed Resolution

It would be great if an exhaustive list of key types and their possible "size" was available in the man page, and maybe the wiki here, so that people whose job is not cryptography and do not know all those magical strings can have a starting point, because the list of supported mechanism that my key gives does not really help with it :(

Logs

$ pkcs11-tool -M
Using slot 0 with a present token (0x0)
Supported mechanisms:
  SHA-1, digest
  SHA224, digest
  SHA256, digest
  SHA384, digest
  SHA512, digest
  MD5, digest
  RIPEMD160, digest
  GOSTR3411, digest
  ECDSA, keySize={192,521}, hw, sign, other flags=0x1d00000
  ECDSA-SHA1, keySize={192,521}, hw, sign, other flags=0x1d00000
  ECDH1-COFACTOR-DERIVE, keySize={192,521}, hw, derive, other flags=0x1d00000
  ECDH1-DERIVE, keySize={192,521}, hw, derive, other flags=0x1d00000
  ECDSA-KEY-PAIR-GEN, keySize={192,521}, hw, generate_key_pair, other flags=0x1d00000
  RSA-X-509, keySize={1024,4096}, hw, decrypt, sign, verify
  RSA-PKCS, keySize={1024,4096}, hw, decrypt, sign, verify
  SHA1-RSA-PKCS, keySize={1024,4096}, sign, verify
  SHA224-RSA-PKCS, keySize={1024,4096}, sign, verify
  SHA256-RSA-PKCS, keySize={1024,4096}, sign, verify
  SHA384-RSA-PKCS, keySize={1024,4096}, sign, verify
  SHA512-RSA-PKCS, keySize={1024,4096}, sign, verify
  MD5-RSA-PKCS, keySize={1024,4096}, sign, verify
  RIPEMD160-RSA-PKCS, keySize={1024,4096}, sign, verify
  RSA-PKCS-PSS, keySize={1024,4096}, hw, sign, verify
  SHA1-RSA-PKCS-PSS, keySize={1024,4096}, sign, verify
  SHA224-RSA-PKCS-PSS, keySize={1024,4096}, sign, verify
  SHA256-RSA-PKCS-PSS, keySize={1024,4096}, sign, verify
  SHA384-RSA-PKCS-PSS, keySize={1024,4096}, sign, verify
  SHA512-RSA-PKCS-PSS, keySize={1024,4096}, sign, verify
  RSA-PKCS-KEY-PAIR-GEN, keySize={1024,4096}, generate_key_pair
@dengert
Copy link
Member

dengert commented Feb 3, 2020

PKCS11-v2.40 "2.3.3 ECDSA public key objects" says:" The CKA_EC_PARAMS or CKA_ECDSA_PARAMS attribute value is known as the “EC domain parameters” and is defined in ANSI X9.62 as a choice of three parameter representation methods with the following syntax"

"This allows detailed specification of all required values using choice ecParameters, the use of a
namedCurve as an object identifier substitute for a particular set of elliptic curve domain parameters, or implicitlyCA to indicate that the domain parameters are explicitly defined elsewhere. The use of a
namedCurve is recommended over the choice ecParameters. The choice implicitlyCA must not be
used in Cryptoki."

As far as I know, no smart cards supports ecParameters. And implicitlyCA must not be used. That leaves just namedCurve. PKCS11 does not list the available curves which are input not as a character string, but as a DER encoded OID of a nameCurve. There does not appear to be any PKCS11 command to list what curves are supported, other then to try and use one and see if the card will use it. (There are curves that have multiple names and thus the same OID, which

OpenSC pkcs11-tool.c lists all the EC curve names known to be used by cards supported by OpenSC drivers. But since pkcs11-tool can call other PKCS11 modules, it should accept an OID in decimal form or HEX and convert to a DER encoded OID so it can be then added to WHat PKCS11 calls "template for creating an EC (ECDSA) public key object" as {CKA_EC_PARAMS, ecParams, sizeof(ecParams)},
In pkcs11-tool.c look for `FILL_ATTR(publicKeyTemplate[n_pubkey_attr], CKA_EC_PARAMS, ecparams, ecparams_size);

What you really need to do is look at the vendor documentation for your smart card to determine which curves are supported.

supported-ecc-curve-for-nitrokey-hsm

@mat813
Copy link
Author

mat813 commented Feb 3, 2020

Ok, my smartcard was just an example with something that I had at hand.
I think it would be nice if somewhere in OpenSC's documentation, was a list of possible values, not related to any smartcard, but to what PKCS11 supports, I have no idea what the standard supports, or what form it could have, maybe a list of possible values:

  • rsa: with what the range of numbers is supported
  • ec:<string|oid> with a list of known oids
  • ...

If there is an authoritative list somewhere else, it would be ok to provide a link to it.
What I mean is that what is in the man page is not quite enough.

@dengert
Copy link
Member

dengert commented Feb 3, 2020

There is no one authoritative list. If you card could support "elliptic curve domain parameters" you could make up your own curve. (It would just not have an OID representation and may not be secure.)

See: Domain_parameters
"several standard bodies published domain parameters of elliptic curves for several common field sizes. Such domain parameters are commonly known as "standard curves" or "named curves"

Also see: where-can-i-find-a-canonical-list-of-elliptic-curve-names-and-their-aliases

Anyone can get an OID for anything. PKCS11 is extensible. It does not specify any specific list. pkcs11-tool.c is not. It has a list of curves that should include all the curves supported by the OpenSC "opensc-pkcs11.so" module. As I said it should allow for the use of any curve if the user provides an OID and a --module that supports the OID for the curve.

It still comes down to what does the token you have support, what does the other end support, what do the applications or protocol support. OpenSSL, TLS, FireFox, OpenSSH, etc. Many of these use curve names.

You are welcome to submit a PR for the Man pages or change the Wiki or submit a PR to allow pkcs11-tool.c to accept any OIDs even if not in the builtin list.

@frankmorgner
Copy link
Member

I agree, that we could do much better in terms of documenting features and standard use cases. However, I fear that I don't have much time to do this, currently.

Luckily, OpenSC is a community project and you're free to extend the wiki or the manual pages...

@frankmorgner
Copy link
Member

(Btw, as Doug said, PKCS#11 won't help you here. If you want a command line tool that tells you all available parameters, you should extend sc-hsm-tool)

frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 14, 2024
frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 16, 2024
frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 16, 2024
frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 30, 2024
frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Feb 13, 2024
@Jakuje Jakuje closed this as completed in 675b336 Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants