Created
February 9, 2024 12:58
-
-
Save joostd/ef34e52d17bbf546977ff8cfd61f38cd to your computer and use it in GitHub Desktop.
Use the FIDO hmac-secret extension to generate a secret
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DEMO for hmac-secret - generate a static secret based on a FIDO credential and a salt | |
# Uses libfido2 tools: https://github.com/Yubico/libfido2 | |
HID="$(shell fido2-token -L | head -1 | cut -d: -f1-2)" | |
all: secret | |
cred.in: | |
# challenge: | |
cat /dev/urandom | head -c32 | base64 > cred.in | |
echo relying party >> cred.in | |
echo user name >> cred.in | |
# userID: | |
cat /dev/urandom | head -c16 | base64 >> cred.in | |
# generate credential using hmac-secret extension | |
cred.out: cred.in | |
fido2-cred -M -h -i cred.in ${HID} > cred.out | |
# verify credential | |
cred: cred.out | |
cat cred.out | fido2-cred -V -h -o cred | |
pubkey: cred | |
tail -n +2 cred > pubkey | |
salt: | |
cat /dev/urandom | head -c32 > ./salt | |
assert.in: cred salt | |
# challenge: | |
cat /dev/urandom | head -c32 | base64 > assert.in | |
echo relying party >> assert.in | |
# credential ID: | |
head -1 cred >> assert.in | |
cat salt | base64 >> assert.in | |
# generate assertion using hmac-secret extension | |
assert.out: assert.in | |
fido2-assert -G -h -i assert.in ${HID} > assert.out | |
# verify assertion: | |
assert: assert.out pubkey | |
cat assert.out | fido2-assert -V -h pubkey es256 | |
secret: assert.out | |
@/bin/echo -n "secret: " | |
@tail -1 assert.out | |
clean: | |
-rm assert.in assert.out cred.in cred.out cred pubkey salt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List FIDO security tokens:
Create an input file:
generate a FIDO credential using the hmac-secret extension:
The output looks like this:
Create an input file to generate an assertion:
Generate an assertion, using the hmac-secret extension:
Optionally, verify the assertion:
The output looks like this:
The last line of this file contains your secret:
Note: Some YubiKeys (such as the YubiKey Bio) have an option
alwaysUV
enabled by default. When that option is enabled, UV is always required and you need to instructfido2-assert
to ask for the PIN as follows:If you do not want UV for creating assertions, you can disable the
alwaysUV
option as follows: