SSH Certificates and Keys in Apple T2 On-host

Key Takeaways

Introduction

Over the past days I have been going down a deep, deep rabbit hole of SSH proxy jumping and SSH certificates combined with smartcards.

After playing around with smart cards for SSH, I recognized that not only external smart cards such as the Yubikey or Nitrokey is a possible lane to go down.

New Apple devices comes with a security chip called T2 built-in. This chip is known to host something Apple has named Secure Enclave [1]. In the Secure Enclave you can store secret keys.

A secure enclave will not serve as an equally secure solution as with external smart cards, but it is a better balance for usability.

The T2 is permanently stored in hardware on one host only, so the access needs to be signed on a per-host basis. In such I would say the T2 and external smart cards complement each other depending on situation.

Always having the key available will bring two additional vulnerabilities:

With a central pubkey directory tied to an identity (automated), the T2 can be of better use for an enterprise setup.

Setting up a Private Key in Secure Enclave

While fiddling around I found Secretive on Github [2].

The short and easy setup are:

$ brew cask install secretive
$ echo "export SSH_AUTH_SOCK=/Users/[USERNAME]/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh" >> ~/.zshrc
$ source ~/.zshrc

A keypair can now be generated in the secure enclave by opening the Secretive app and pressing the + (perhaps there is some way to use ssh-keygen as well?)

The public key of the curve generated on-chip is available in a container directory on disk. Check out the Public Key Path in Secretive to find where.

Using the trick we found in our recent venture into using smart cards for signing the key, we can used PCKS#11 without compromising security [3]. In this case I use a Nitrokey:

$ brew cask install opensc
$ PKCS11_MODULE_PATH=/usr/local/lib/opensc-pkcs11.so
$ ssh-keygen -D $PKCS11_MODULE_PATH -e > ca.pub
$ ssh-keygen -D $PKCS11_MODULE_PATH -s ca.pub -I example -n zone-web -V +1h -z 1 id_ecdsa.pub
> Enter PIN for 'OpenPGP card (User PIN)': *****
> Signed user key id_ecdsa-cert.pub: id "example" serial 1 for zone-web valid from 2020-10-14T20:26:00 to 2020-10-14T21:27:51

$ cp id_ecdsa-cert.pub ~/.ssh/

If you now try to ssh into a server using the given certificate authority as shown in the SSH-CA post [3], access should be granted with a fingerprint.

A Word of Caution

The T2 has some vulnerabilities shown recently. Make sure to include these in your risk assessment of using it. If you won't go down the smart card route it will still be better than storing the key on disk.

[1] https://support.apple.com/guide/security/secure-enclave-overview-sec59b0b31ff/web
[2] https://github.com/maxgoedjen/secretive
[3] https://secdiary.com/2020-10-13-ssh-ca-proxyjump.html