TOTP Code Backup

Just a quick note for anyone who stumbles upon this: KeePassXC is able to properly store TOTP secrets (and also generate TOTP codes). You can use a small shell command in Linux to mass import these TOTP entries from KeePassXC into the OTP applet on the Apex:

keepassxc-cli export  -f xml /home/user/Database.kdbx | xmllint -xpath "//Key[text()='otp']/following-sibling::Value/text()" - | xargs -l ykman -r "READER_NAME" oath accounts uri

If your KeePassXC database is secured using the HMAC-SHA1 Yubico-style protocol as well, add e.g. -y "1:12341234" to the keepassxc-cli command, 12341234 being the serial number of the key (displayed in KeePassXC) and 1 the slot to use.

You also have to replace the path /home/user/Database.kdbx with the path to your KeePassXC database. In addition, the READER_NAME string has to be relaced with the name of the PC/SC reader you use, you can look those up by running pcsc_scan.

In terms of requirements, you will need yubikey-manager CLI tool, and the libxml2 tools.

Also, just as a final note: I do not recommend storing these TOTP secrets in the same database where you store the associated passwords for these accounts.

2 Likes