Now OpenSSH encrypts secret keys in memory against Side-Channel attacks.
Many experts demonstrated variants of side-channel attacks against OpenSSH application installed on targeted systems. In the attack scenario, a process owned by an unprivileged attacker exploits memory read vulnerabilities to steal secret SSH private keys from the memory of the target system.
That’s possible because OpenSSH has an agent that keeps a copy of your SSH key in the memory so that you don’t have to type your passphrase every time you want to connect to the same remote server.
To prevent such kind of attacks, modern operating systems by default store sensitive data in the kernel memory that is not accessible by user-level privileged processes.
Anyway, SSH keys are managed on the RAM or CPU memory in plaintext format, allowing attackers to access them with side channel attacks.
The latest version of the OpenSSH addresses this problem by implementing the encryption of the private keys before storing them into the system memory.
“Add protection for private keys at rest in RAM against speculation and memory sidechannel attacks like Spectre, Meltdown, Rowhammer and Rambleed. This change encrypts private keys when they are not in use with a symmetic key that is derived from a relatively large “prekey” consisting of random data (currently 16KB). Attackers must recover the entire prekey with high accuracy before they can attempt to decrypt the shielded private key, but the current generation of attacks have bit error rates that, when applied cumulatively to the entire prekey, make this unlikely.” reads the security advisory published by OpenSSH developer Damien Miller.
“Implementation-wise, keys are encrypted “shielded” when loaded and then automatically and transparently unshielded when used for signatures or when being saved/serialised.”
Miller explained that OpenSSH plans to remove this protection against side-channel attacks in a few years when computer architecture becomes less unsafe.