Nitrokey / nitrokey-pro-firmware

Firmware for the Nitrokey Pro device
GNU General Public License v3.0
117 stars 21 forks source link

Nitrokey HSM: handle v4.0 smart cards #100

Open szszszsz opened 9 months ago

szszszsz commented 9 months ago

The new H/W v4.0 HSM smart cards are not properly setting up with the current firmware. The problem with communication starts right away after execution of the PPS procedure, where the higher bit rate is configured with the smart card, after which the USART peripheral working in the SMARTCARD mode is reconfigured with higher bitrate as well. After this point smart card is requested for its serial number, which ends up malformed. Similarly further USB CCID requests, which are passed to the smart card, are either ending up in a Default Handler due to the Frame Exception being raised, or just in an infinite loop, where the MCU awaits for the flag change from the USART peripheral, which at some point should signalize data reception. Interestingly, when the PTS_config() body execution is skipped (= insert return as a first line), everything works fine at the default speed of 9600bps, however this speed is clearly not enough to have a proper user experience. The aim is to have at least the speed of the previous smart card generation, which is ~ 115kbps. Even if the configuration of the minimal speed is attempted, which should end up in the same value as the default one - 9600bps, the proper communication is not achieved.

The v3.0 cards work properly with the current implementation. The only changes are:

Done so far:

Some of the mentioned are stored in the commits history of the wip scratch branch (does not work, and its not coherent):

Things to check yet:

Initial configuration - SC_Init():

Mentioned PTS_config(): https://github.com/Nitrokey/nitrokey-pro-firmware/blob/47dd7f1ad6789e5b317266b831d8624c7d126063/src/ccid/smartcard/smartcard.c#L507-L670

Hardware schematics: