Hey folks,

I'm using signify(1) for update signatures in the upcoming WireGuard for
Windows (there'll be OpenBSD news soon in that department, I hope!). Not
wanting to store keys on my laptop or something, I managed to get a YubiHSM
to produce valid signify(1) signatures. I thought I should document that
somewhere, so here goes. Excuse the bashisms, coreutilsisms, and assume
we're working inside a tmpfs.

First we create the signify(1) key:

signify -G -c "something neat" -n -p some-new-key.pub -s some-new-key.sec

Now extract the private key and PEM encode it:

{
  echo -----BEGIN PRIVATE KEY-----
  {
    base64 -d <<<MC4CAQAwBQYDK2VwBCIEIA==
    tail -n 1 some-new-key.sec | base64 -d | tail -c 64 | head -c 32
  } | base64 | tr -d '\n'
  echo
  echo -----END PRIVATE KEY-----
} > some-new-key.sec.pem

Upload it to the HSM:

yubihsm-shell --connector yhusb:// -a put-asymmetric-key -i 1 -l some-new-key 
-d 1 -c sign-eddsa --informat=PEM --in=some-new-key.sec.pem

Delete the tmpfs private key:

rm some-new-key.sec.pem some-new-key.sec

Create a message:

echo hello world > msg

Extract the header from the public key:

tail -n 1 some-new-key.pub | base64 -d | head -c 10 > msg.sig.header.tmp

Create a signature with the HSM:

yubihsm-shell --connector yhusb:// -a sign-eddsa -i 1 -A ed25519 
--informat=binary --in=msg --outformat=binary --out=msg.sig.footer.tmp

Assemble the signature and clean up:

echo "untrusted comment: verify with some-new-key.pub" > msg.sig
cat msg.sig.header.tmp msg.sig.footer.tmp | base64 | tr -d '\n' >> msg.sig
echo >> msg.sig
cat msg >> msg.sig
rm msg.sig.header.tmp msg.sig.footer.tmp msg

Verify that the signature is valid:

signify -V -e -p some-new-key.pub -m msg


Hope this helps somebody.

Jason

Reply via email to