# Feitian OTP applet wire protocol This document describes the protocol of the OTP (TOTP/HOTP) applet on Feitian FIDO security keys, as implemented by `keyroost-feitianotp`. It is a smart-card applet like the Yubico/Trussed OATH applet (`oath` group), and its commands have the same general shape, but it is a different protocol: its own AID, instruction bytes and tags, three slots, and no field for a TOTP period. ## How each statement here is known Every fact below is marked with where it comes from: - **Measured**: seen in an exchange with a physical key. - *Key A*: Feitian BioPass FIDO Pro, USB `096E:086A`, OTP applet 1.0.1. Read with Libre Key Companion (Android, USB CCID), and with `keyroostctl` over PC/SC on Windows (`feitian info`, `list`, `add`, `code` and `delete`; not `reset`). - *Key B*: Feitian ePass FIDO NFC Plus, USB `096E:0853`, OTP applet 1.0.2. Read with Libre Key Companion (Android, USB CCID), over direct CCID, and with `keyroostctl` over PC/SC on Windows (every `feitian` command). Two keys of this model were read. Apart from the value under tag `51` they answered alike in what both were asked: SELECT and LIST over PC/SC and over FIDO HID, and the wait for a touch. Which of the two an exchange was made with was not always noted. The product names are what the keys report. Feitian's client names a model with `80 E3 EE 80 00`; the second byte under tag `81` of the answer is `08` on Key A and `02` on a Key B, the numbers that client calls BioPass FIDO Pro and ePass FIDO-NFC Plus, and tag `92` holds the COS version Feitian publishes for each product (4.7.17 and 1.826). That read was made on Key A and on one of the two Key B. - **Client**: what Feitian's own client applications send or expect. Not yet exercised on hardware by this project. Codes were checked against references computed independently from the published RFC 4226 and RFC 6238 test seeds, written to the keys for the purpose. ## Transport - **Interface:** the key's smart-card interface: CCID over USB, or NFC. The applet is selected by AID. *(Measured.)* - **APDUs:** short ISO 7816. Both keys answer over T=1. *(Measured.)* - **FIDO HID:** the same APDUs also go through the key's FIDO HID interface, each one as it is in a `CTAPHID_MSG`. Feitian's client uses that when there is no CCID reader, and so does `keyroost`, for a key with no reader on this computer or one whose reader can't be opened. *(Measured, Key A and Key B: SELECT, LIST, PUT, CALCULATE and DELETE, with the same answers as over PC/SC.)* - Short APDUs only: the SELECT in extended-length form is answered `6700`. *(Measured.)* - A `CTAPHID_MSG` reaches whichever applet was selected last. With this applet selected, U2F's VERSION is answered `6D00`; after a SELECT of the FIDO applet (`A0 00 00 06 47 2F 00 01`) it answers `U2F_V2` again. So `keyroost` selects the FIDO applet again when it is done. *(Measured.)* - A command that waits for a touch is answered `6984` only once the key has waited for it (see CALCULATE), with nothing sent meanwhile. CTAP's usual read timeout runs out first, so an exchange is given longer. *(Measured.)* Feitian's client reads for up to 30 seconds per exchange there. *(Client.)* - Windows lets only an administrator open this interface. - **Windows:** Key B's card can stay unresponsive after plug-in. The reader's cold reset fails, and connecting answers `SCARD_W_UNRESPONSIVE_CARD`, or `SCARD_E_PROTO_MISMATCH` about ten seconds after a warm reset. This is the whole card, not this applet: OpenPGP and PIV on the key go undetected too. A warm reset over a direct connection (`IOCTL_SMARTCARD_POWER` with `SCARD_WARM_RESET`) brings the card up, and `keyroost` does that once, for a Feitian reader, before it gives up. *(Measured on one PC, Windows 11 with the inbox CCID driver: no applet detected without the retry, all three with it. Key A connected without it there. Reported on other PCs. Why the cold reset fails is not established.)* ## Selecting the applet ``` 00 A4 04 00 09 D1 56 00 01 32 83 26 01 01 ``` The AID starts with Feitian's registered RID, `D1 56 00 01 32`. There is no `Le` byte. *(Measured, both keys.)* The answer is a flat run of TLVs with one-byte lengths: | Tag | Length | Meaning | |---|---|---| | `59` | 3 | Applet version: `01 00 02` is 1.0.2. *(Measured.)* | | `51` | 8 | A value Feitian's client calls the challenge and uses as the salt of a slot's access-code key. *(Length measured; use is Client.)* | | `7B` | 1 | One bit per slot that has an access code: bit 0 slot 1, bit 1 slot 2, bit 2 the default slot. Both keys answer `00`. *(Value measured; bit layout is Client.)* | Each key answers its own `51` value, and none was seen to change it. Key A answered the same value when it was first read and when it was read again on 2026-11-19 and on 2026-11-22. The two keys of Key B's model answer different values from each other: one answered its value on 2026-11-18 and on 2026-11-22, the other on 2026-11-19 and on 2026-11-22, across repeated SELECTs and card resets and, on that second key, a RESET of the applet. *(Measured.)* These keys do not host the Yubico OATH applet. A SELECT of its AID (`A0 00 00 05 27 21 01`) is answered `6700` by Key A and `6D00` by Key B, not `6A82`. *(Measured.)* ## The key's serial ``` 80 E3 03 00 00 ``` This is not a command of the OTP applet. The key answers it whichever application is selected: nothing selected after a reset, and this applet, PIV and OpenPGP selected, all gave the same answer. *(Measured, one Key B, 2026-11-22.)* It is the command Feitian's client reads the serial it shows with. *(Client.)* The answer is the serial in ASCII, padded with zero bytes: twelve bytes, nine digits and three zeros. *(Measured, one Key B.)* Each key answers a serial of its own: the two keys of Key B's model answer different serials, and Key A a third, nine digits as well. *(Measured, Key A and both keys of Key B's model. For Key A and the second Key B only the serial keyroost took from the answer was seen, not the bytes.)* keyroost takes an answer of that shape, six or more letters or digits and then only zeros, as the key's serial, and nothing else. Feitian's client also reads an answer of exactly eight bytes as a binary serial; no key was seen to answer that way. *(Client.)* The key's OpenPGP application has a serial field of its own, in its AID: `00 00 00 01` on both keys of Key B's model, whose AIDs are the same sixteen bytes. Feitian's client selects that application by an AID with those four bytes in it. So the field does not tell one key from another. *(AIDs measured, both keys of Key B's model; the AID the client selects by is Client.)* keyroost used to show that field as the serial of a Feitian key with OpenPGP, and showed none for one without. Key A is one without: it answers the OpenPGP SELECT `6700`. *(Measured.)* ## The key's device information ``` 80 E3 EE 80 00 ``` Like the serial read, this is the key's command and not the OTP applet's. A Key B answered it with nothing selected and with each of its applications selected, Key A with PIV selected. *(Measured, Key A and one Key B, 2026-11-22 and 23.)* It is the command Feitian's client names a key's model with. *(Client.)* The answer is `80`, a second byte, and then TLVs with one-byte tags and lengths. The second byte is not a length to go by: it counts the TLVs on Key A and the whole answer on Key B. keyroost reads the TLVs to the end of the answer, as Feitian's client does. *(Measured; the client's reading is Client.)* | Tag | Key A | Key B | What | |---|---|---|---| | `81` | `04 08` | `02 02` | The last byte is the product: Feitian's clients name `08` "BioPass FIDO Pro" and `02` "ePass FIDO-NFC Plus". They read a value of three bytes too, with one more byte in front and the product still last; no key was seen to answer that way. *(Client.)* | | `82` | nine ASCII digits | nine ASCII digits | The serial that the serial read above gives. | | `84` | `47 17 00` | `07 04 00` | Also each key's USB release number. Feitian's client shows the first two bytes as the COS version. *(Client.)* | | `92` | `47 17 00` | `01 08 26` | The COS version Feitian publishes for the product: 4.7.17 for the BioPass FIDO Pro, 1.826 for the ePass FIDO NFC Plus. | The other tags (`83`, `85`, `86`, and on Key A `87` to `90`) are not read. *(Measured.)* Feitian's product list () gives each product a COS version under "COS/Applet version", and for some a version for each application beside it: for the ePass FIDO NFC Plus (K9D, K40 Plus), COS 1.826 with FIDO 9134, PIV 9166, openPGP 7386 and OTP 9126; for the BioPass FIDO Pro (K49 Pro, K50 Pro), COS 4.7.17. Those are the digits under `92` on the two keys. The list has a second row named ePass FIDO NFC Plus (K9, K40) with COS 3.3.01; no key with that version was read. *(Feitian's product list.)* keyroost shows the value under `92` as a Feitian key's firmware version, in the app's key header and in `fido info`, as the three bytes read, two digits each: `47.17.00` and `01.08.26`. Feitian groups those digits differently for the two products, so keyroost does not regroup them. When the key answers this read, keyroost shows it in place of the key's CTAPHID INIT version bytes (`1.0.1` on Key A), which are neither value. When the read gives nothing, for instance with no smart-card reader for the key, the INIT version bytes are shown as they are. ## An application's version ``` 80 E2 80 00 05 DF FF 02 80 01 00 ``` Sent after a SELECT, this answers for the application selected. It is the command Feitian's client shows each application's version with. *(Client.)* | Key | Selected | Answer | |---|---|---| | A | PIV | `00 00 00 01 14 00 33 20 47 17 18 01 09 11 00 00` | | B | PIV | `00 00 00 01 00 00 00 00 91 66 25 02 25 14 16 00` | | B | OTP | `00 00 00 01 14 00 00 00 91 26 25 01 17 11 14 13` | *(Measured, Key A and one Key B, 2026-11-23; the other Key B answered the same sixteen bytes with PIV selected.)* The version is bytes 8 and 9, where the client reads it: `91 66` and `91 26` are the PIV 9166 and OTP 9126 of Feitian's product list (: the ePass FIDO NFC Plus K9D, COS 1.826, lists PIV 9166 and OTP 9126; the K9, COS 3.3.01, lists PIV 8063). Key A's `47 17` are the first digits of its COS version; the list gives that product no number for PIV. The other bytes are not read. The OTP applet's SELECT answer carries a version of another kind under tag `59` (1.0.2 on the same Key B). Feitian told a contributor (November 2026) that the numbers of one product order by size, a later version having the larger number, and that the numbers of two products do not compare. It also said that a change to an application, to the COS or to the hardware can each change what PIV does, and that it keeps no list of the differences between versions to publish. keyroost reads this version for PIV only, on the two products it has PIV rows for, and shows it as the PIV applet's version, the digits as Feitian writes them (`9166`). What it knows a product's PIV to do is recorded at the version it was measured at: a key of the product with an earlier version, or one whose version could not be read, is sent Feitian's commands and not assumed to take all of them. ## Slots Every command after SELECT names a slot in P2. | P2 | Slot | | |---|---|---| | `F0` | default | Where Feitian's apps store codes. *(Measured: all credentials on both keys.)* | | `00` | 1 | Keyboard slot. *(LIST measured, empty on Key B; use is Client.)* | | `01` | 2 | Keyboard slot. *(Same.)* | A credential is identified by its slot and its stored name together. ## Credential names The applet has no period field. Feitian's apps keep the period in the stored name, and so does `keyroost`: ``` TOTP: 30:issuer_#_account 60:issuer_#_account HOTP: issuer_#_account ``` - A TOTP name starts with `30:` or `60:`; those are the only two periods. - Issuer and account are joined with `_#_`. With no issuer the account stands alone. - An HOTP name has no prefix. *(Measured: every stored name on both keys has this form. That Feitian's apps write it this way is Client.)* A TOTP name with no prefix is read as a 30-second credential; the card has nothing that says otherwise. CALCULATE and DELETE send the stored name back unchanged, prefix included. ## Commands All commands use CLA `00`. Data is a run of TLVs with one-byte lengths. ### LIST (`17`) ``` 00 17 00 00 ``` The answer is one `52` TLV per credential, `52 `. An empty slot answers `9000` with no data. *(Measured.)* The first value byte holds the kind in its high nibble and the algorithm in its low nibble: | Nibble | Value | Meaning | |---|---|---| | high | `1` | HOTP *(Measured, Key A)* | | high | `2` | TOTP *(Measured)* | | high | `3`, `4` | Static password, challenge-response *(Client; not handled, counted as skipped)* | | low | `1` | HMAC-SHA-1 *(Measured)* | | low | `2` | HMAC-SHA-256 *(Measured, Key B)* | Feitian's client answers a `6700` here by sending the four bytes `00 17 00 00` (no slot, no `Le`) and then asks no other slot. *(Client. Neither key returned `6700` to a LIST.)* `keyroost` does the same for the default slot only. ### CALCULATE (`A2`) ``` 00 A2 01 54 08