Blob


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