
Agent SSH qui crée et gère des clés scellées par TPM pour une authentification liée au matériel, prenant en charge la génération de clés, l'importation, le wrapping, la protection par PIN, et le repli proxy.
ssh-tpm-agent est un agent compatible avec ssh-agent qui permet de créer des clés
par le Trusted Platform Module (TPM) pour l'authentification auprès de serveurs ssh.
Les clés scellées TPM sont des clés privées créées à l'intérieur du Trusted Platform Module
(TPM) et scellées dans des fichiers avec le suffixe .tpm. Elles sont liées au matériel sur lequel
elles sont produites et ne peuvent pas être transférées vers d'autres machines.
Cela vous permet d'utiliser un client natif au lieu de devoir charger latéralement des bibliothèques PKCS11 existantes dans le ssh-agent et/ou le client ssh.
Le projet utilise les TPM 2.0 Key Files
implémentés via le projet go-tpm-keyfiles.
ssh-agent fonctionnel.ssh-agent pour les replis.Au lieu d'utiliser directement le TPM, vous pouvez utiliser --swtpm ou export SSH_TPM_AGENT_SWTPM=1 pour créer une identité adossée à
swtpm qui sera stockée sous
/var/tmp/ssh-tpm-agent.
Notez que swtpm ne fournit aucune propriété de sécurité et ne doit être utilisé que pour
les tests.
La façon la plus simple d'installer ce plugin est d'exécuter ce qui suit :
go install github.com/foxboron/ssh-tpm-agent/cmd/...@latest
Vous pouvez également télécharger les binaires précompilés.
# Create key
$ ssh-tpm-keygen
Generating a sealed public/private ecdsa key pair.
Enter file in which to save the key (/home/fox/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/fox/.ssh/id_ecdsa.tpm
Your public key has been saved in /home/fox/.ssh/id_ecdsa.pub
The key fingerprint is:
SHA256:NCMJJ2La+q5tGcngQUQvEOJP3gPH8bMP98wJOEMV564
The key's randomart image is the color of television, tuned to a dead channel.
$ cat /home/fox/.ssh/id_ecdsa.pub
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOTOsMXyjTc1wiQSKhRiNhKFsHJNLzLk2r4foXPLQYKR0tuXIBMTQuMmc7OiTgNMvIjMrcb9adgGdT3s+GkNi1g=
# Using the socket
$ ssh-tpm-agent -l /var/tmp/tpm.sock
$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"
$ ssh [email protected]
Remarque : Pour ssh-tpm-agent, vous pouvez spécifier le mot de passe propriétaire du TPM à l'aide des options de ligne de commande -o ou --owner-password, qui sont préférables. Vous pouvez également utiliser la variable d'environnement SSH_TPM_AGENT_OWNER_PASSWORD.
Utile si vous souhaitez sauvegarder la clé vers un stockage sécurisé distant tout en utilisant la clé au quotidien depuis le TPM.
# Create a key, or use an existing one
$ ssh-keygen -t ecdsa -f id_ecdsa
Generating public/private ecdsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_ecdsa
Your public key has been saved in id_ecdsa.pub
The key fingerprint is:
SHA256:bDn2EpX6XRX5ADXQSuTq+uUyia/eV3Z6MW+UtxjnXvU fox@framework
The key's randomart image is:
+---[ECDSA 256]---+
| .+=o..|
| o. oo.|
| o... .o|
| . + .. ..|
| S . . o|
| o * . oo=*|
| ..+.oo=+E|
| .++o...o=|
| .++++. .+ |
+----[SHA256]-----+
# Import the key
$ ssh-tpm-keygen --import id_ecdsa
Sealing an existing public/private ecdsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_ecdsa.tpm
The key fingerprint is:
SHA256:bDn2EpX6XRX5ADXQSuTq+uUyia/eV3Z6MW+UtxjnXvU
The key's randomart image is the color of television, tuned to a dead channel.
Les services activés par socket vous permettent de démarrer ssh-tpm-agent lorsque votre système en a besoin.
# Using the socket
$ ssh-tpm-agent --install-user-units
Installed /home/fox/.config/systemd/user/ssh-tpm-agent.socket
Installed /home/fox/.config/systemd/user/ssh-tpm-agent.service
Enable with: systemctl --user enable --now ssh-tpm-agent.socket
$ systemctl --user enable --now ssh-tpm-agent.socket
$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"
$ ssh [email protected]
# Start the usual ssh-agent
$ eval $(ssh-agent)
# Create a strong RSA key
$ ssh-keygen -t rsa -b 4096 -f id_rsa -C ssh-agent
...
The key fingerprint is:
SHA256:zLSeyU/6NKHGEvyZLA866S1jGqwdwdAxRFff8Z2N1i0 ssh-agent
$ ssh-add id_rsa
Identity added: id_rsa (ssh-agent)
# Print looonnggg key
$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc[...]8TWynQ== ssh-agent
# Create key on the TPM
$ ssh-tpm-keygen -C ssh-tpm-agent
Generating a sealed public/private ecdsa key pair.
Enter file in which to save the key (/home/fox/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Confirm passphrase:
Your identification has been saved in /home/fox/.ssh/id_ecdsa.tpm
Your public key has been saved in /home/fox/.ssh/id_ecdsa.pub
The key fingerprint is:
SHA256:PoQyuzOpEBLqT+xtP0dnvyBVL6UQTiQeCWN/EXIxPOo
The key's randomart image is the color of television, tuned to a dead channel.
# Start ssh-tpm-agent with a proxy socket
$ ssh-tpm-agent -A "${SSH_AUTH_SOCK}" &
$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"
# ssh-tpm-agent is proxying the keys from ssh-agent
$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc[...]8TWynQ== ssh-agent
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo[...]q4whro= ssh-tpm-agent
$ ssh-tpm-agent --no-load &
2023/08/12 13:40:50 Listening on /run/user/1000/ssh-tpm-agent.sock
$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"
$ ssh-add -L
The agent has no identities.
$ ssh-tpm-add $HOME/.ssh/id_ecdsa.tpm
Identity added: /home/user/.ssh/id_ecdsa.tpm
$ ssh-add -L
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJCxqisGa9IUNh4Ik3kwihrDouxP7S5Oun2hnzTvFwktszaibJruKLJMxHqVYnNwKD9DegCNwUN1qXCI/UOwaSY= test
Côté client, créez une clé primaire sous une hiérarchie. Cet exemple utilisera la hiérarchie owner avec une SRK.
Le fichier de sortie srk.pem doit être transféré vers l'extrémité distante qui
crée la clé. Cela pourrait être fait dans le cadre du provisionnement du client.
$ tpm2_createprimary -C o -G ecc -g sha256 -c prim.ctx -a 'restricted|decrypt|fixedtpm|fixedparent|sensitivedataorigin|userwithauth|noda' -f pem -o srk.pem
À l'extrémité distante, nous créons une clé ssh p256, sans mot de passe, et l'enveloppons avec
ssh-tpm-keygen à l'aide du srk.pem provenant du côté client.
$ ssh-keygen -t ecdsa -b 256 -N "" -f ./ecdsa.key
# OR with openssl
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:prime256v1 -out ecdsa.key
# Wrap with ssh-tpm-keygen
$ ssh-tpm-keygen --wrap-with srk.pub --wrap ecdsa.key -f wrapped_id_ecdsa
Côté client, nous pouvons déballer wrapped_id_ecdsa en une clé chargeable.
$ ssh-tpm-keygen --import ./wrapped_id_ecdsa.tpm -f id_ecdsa.tpm
$ ssh-tpm-add id_ecdsa.tpm
ssh-tpm-agent prend également en charge le stockage des clés d'hôte dans le TPM.