summaryrefslogtreecommitdiff
path: root/src/lib/libtls/tls_config.c
diff options
context:
space:
mode:
authorjsing <>2018-02-10 04:57:35 +0000
committerjsing <>2018-02-10 04:57:35 +0000
commit351d578b1eacfbf1586f49fbbabbdb4e7efdbf5c (patch)
tree220397ac4d651f9ebaa0a028f81a800a6991a0eb /src/lib/libtls/tls_config.c
parent0865717e89a23608e9e870a932e575c2eee93965 (diff)
downloadopenbsd-351d578b1eacfbf1586f49fbbabbdb4e7efdbf5c.tar.gz
openbsd-351d578b1eacfbf1586f49fbbabbdb4e7efdbf5c.tar.bz2
openbsd-351d578b1eacfbf1586f49fbbabbdb4e7efdbf5c.zip
Move the keypair pubkey hash handling code to during config.
The keypair pubkey hash was being generated and set in the keypair when the TLS context was being configured. This code should not be messing around with the keypair contents, since it is part of the config (and not the context). Instead, generate the pubkey hash and store it in the keypair when the certificate is configured. This means that we are guaranteed to have the pubkey hash and as a side benefit, we identify bad certificate content when it is provided, instead of during the context configuration. ok beck@
Diffstat (limited to 'src/lib/libtls/tls_config.c')
-rw-r--r--src/lib/libtls/tls_config.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c
index 6dfebfaebf..2dab4fc7d8 100644
--- a/src/lib/libtls/tls_config.c
+++ b/src/lib/libtls/tls_config.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_config.c,v 1.48 2018/02/10 04:41:24 jsing Exp $ */ 1/* $OpenBSD: tls_config.c,v 1.49 2018/02/10 04:57:35 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -351,12 +351,13 @@ tls_config_add_keypair_mem_internal(struct tls_config *config, const uint8_t *ce
351 351
352 if ((keypair = tls_keypair_new()) == NULL) 352 if ((keypair = tls_keypair_new()) == NULL)
353 return (-1); 353 return (-1);
354 if (tls_keypair_set_cert_mem(keypair, cert, cert_len) != 0) 354 if (tls_keypair_set_cert_mem(keypair, &config->error, cert, cert_len) != 0)
355 goto err; 355 goto err;
356 if (tls_keypair_set_key_mem(keypair, key, key_len) != 0) 356 if (tls_keypair_set_key_mem(keypair, &config->error, key, key_len) != 0)
357 goto err; 357 goto err;
358 if (staple != NULL && 358 if (staple != NULL &&
359 tls_keypair_set_ocsp_staple_mem(keypair, staple, staple_len) != 0) 359 tls_keypair_set_ocsp_staple_mem(keypair, &config->error, staple,
360 staple_len) != 0)
360 goto err; 361 goto err;
361 362
362 tls_config_keypair_add(config, keypair); 363 tls_config_keypair_add(config, keypair);
@@ -431,7 +432,8 @@ int
431tls_config_set_cert_mem(struct tls_config *config, const uint8_t *cert, 432tls_config_set_cert_mem(struct tls_config *config, const uint8_t *cert,
432 size_t len) 433 size_t len)
433{ 434{
434 return tls_keypair_set_cert_mem(config->keypair, cert, len); 435 return tls_keypair_set_cert_mem(config->keypair, &config->error,
436 cert, len);
435} 437}
436 438
437int 439int
@@ -592,7 +594,8 @@ int
592tls_config_set_key_mem(struct tls_config *config, const uint8_t *key, 594tls_config_set_key_mem(struct tls_config *config, const uint8_t *key,
593 size_t len) 595 size_t len)
594{ 596{
595 return tls_keypair_set_key_mem(config->keypair, key, len); 597 return tls_keypair_set_key_mem(config->keypair, &config->error,
598 key, len);
596} 599}
597 600
598static int 601static int
@@ -789,7 +792,8 @@ int
789tls_config_set_ocsp_staple_mem(struct tls_config *config, const uint8_t *staple, 792tls_config_set_ocsp_staple_mem(struct tls_config *config, const uint8_t *staple,
790 size_t len) 793 size_t len)
791{ 794{
792 return tls_keypair_set_ocsp_staple_mem(config->keypair, staple, len); 795 return tls_keypair_set_ocsp_staple_mem(config->keypair, &config->error,
796 staple, len);
793} 797}
794 798
795int 799int