Notes From The Dork Web

Migrating OpenSSH To Post-Quantum Cryptography

Far too many years ago I used to use RSA keys with SSH. Being paranoid I used 2048-bit RSA keys (as was the style at the time). When ed25519 support hit I waited some time before switching as I wanted it to be stable and I ran mixed systems for some time. There's a lot of scare mongering going around, and it's understandable to be fatigued from AI and tech companies crying wolf while vagueposting about cryptopocalyptic things happening, particularly when the advice from the guys that read your mail is a lot more nuanced.

For most people, upgrading operating systems will be sufficient. You don't need to regenerate keys, it's just configuration settings. This post is more about my migration, which I did sooner as I have systems where upgrading the OS or SSH version is more complex.

The bottom line is that if you really needed to migrate to PQC, you would've already been aware of that requirement. I'm a big fan of James Mickens' Mossad/Not-Mossad duality approach. If you're in the Not-Mossad camp, this post is for you.

You're not going to get hacked through this right now. The people that read your email think other people that also read your email might capture your SSH traffic for decryption later when and if quantum computers that can reliably factor numbers higher than 15 become affordable. Disgruntled employees are unlikely to build quantum computers to hack historical SSH sessions, but if the consequences of your SSH sessions becoming accessible to other people that read your email become high enough, you might want to migrate.

In the specific case of OpenSSH, post quantum algorithm support was introduced a couple of versions ago. Unlike switching from RSA to ec25519 this doesn't require you to recreate keys. You just need to ensure your clients and servers have supported versions, and configure your servers to use the new key exchange algorithms. You can also optionally configure algorithm preference on an all or per-host basis. There's a slightly larger processing hit on connection, but otherwise you're unlikely to notice a difference.

There are several reasons not to migrate:

  1. Tech companies are pushing this hard because they care about their security, not yours and you've made a decision based on what you deem acceptable risks for your infrastructure and data - i.e. their threat model is not your threat model.
  2. You have older computers or operating systems that won't play nice with the post-PQ algorithms.
  3. You're just tired about vagueposting and the constant crying wolf from AI and tech companies and want to get off the fucking ride until the bugs have been shaken out of the software.

All of these are valid, don't let anyone tell you they aren't. Migrating OpenSSH is a 5 minutes per host job, but it's your choice when and if you decide to do it. Unless you overwrite your OS's settings it'll probably be the default within a year of upgrades anyway.

Doing The Migration

Support for FIPS 203 Module-Lattice Key Enapsulation mechanism (ML-KEM) combined with X25519 ECDH was added to OpenSSH in 9.9. This is the standard recommended by FIPS and the one we'll use here. OpenSSH 10.0 makes mlkem768x25519-sha256 the default key exchange when both ends support it. We'll use this and add support for sntrup761x25519-sha512 while retaining support for curve25519-sha256 until everything's migrated.

Server Config

You can check your server SSH version by running sshd -V. If it says it's 9.9 or above, you're good to migrate. If not, you'll need to upgrade your SSH server version before you start.

OpenSSH configuration is stored in sshd_config, normally under /etc/ssh/. In sshd_config, set your KexAlgorithms value to the following:

KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512,curve25519-sha256

This determines which key exchange algorithms the server supports. The curve25519-sha256 algorithm isn't post-quantum but is worth keeping while testing. Once updated you can restart your SSH service. On OpenBSD this is doas rcctl reload sshd.

To verify this works, enter sshd -T | grep kexalgorithms as root, or via sudo/doas as appropriate. The kexalgorithms should match both options and order. When your last system is migrated, remove curve25519-sha256 to complete your migration.

Client Config

You can check your OpenSSH client version by running ssh -V from a terminal. As long as it's 9.9 or above you're good. You can verify your connection is using PQC algorithms by running ssh -v somehost where somehost is a server configured as above. Scroll up and look for the kex: algorithm: line, e.g.:

debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: sntrup761x25519-sha512

The above, from an older system of mine shows it negotiated the second algorithm in my list. This is why we have the 3 algorithms in place.

When an SSH client connects to the server, each sends a list of supported key exchange algorithms to the other. The server selects the first supported algorithm from the client's preference list. If you wanted to limit connections to specific algorithms, update either the systemwide ssh_config (normally under /etc/ssh/), or under ~/.ssh/config:

Host *
    KexAlgorithms mlkem768x25519-sha256

This can also be applied to individual host definitions. Be warned, setting this will stop your from connecting to systems without your chosen algorithms enabled.

Once you've completed your last migration, you can go back through and provided nothing used the non-PQ curve25519-sha256 kex algorithm, you can remove that and restart SSH again.

Strategies For Systems That Can't Be Migrated

Sometimes you'll have systems stuck on an older version of OpenSSH (such as routers), or for some reason can't be configured to use the new key exchange algorithms. Some strategies for these include:

  1. Block the SSH service from the Internet and use a jump/bastion host capable of supporting the new kex algorithms to access the system from there.
  2. Wrap your SSH connection using a PQ VPN such as Rosenpass (Vanilla Wireguard isn't PQ)
  3. Wrap your SSH connection using Stunnel 5.76+ built with OpenSSL 3.5 or later, and curves = X25519MLKEM768:X25519:P-256:P-384

Most importantly, don't let vagueposting, fear, and hype define your cryptographic architecture. Take the time to think about what you have, what you need to protect, from whom, and what options meet that criteria.

If someone who benefits from being a middleman on behalf of people who read your email tells you that they've seen some spicy shit they can't share details about, check if any of these were the same or adjacent to people who told you AI was supposed to have taken all our jobs right now and cryptography was meant to be over in November.

#linux #openbsd #openssh #selfhosting