Skip to content

Conversation

@xhanulik
Copy link
Member

Driver card-idprime.c does not support some of the IDPrime cards - MD 830, 930 and 940.

The main problem is not matching key references that are assigned during the processing of the index file. The key references were recently set according to the OS version. However, some of the tested cards shared the same OS version but different key references of the private keys. The card matching is now done via ATR for particular card types, and the key reference offsets are distinguished according to card->type.

The idprime_process_index() function for processing the 0x0101 file adds the found certificate objects to the card. The index file contains entries which (probably) differ as the certificates were imported to the card with different tools. The entries can be

  • ksc or kxc alone - card should have corresponding private and public key
  • ksc/kxc with pubkxs/pubkxc - certificate is missing corresponding private key (CA certificates)
  • priprk, ksc/kxc and pubkxs/pubkxc - card should have the corresponding private and public key

Each certificate entry contains an index and the offset used for getting the private key reference.
Certificates that are missing a private key on the card are also added to the card but with some dummy key reference, which is then processed in sc_pkcs15emu_idprime_init(), where only the public key is added.

IDPrime 930 and 940 cards can work with 4096b RSA keys, which is added to the card initialization.

Cards also support EC keys and certificates - the sc_pkcs15emu_idprime_init() is extended by adding EC keys to the card. When signing with ECDSA keys, the data for signature needs to be padded (probably to some multiple of 8 bytes) before sending to the card.

The changes were tested with cards

  • IDPrime 3810 with RSA keys
  • IDPrime MD 830-FIPS with RSA keys
  • IDPrime 930 with RSA keys
  • IDPrime 940 cards with 4096b RSA key and EC key

There are still some issues which need to be addressed

  • key references (and offsets in idprime_process_index()) of EC keys may differ from the key references of RSA key
  • IDPrime 940 cards support CC certificates which are listed as common certificates in the index file

@xhanulik
Copy link
Member Author

xhanulik commented Feb 8, 2023

Added reading of cmap file, which contains records holding private key container names and index of corresponding certificates. It is used for the detection of CA certificates on the card.

For IDPrime 940, there is also a second PIN (Digital Signature PIN) used for accessing CC certificates on the card. File 0x0005 contains key references of private keys with PIN index and index of corresponding certificates. This is used for the classification of key objects to correct PIN.

xhanulik added 13 commits April 21, 2023 15:24
`kxc` and `ksc` objects denote certificates. Certificate objects
can be standalone - then we expect that they have public and private
keys on the card, or there can be `priprk` and `pubksc` denoting
corresponding private a public keys.
Cmap file contains records denoting container name and the record
index corresponds to the index of certificate.
IDPrime 940 uses digital signature pin for accessing CC certificates
File 0x0005 on IDPrime 940 contains 8 bytes records, which probably
denote key reference and PIN index associated with certificate index.
Copy link
Member

@Jakuje Jakuje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully last comments

Copy link
Member

@frankmorgner frankmorgner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look at @Jakuje comment about the possible memory leak, thank you.

xhanulik added 2 commits June 2, 2023 16:07
To indicate that the returned memory does not need to be free'd.
@Jakuje
Copy link
Member

Jakuje commented Jun 7, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants