summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2018-04-07 16:35:35 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2018-04-07 16:35:35 +0000
commitdbdf68a3798295a0cafa4109305a2ef37633c6ed (patch)
treed1f922d1e464a6ac934a2f9470fee68c5aa2961c
parent85174bf88c0fe3675b3125c2254f8d3389babca0 (diff)
Correct tls_config_clear_keys() behaviour.
Previously this incorrectly called tls_keypair_clear(), which results in the private key being cleared, along with the certificate, OCSP staple and pubkey hash. This breaks OCSP stapling if tls_config_clear_keys() is called following tls_configure(), as is done by httpd. Fix this by calling tls_keypair_clear_key() so that only the private key is cleared, leaving the other public data untouched. While here, remove tls_keypair_clear() and fold the necessary parts into tls_keypair_free(). ok beck@
-rw-r--r--lib/libtls/tls_config.c7
-rw-r--r--lib/libtls/tls_internal.h4
-rw-r--r--lib/libtls/tls_keypair.c37
3 files changed, 18 insertions, 30 deletions
diff --git a/lib/libtls/tls_config.c b/lib/libtls/tls_config.c
index d32176fe6e1..07019252a7d 100644
--- a/lib/libtls/tls_config.c
+++ b/lib/libtls/tls_config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls_config.c,v 1.51 2018/03/20 15:40:10 jsing Exp $ */
+/* $OpenBSD: tls_config.c,v 1.52 2018/04/07 16:35:34 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -189,10 +189,7 @@ tls_config_clear_keys(struct tls_config *config)
struct tls_keypair *kp;
for (kp = config->keypair; kp != NULL; kp = kp->next)
- tls_keypair_clear(kp);
-
- tls_config_set_ca_mem(config, NULL, 0);
- tls_config_set_crl_mem(config, NULL, 0);
+ tls_keypair_clear_key(kp);
}
int
diff --git a/lib/libtls/tls_internal.h b/lib/libtls/tls_internal.h
index 0d7e2289d39..b236204e814 100644
--- a/lib/libtls/tls_internal.h
+++ b/lib/libtls/tls_internal.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls_internal.h,v 1.71 2018/03/19 16:34:47 jsing Exp $ */
+/* $OpenBSD: tls_internal.h,v 1.72 2018/04/07 16:35:34 jsing Exp $ */
/*
* Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org>
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
@@ -199,7 +199,7 @@ int tls_set_mem(char **_dest, size_t *_destlen, const void *_src,
int tls_set_string(const char **_dest, const char *_src);
struct tls_keypair *tls_keypair_new(void);
-void tls_keypair_clear(struct tls_keypair *_keypair);
+void tls_keypair_clear_key(struct tls_keypair *_keypair);
void tls_keypair_free(struct tls_keypair *_keypair);
int tls_keypair_set_cert_file(struct tls_keypair *_keypair,
struct tls_error *_error, const char *_cert_file);
diff --git a/lib/libtls/tls_keypair.c b/lib/libtls/tls_keypair.c
index 03e7f4ad76d..a98e5c2e7e4 100644
--- a/lib/libtls/tls_keypair.c
+++ b/lib/libtls/tls_keypair.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls_keypair.c,v 1.5 2018/02/10 04:57:35 jsing Exp $ */
+/* $OpenBSD: tls_keypair.c,v 1.6 2018/04/07 16:35:34 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -29,14 +29,6 @@ tls_keypair_new(void)
return calloc(1, sizeof(struct tls_keypair));
}
-static void
-tls_keypair_clear_key(struct tls_keypair *keypair)
-{
- freezero(keypair->key_mem, keypair->key_len);
- keypair->key_mem = NULL;
- keypair->key_len = 0;
-}
-
static int
tls_keypair_pubkey_hash(struct tls_keypair *keypair, struct tls_error *error)
{
@@ -64,6 +56,14 @@ tls_keypair_pubkey_hash(struct tls_keypair *keypair, struct tls_error *error)
return (rv);
}
+void
+tls_keypair_clear_key(struct tls_keypair *keypair)
+{
+ freezero(keypair->key_mem, keypair->key_len);
+ keypair->key_mem = NULL;
+ keypair->key_len = 0;
+}
+
int
tls_keypair_set_cert_file(struct tls_keypair *keypair, struct tls_error *error,
const char *cert_file)
@@ -117,25 +117,16 @@ tls_keypair_set_ocsp_staple_mem(struct tls_keypair *keypair,
}
void
-tls_keypair_clear(struct tls_keypair *keypair)
-{
- struct tls_error error;
-
- tls_keypair_set_cert_mem(keypair, &error, NULL, 0);
- tls_keypair_set_key_mem(keypair, &error, NULL, 0);
- tls_keypair_set_ocsp_staple_mem(keypair, &error, NULL, 0);
-
- free(keypair->pubkey_hash);
- keypair->pubkey_hash = NULL;
-}
-
-void
tls_keypair_free(struct tls_keypair *keypair)
{
if (keypair == NULL)
return;
- tls_keypair_clear(keypair);
+ tls_keypair_clear_key(keypair);
+
+ free(keypair->cert_mem);
+ free(keypair->ocsp_staple);
+ free(keypair->pubkey_hash);
free(keypair);
}