I deleted all my SSH keys again
In some rather unfortunate timing, I chose last month to migrate all of my SSH keys to use ones stored in YubiKeys, TPMs, or Apple’s Secure Enclave.
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
In some rather unfortunate timing, I chose last month to migrate all of my SSH keys to use ones stored in YubiKeys, TPMs, or Apple’s Secure Enclave.
These are all non-quantum-safe ed25519 keys.
Today the NSA released an advisory recommending an immediate transition to post-quantum cryptography.
There are some interesting parts to this advisory that stand out from previous generic PQC recommendations.
Firstly, the NSA are referencing specific disclosures directly affecting current crypto systems:
Frontier [AI] companies have engaged with the U.S. government to responsibly disclose recent discoveries that impact the security of some cryptographic systems currently in use. This threat, alongside the existing concerns about quantum computing, presents a significant threat to cryptographic systems protecting sensitive information.
Though it hints at more of a store-and-decrypt attack rather than immediately available capability:
Adversaries are already collecting encrypted information to decrypt once the capabilities become available.
But since this advice is a bit of a shift from what the NSA has previously recommended – and thinking about how slow standards like FIPS are to update to newer algorithms – this feels quite out of character. As Filippo Valsorda notes:
The NSA wants you to move to PQC in such a rush that it’s saying explicitly, against all its previous recommendations, that you can use the X25519MLKEM768 hybrid key exchange since it’s the most widely available solution.
So it seems like this is an advisory it would be wise to take seriously.
Unfortunately all of the keys I minted using my hardware enclaves as part of the previous post are not PQC-ready. Yubico currently have YubiKeys with PQC in private beta but I don’t think they’re going to be generally available until next year.
Recent versions of OpenSSH support post-quantum crypto for key exchange using traditional on-disk keys for now though.
I guess it’s time to cycle all my keys again.
Note that following along with this requires at least OpenSSH 10.6. I’ve tested this on Alpine Edge and Fedora 45, but you may struggle on slower moving distributions. I need to work out what to do about my FreeBSD, macOS and Debian hosts.
OpenSSH technically added experimental support for post-quantum ML-DSA-44 keys in 10.4 under the name ssh-mldsa44-ed25519@openssh.com, and some guides online still reference this name.
The name was standardised as ssh-mldsa44-ed25519 (no suffix) in 10.6, but OpenSSH seems to treat these as two separate algorithms so, for example, a macOS 27 client running 10.5 which is only aware of ssh-mldsa44-ed25519@openssh.com cannot auth to a Fedora 45 server running 10.6 which is only aware of ssh-mldsa44-ed25519.
I don’t think there’s any solution to this beyond waiting for your distro to upgrade to 10.6, or installing OpenSSH 10.6+ manually.
We can generate a key which layers the existing classical ed25519 protection with post-quantum resistant ML-DSA-44.
ssh-keygen -t mldsa44-ed25519 -f ~/.ssh/id_mldsa44-ed25519
After this, we are left with a public key in a id_mldsa44-ed25519.pub file in the location we specified with -f. We can use this with ssh-key-add or add it directly to authorized_keys on a destination host.
In the future, I’m sure PQC keys will “just work” with OpenSSH but for now I had to be quite explicit about wanting to use the key, and about allowing the server to use PQC also, adding these lines to my ~/.ssh/config:
Host blog.infected.systems IdentityFile ~/.ssh/id_mldsa44-ed25519 PubkeyAcceptedAlgorithms ^ssh-mldsa44-ed25519
Server: Generate PQC key
Generating a PQC client key doesn’t automatically mean it can be used when connecting to our server, as OpenSSH still does not automatically generate mldsa44-ed25519 host keys yet.
When trying to SSH into a stock Fedora 45 host, I get:
debug1: Skipping ssh-mldsa44-ed25519 key /home/user/.ssh/id_mldsa44-ed25519 - corresponding algorithm not in PubkeyAcceptedAlgorithms
To resolve this, we can generate a mldsa44-ed25519 host key on the SSH server:
ssh-keygen -t mldsa44-ed25519 -f /etc/ssh/ssh_host_mldsa44_ed25519_key -N ""
The -N above stands for New Passphrase and is blank since we want to generate a key for unattended server authentication.
We still need to tell the OpenSSH server to use the PQC host key we just generated. Create an SSH server drop-in config with:
nano /etc/ssh/sshd_config.d/00-pqc.conf
In this file, we can now enable ML-DSA-44 as an offered algorithm in HostKeyAlgorithms, and specify that we accept ML-DSA-44 public keys:
HostKeyAlgorithms ^ssh-mldsa44-ed25519 PubkeyAcceptedAlgorithms ^ssh-mldsa44-ed25519
Note that the ^ in front of the algorithm name means we’re just adding the algorithm to the front of the default list of accepted algorithms rather than overriding the list.
Also note that the 00- prefix on the drop-in file is also deliberate. On Fedora/Red Hat systems we want to ensure this file is read before 40-redhat-crypto-policies.conf.
After a restart of the SSH daemon on the server, we ought to be able to connect with the PQC key:
debug1: Offering public key: /home/user/.ssh/id_mldsa44-ed25519 MLDSA44-ED25519 SHA256:ZAh94rqrTo/r29erDDrAJMmrKhsn0ItigtganJPNswM explicit debug1: Server accepts key: /home/user/.ssh/id_mldsa44-ed25519 MLDSA44-ED25519 SHA256:ZAh94rqrTo/r29erDDrAJMmrKhsn0ItigtganJPNswM explicit Authenticated to blog.infected.systems ([2a11:f2c0:ffcc::beef]:22) using "publickey".
We can also check the server config to ensure the config has applied:
sudo sshd -T | grep -iE '^(hostkey|hostkeyalgorithms|pubkeyacceptedalgorithms)'
If our changes have worked, this should show ssh-mldsa44-ed25519 at the start of both the HostKeyAlgorithms and PubkeyAcceptedAlgorithms. Our new ssh_host_mldsa44_ed25519_key ought to be loaded along with the other HostKeys. We didn’t need to specify this directly since OpenSSH loads these files using a wildcard and we matched the existing naming scheme when creating the new key.
This server will now accept authentication using PQC, but will still work as before for any classic keys we were already using.
Because of the intensity of the wording in the advisory above, it’s probably a good idea to restrict the server to only use PQC.
Before doing this obviously make sure that you’re happy that all of your client devices are capable of PQC-based key auth.
To do this, we can create the same 00-pqc.conf file but be a bit more restrictive with the options we choose. Note the lack of ^ before the algorithm names, and the new HostKey option which uses a specific path on disk meaning OpenSSH will load only the PQC key (overrides the default HostKey option, which uses a wildcard to pick up any keys on disk):
HostKey /etc/ssh/ssh_host_mldsa44_ed25519_key HostKeyAlgorithms ssh-mldsa44-ed25519 PubkeyAcceptedAlgorithms ssh-mldsa44-ed25519
The output of our config debug command before now confirms a single approved ML-DSA-44-based auth method for each config option:
$ sudo sshd -T | grep -iE '^(hostkey|hostkeyalgorithms|pubkeyacceptedalgorithms)' HostKeyAgent none HostKeyAlgorithms ssh-mldsa44-ed25519 PubkeyAcceptedAlgorithms ssh-mldsa44-ed25519 HostKey /etc/ssh/ssh_host_mldsa44_ed25519_key
Hopefully this helps some folk. I put this post together fairly quickly so if anyone has suggestions or recommendations please do let me know!
I like to add the host keys for SSH servers into DNS as SSHFP records. This helps protect against MITM style attacks since SSH uses a trust-on-first-use model for host keys and I switch between a lot of client devices so there’s a lot of “first use”. Unfortunately it doesn’t seem like SSHFP records are supported yet for ML-DSA-44 host keys.
I also have Caddy in front of this blog handling TLS termination. It does fully support PQC and if your browser is up-to-date you probably are reading this page using X25519MLKEM768. But because of limitations in upstream Go crypto libraries, it doesn’t seem possible yet to force Caddy into using only PQC. Going PQC-only should be possible in nginx though based on some of the notes in this guide.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。
