Skip to content

Commit 707316f

Browse files
committed
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. Implementation-wise, keys are encrypted "shielded" when loaded and then automatically and transparently unshielded when used for signatures or when being saved/serialised. Hopefully we can remove this in a few years time when computer architecture has become less unsafe. been in snaps for a bit already; thanks deraadt@ ok dtucker@ deraadt@
1 parent 9ebeca6 commit 707316f

11 files changed

Lines changed: 324 additions & 41 deletions

File tree

‎usr.bin/ssh/authfd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: authfd.c,v 1.113 2018/12/27 23:02:11 djm Exp $ */
1+
/* $OpenBSD: authfd.c,v 1.114 2019/06/21 04:21:04 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -421,7 +421,7 @@ encode_constraints(struct sshbuf *m, u_int life, u_int confirm, u_int maxsign)
421421
* This call is intended only for use by ssh-add(1) and like applications.
422422
*/
423423
int
424-
ssh_add_identity_constrained(int sock, const struct sshkey *key,
424+
ssh_add_identity_constrained(int sock, struct sshkey *key,
425425
const char *comment, u_int life, u_int confirm, u_int maxsign)
426426
{
427427
struct sshbuf *msg;

‎usr.bin/ssh/authfd.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: authfd.h,v 1.44 2018/07/12 04:35:25 djm Exp $ */
1+
/* $OpenBSD: authfd.h,v 1.45 2019/06/21 04:21:04 djm Exp $ */
22

33
/*
44
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -29,7 +29,7 @@ void ssh_close_authentication_socket(int sock);
2929
int ssh_lock_agent(int sock, int lock, const char *password);
3030
int ssh_fetch_identitylist(int sock, struct ssh_identitylist **idlp);
3131
void ssh_free_identitylist(struct ssh_identitylist *idl);
32-
int ssh_add_identity_constrained(int sock, const struct sshkey *key,
32+
int ssh_add_identity_constrained(int sock, struct sshkey *key,
3333
const char *comment, u_int life, u_int confirm, u_int maxsign);
3434
int ssh_remove_identity(int sock, struct sshkey *key);
3535
int ssh_update_card(int sock, int add, const char *reader_id,

‎usr.bin/ssh/krl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
*/
1616

17-
/* $OpenBSD: krl.c,v 1.42 2018/09/12 01:21:34 djm Exp $ */
17+
/* $OpenBSD: krl.c,v 1.43 2019/06/21 04:21:04 djm Exp $ */
1818

1919
#include <sys/types.h>
2020
#include <sys/tree.h>
@@ -730,7 +730,7 @@ revoked_certs_generate(struct revoked_certs *rc, struct sshbuf *buf)
730730

731731
int
732732
ssh_krl_to_blob(struct ssh_krl *krl, struct sshbuf *buf,
733-
const struct sshkey **sign_keys, u_int nsign_keys)
733+
struct sshkey **sign_keys, u_int nsign_keys)
734734
{
735735
int r = SSH_ERR_INTERNAL_ERROR;
736736
struct revoked_certs *rc;

‎usr.bin/ssh/krl.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
*/
1616

17-
/* $OpenBSD: krl.h,v 1.6 2018/09/12 01:21:34 djm Exp $ */
17+
/* $OpenBSD: krl.h,v 1.7 2019/06/21 04:21:04 djm Exp $ */
1818

1919
#ifndef _KRL_H
2020
#define _KRL_H
@@ -56,7 +56,7 @@ int ssh_krl_revoke_key_sha1(struct ssh_krl *krl, const u_char *p, size_t len);
5656
int ssh_krl_revoke_key_sha256(struct ssh_krl *krl, const u_char *p, size_t len);
5757
int ssh_krl_revoke_key(struct ssh_krl *krl, const struct sshkey *key);
5858
int ssh_krl_to_blob(struct ssh_krl *krl, struct sshbuf *buf,
59-
const struct sshkey **sign_keys, u_int nsign_keys);
59+
struct sshkey **sign_keys, u_int nsign_keys);
6060
int ssh_krl_from_blob(struct sshbuf *buf, struct ssh_krl **krlp,
6161
const struct sshkey **sign_ca_keys, size_t nsign_ca_keys);
6262
int ssh_krl_check_key(struct ssh_krl *krl, const struct sshkey *key);

‎usr.bin/ssh/ssh-agent.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ssh-agent.c,v 1.235 2019/06/14 03:51:47 djm Exp $ */
1+
/* $OpenBSD: ssh-agent.c,v 1.236 2019/06/21 04:21:04 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -408,7 +408,10 @@ process_add_identity(SocketEntry *e)
408408
error("%s: decode private key: %s", __func__, ssh_err(r));
409409
goto err;
410410
}
411-
411+
if ((r = sshkey_shield_private(k)) != 0) {
412+
error("%s: shield private key: %s", __func__, ssh_err(r));
413+
goto err;
414+
}
412415
while (sshbuf_len(e->request)) {
413416
if ((r = sshbuf_get_u8(e->request, &ctype)) != 0) {
414417
error("%s: buffer error: %s", __func__, ssh_err(r));

‎usr.bin/ssh/ssh-keygen.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ssh-keygen.c,v 1.331 2019/06/06 05:13:13 otto Exp $ */
1+
/* $OpenBSD: ssh-keygen.c,v 1.332 2019/06/21 04:21:04 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1633,7 +1633,7 @@ load_pkcs11_key(char *path)
16331633

16341634
/* Signer for sshkey_certify_custom that uses the agent */
16351635
static int
1636-
agent_signer(const struct sshkey *key, u_char **sigp, size_t *lenp,
1636+
agent_signer(struct sshkey *key, u_char **sigp, size_t *lenp,
16371637
const u_char *data, size_t datalen,
16381638
const char *alg, u_int compat, void *ctx)
16391639
{

‎usr.bin/ssh/sshconnect.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshconnect.c,v 1.315 2019/05/03 03:27:38 dtucker Exp $ */
1+
/* $OpenBSD: sshconnect.c,v 1.316 2019/06/21 04:21:04 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1361,7 +1361,7 @@ ssh_local_cmd(const char *args)
13611361
}
13621362

13631363
void
1364-
maybe_add_key_to_agent(char *authfile, const struct sshkey *private,
1364+
maybe_add_key_to_agent(char *authfile, struct sshkey *private,
13651365
char *comment, char *passphrase)
13661366
{
13671367
int auth_sock = -1, r;

‎usr.bin/ssh/sshconnect.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshconnect.h,v 1.37 2019/01/19 21:36:38 djm Exp $ */
1+
/* $OpenBSD: sshconnect.h,v 1.38 2019/06/21 04:21:05 djm Exp $ */
22

33
/*
44
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -52,4 +52,4 @@ void ssh_userauth2(struct ssh *ssh, const char *, const char *,
5252

5353
int ssh_local_cmd(const char *);
5454

55-
void maybe_add_key_to_agent(char *, const struct sshkey *, char *, char *);
55+
void maybe_add_key_to_agent(char *, struct sshkey *, char *, char *);

‎usr.bin/ssh/sshd.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshd.c,v 1.535 2019/06/06 05:13:13 otto Exp $ */
1+
/* $OpenBSD: sshd.c,v 1.536 2019/06/21 04:21:05 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1286,7 +1286,7 @@ set_process_rdomain(struct ssh *ssh, const char *name)
12861286

12871287
static void
12881288
accumulate_host_timing_secret(struct sshbuf *server_cfg,
1289-
const struct sshkey *key)
1289+
struct sshkey *key)
12901290
{
12911291
static struct ssh_digest_ctx *ctx;
12921292
u_char *hash;
@@ -1598,6 +1598,12 @@ main(int ac, char **av)
15981598
&key, NULL)) != 0 && r != SSH_ERR_SYSTEM_ERROR)
15991599
do_log2(ll, "Unable to load host key \"%s\": %s",
16001600
options.host_key_files[i], ssh_err(r));
1601+
if (r == 0 && (r = sshkey_shield_private(key)) != 0) {
1602+
do_log2(ll, "Unable to shield host key \"%s\": %s",
1603+
options.host_key_files[i], ssh_err(r));
1604+
sshkey_free(key);
1605+
key = NULL;
1606+
}
16011607
if ((r = sshkey_load_public(options.host_key_files[i],
16021608
&pubkey, NULL)) != 0 && r != SSH_ERR_SYSTEM_ERROR)
16031609
do_log2(ll, "Unable to load host key \"%s\": %s",

0 commit comments

Comments
 (0)