1 f9ab77a8 2023-08-23 op /* $OpenBSD: tls_peer.c,v 1.8 2017/04/10 17:11:13 jsing Exp $ */
3 f9ab77a8 2023-08-23 op * Copyright (c) 2015 Joel Sing <jsing@openbsd.org>
4 f9ab77a8 2023-08-23 op * Copyright (c) 2015 Bob Beck <beck@openbsd.org>
6 f9ab77a8 2023-08-23 op * Permission to use, copy, modify, and distribute this software for any
7 f9ab77a8 2023-08-23 op * purpose with or without fee is hereby granted, provided that the above
8 f9ab77a8 2023-08-23 op * copyright notice and this permission notice appear in all copies.
10 f9ab77a8 2023-08-23 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 f9ab77a8 2023-08-23 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 f9ab77a8 2023-08-23 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 f9ab77a8 2023-08-23 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 f9ab77a8 2023-08-23 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 f9ab77a8 2023-08-23 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 f9ab77a8 2023-08-23 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 f9ab77a8 2023-08-23 op #include "config.h"
21 f9ab77a8 2023-08-23 op #include <stdio.h>
23 f9ab77a8 2023-08-23 op #include <openssl/x509.h>
25 f9ab77a8 2023-08-23 op #include <tls.h>
26 f9ab77a8 2023-08-23 op #include "tls_internal.h"
29 f9ab77a8 2023-08-23 op tls_peer_cert_hash(struct tls *ctx)
31 f9ab77a8 2023-08-23 op if (ctx->conninfo == NULL)
32 f9ab77a8 2023-08-23 op return (NULL);
33 f9ab77a8 2023-08-23 op return (ctx->conninfo->hash);
36 f9ab77a8 2023-08-23 op tls_peer_cert_issuer(struct tls *ctx)
38 f9ab77a8 2023-08-23 op if (ctx->conninfo == NULL)
39 f9ab77a8 2023-08-23 op return (NULL);
40 f9ab77a8 2023-08-23 op return (ctx->conninfo->issuer);
44 f9ab77a8 2023-08-23 op tls_peer_cert_subject(struct tls *ctx)
46 f9ab77a8 2023-08-23 op if (ctx->conninfo == NULL)
47 f9ab77a8 2023-08-23 op return (NULL);
48 f9ab77a8 2023-08-23 op return (ctx->conninfo->subject);
52 f9ab77a8 2023-08-23 op tls_peer_cert_provided(struct tls *ctx)
54 f9ab77a8 2023-08-23 op return (ctx->ssl_peer_cert != NULL);
58 f9ab77a8 2023-08-23 op tls_peer_cert_contains_name(struct tls *ctx, const char *name)
62 f9ab77a8 2023-08-23 op if (ctx->ssl_peer_cert == NULL)
65 f9ab77a8 2023-08-23 op if (tls_check_name(ctx, ctx->ssl_peer_cert, name, &match) == -1)
68 f9ab77a8 2023-08-23 op return (match);
72 f9ab77a8 2023-08-23 op tls_peer_cert_notbefore(struct tls *ctx)
74 f9ab77a8 2023-08-23 op if (ctx->ssl_peer_cert == NULL)
76 f9ab77a8 2023-08-23 op if (ctx->conninfo == NULL)
78 f9ab77a8 2023-08-23 op return (ctx->conninfo->notbefore);
82 f9ab77a8 2023-08-23 op tls_peer_cert_notafter(struct tls *ctx)
84 f9ab77a8 2023-08-23 op if (ctx->ssl_peer_cert == NULL)
86 f9ab77a8 2023-08-23 op if (ctx->conninfo == NULL)
88 f9ab77a8 2023-08-23 op return (ctx->conninfo->notafter);
91 f9ab77a8 2023-08-23 op const uint8_t *
92 f9ab77a8 2023-08-23 op tls_peer_cert_chain_pem(struct tls *ctx, size_t *size)
94 f9ab77a8 2023-08-23 op if (ctx->ssl_peer_cert == NULL)
95 f9ab77a8 2023-08-23 op return (NULL);
96 f9ab77a8 2023-08-23 op if (ctx->conninfo == NULL)
97 f9ab77a8 2023-08-23 op return (NULL);
98 f9ab77a8 2023-08-23 op *size = ctx->conninfo->peer_cert_len;
99 f9ab77a8 2023-08-23 op return (ctx->conninfo->peer_cert);