Skip to content

Instantly share code, notes, and snippets.

View joostd's full-sized avatar

Joost van Dijk joostd

  • Utrecht, the Netherlands
View GitHub Profile
@joostd
joostd / demo.py
Created June 20, 2026 06:32
WebAuthn demo in Python
import logging
import os
import secrets
from flask import Flask, request, jsonify, send_from_directory
from fido2.server import Fido2Server
from fido2.webauthn import (
PublicKeyCredentialRpEntity,
PublicKeyCredentialUserEntity,
ResidentKeyRequirement,
)
@joostd
joostd / ssh-macos-touchid.md
Created June 12, 2026 08:56
Use TouchID as an SSH key on macOS

Use TouchID as an SSH key on macOS

on macOS, an ssh-keychain SecurityKeyProvider is available that supports touchID.

TL;DR

The gist of this gist is:

$ sc_auth create-ctk-identity -l SSH -k p-256-ne -t bio -N username -E user@example.org
@joostd
joostd / symmetric_key_gcm.py
Created May 12, 2026 13:43
Extend python-yubihsm with AES in GCM mode, implemented with AES in ECB mode as primitive. No key meterial crosses the USB boundary.
# symmetric_key_gcm.py
#
# AES-GCM extension for the python-yubihsm SymmetricKey class.
#
# The YubiHSM 2 has no native GCM command, so this module builds GCM from
# the two primitives the device does expose:
#
# ENCRYPT_ECB – used to derive H (GHASH subkey) and to generate the
# CTR keystream blocks that encrypt/decrypt the payload.
# ENCRYPT_ECB – also used to encrypt the J0 counter block for the tag.
@joostd
joostd / register.py
Last active January 23, 2026 12:09
Tap and go with a FIDO security key
"""
Register a resident FIDO credential, using USB
Insert a FIDO2 security key in a USB port, and run with:
ykman script register.py
"""
from fido2.hid import CtapHidDevice
from fido2.ctap2 import Ctap2, ClientPin
from fido2.utils import sha256, hmac_sha256
from secrets import token_bytes
@joostd
joostd / Dockerfile
Created June 26, 2025 14:06
Use OpenSSL with YubiHSM2 via pkcs11-provider
FROM ubuntu:24.04
USER root
ENV YUBIHSM_PKCS11_CONF="/opt/yubihsm.conf"
WORKDIR /opt
COPY <<EOF yubihsm.conf
connector=http://host.docker.internal:12345
EOF
COPY <<EOF openssl.conf
HOME = .
openssl_conf = openssl_init
@joostd
joostd / gencsr.sh
Created January 16, 2025 13:33
Generate a CSR for an asymmetric key stored in a YubiHSM 2 with OpenSSL and yubihsm-shell
#!/bin/bash
# Generate a Certificate Signing Request (CSR) for an asymmetric key stored in a YubiHSM 2
# Usage:
# ./gencsr.sh <id> <cn>
#
# where <id> is the object ID of the asymmetric key,
# and <cn> is the Common Name of the subject DN in the generated CSR.
@joostd
joostd / check-yhsm-csr-attestation.sh
Last active January 29, 2025 12:25
Check if a YubiHSM 2 FIPS key attestation and CSR meet CA/B forum requirements for code signing
#!/bin/bash
# extend PATH with location of yubihsm-parse-attestation tool
PATH=$PATH:~/go/bin
# check for installed tools
command -v curl >/dev/null 2>&1 \
|| { echo >&2 "please install curl - see https://github.com/curl/curl"; exit 1; }
command -v openssl >/dev/null 2>&1 \
|| { echo >&2 "please install openssl - see https://github.com/openssl/openssl"; exit 1; }
@joostd
joostd / Dockerfile
Last active March 1, 2025 23:07
Demo for using a FIDO security key and ssh-agent to provide a form of SSH single sign-on (SSO), but require the security key to be inserted when signing in.
FROM ubuntu:22.04
ARG user
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
EXPOSE 22
RUN useradd -ms /bin/bash "$user"
COPY id_userca.pub /etc/ssh/user_ca.pub
RUN echo "TrustedUserCAKeys /etc/ssh/user_ca.pub" >> /etc/ssh/sshd_config
CMD ["/usr/sbin/sshd", "-D"]
@joostd
joostd / ykcs11_generate_rsa.c
Last active November 13, 2024 21:28
Generate an RSA key in slot 9a of a YubiKey using YKCS11
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pkcs11y.h>
/*
* Generate an RSA key in slot 9a of a YubiKey
@joostd
joostd / get-rsa-wrapped-key.sh
Last active September 3, 2024 18:35
Wrap and Unwrap keys using RSA_AES_KEY_WRAP_SHA256 with YubiHSM and OpenSSL
# generate and wrap target key on YubiHSM (firmware 2.4), unwrap using OpenSSL 3.3.1.
# Wrapping Algorithm = RSA_AES_KEY_WRAP_SHA256 (OAEP Padding - SHA256 digest + 256 bit AES-KWP)
HSM=yhusb://
TARGET_KEYID=0x1234
WRAP_KEYID=0xabcd
yubihsm="./yubihsm-shell -C $HSM -p password"
# generate target key
$yubihsm --action generate-asymmetric-key --object-id $TARGET_KEYID --domain 1 --capabilities exportable-under-wrap -A ecp256