summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_lib.c
diff options
context:
space:
mode:
authorjsing <>2022-08-17 07:39:19 +0000
committerjsing <>2022-08-17 07:39:19 +0000
commitb0c5f651476e9397892adf645bba468df03d0ea9 (patch)
treed4b208572f46a7c773aecb3e2d410aeaae5e817a /src/lib/libssl/ssl_lib.c
parent7e9e21e27683a4be2c58fedde7fc9303f63a83f9 (diff)
downloadopenbsd-b0c5f651476e9397892adf645bba468df03d0ea9.tar.gz
openbsd-b0c5f651476e9397892adf645bba468df03d0ea9.tar.bz2
openbsd-b0c5f651476e9397892adf645bba468df03d0ea9.zip
Deduplicate peer certificate chain processing code.
Rather than reimplement this in each TLS client and server, deduplicate it into a single function. Furthermore, rather than dealing with the API hazard that is SSL_get_peer_cert_chain() in this code, simply produce two chains - one that has the leaf and one that does not. SSL_get_peer_cert_chain() can then return the appropriate one. This also moves the peer cert chain from the SSL_SESSION to the SSL_HANDSHAKE, which makes more sense since it is not available on resumption. ok tb@
Diffstat (limited to 'src/lib/libssl/ssl_lib.c')
-rw-r--r--src/lib/libssl/ssl_lib.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index e346e3cf7f..9af1934dd6 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.300 2022/07/24 15:05:16 jsing Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.301 2022/08/17 07:39:19 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -880,14 +880,17 @@ SSL_get_peer_certificate(const SSL *s)
880STACK_OF(X509) * 880STACK_OF(X509) *
881SSL_get_peer_cert_chain(const SSL *s) 881SSL_get_peer_cert_chain(const SSL *s)
882{ 882{
883 if (s == NULL || s->session == NULL) 883 if (s == NULL)
884 return NULL; 884 return NULL;
885 885
886 /* 886 /*
887 * If we are a client, cert_chain includes the peer's own 887 * Achtung! Due to API inconsistency, a client includes the peer's leaf
888 * certificate; if we are a server, it does not. 888 * certificate in the peer certificate chain, while a server does not.
889 */ 889 */
890 return s->session->cert_chain; 890 if (!s->server)
891 return s->s3->hs.peer_certs;
892
893 return s->s3->hs.peer_certs_no_leaf;
891} 894}
892 895
893STACK_OF(X509) * 896STACK_OF(X509) *