Obtain serial number on the command line for unlocking keepassxc

I am using keepassxc-cli to extract passwords from my database which is locked with a password and my nitro-key. keepassxc-cli reqires the slot and the serial number for this to work. The GUI keepassxc extracts a serial number from the plugged in nitrokey, and can open the database. However, I fail to extract this exact same serial number using the commandline. nitropy seems not to be able to show the serial number. lsusb reports 0 for the iSerial and gpg –card-status reports a serial number that is different from the one that keepassxc(GUI) shows. The one gpg serial number seems to be part of the UUID but there is an other serial number hidden somewhere that keepassxc needs.

Any ideas?

I can see the serial number with nitropy nk3 secrets status. Note that nitropy display the number in hexadecimal. I don’t know which number format keepassxc-cli requires.

Try this command, it prints Nitrokey 3 serials in some kinds of representation:

nitropy list 2>&1 | grep “/dev/hidraw.\*: Nitrokey 3” | awk -Wnon-decimal-data ’ { printf “%s\\n%d\\n%s\\n%d\\n”,$4,“0x” $4,substr($4,1,8),“0x” substr($4,1,8) } ’