Regardless whether you are on Android or desktop, you should at this point have an implementation of the CardChannel interface (be it NFCCardChannel or PCSCCardChannel). You can now start working with the card. The first thing to do is creating a KeycardCommandSet instance. This class gives access to all of the applet functionality, wrapping the low-level APDUs in easy to use methods. All other classes in the SDK are helper to format parameters and parse responses from the card. To create a command set, just do
If you also need to accept cards from the Keycard test CA, or want to pin specific card identities, see Secure Channel.
Modern SmartCards can have several applications installed, so after connection with the card you need to select the Keycard applet. This is easily done with
While this correctly selects the applet, it discards the card response, which contains information that can be useful to identify this specific card and its state. For this reason we could rewrite this as
The application remains selected until another applet is explicitly selected, or the card is powered off (for example is removed from the field)
getInstanceUID() and getFreePairingSlots() have no meaning —
the instance UID and the pairing slot count are no longer in the SELECT
response, and pairing does not exist. Use getKeyUID() to identify the wallet
and getCertData() for a card identifier that survives a reinstall. The SDK
returns null/zero for the removed fields rather than failing, so the same code
runs on both card generations.This step is necessary to bring the initial credentials on the Keycard instance. When the card is not initialized, it cannot perform any operation. Initialization sets the PIN and PUK and requires no prior authentication. Once the card is initialized, it cannot be initialized again (though the credentials themselves can be changed later, with authentication).
You can also specify the number of retries for PIN/PUK and a duress PIN
The init overloads that take a pairing password instead of a secret are there for applet 3.x cards, which pair. On a 4.0 card the secret must be empty, otherwise the card rejects the payload length.