libc: remove THIRDPARTYLICENSE/extract-copyright
[unleashed.git] / lib / libtls / tls_peer.c
blobec97a30838664ecc6c26f9cfbcdebbbb0f65f99c
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>
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.
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.
19 #include <stdio.h>
21 #include <openssl/x509.h>
23 #include <tls.h>
24 #include "tls_internal.h"
26 const char *
27 tls_peer_cert_hash(struct tls *ctx)
29 if (ctx->conninfo == NULL)
30 return (NULL);
31 return (ctx->conninfo->hash);
33 const char *
34 tls_peer_cert_issuer(struct tls *ctx)
36 if (ctx->conninfo == NULL)
37 return (NULL);
38 return (ctx->conninfo->issuer);
41 const char *
42 tls_peer_cert_subject(struct tls *ctx)
44 if (ctx->conninfo == NULL)
45 return (NULL);
46 return (ctx->conninfo->subject);
49 int
50 tls_peer_cert_provided(struct tls *ctx)
52 return (ctx->ssl_peer_cert != NULL);
55 int
56 tls_peer_cert_contains_name(struct tls *ctx, const char *name)
58 int match;
60 if (ctx->ssl_peer_cert == NULL)
61 return (0);
63 if (tls_check_name(ctx, ctx->ssl_peer_cert, name, &match) == -1)
64 return (0);
66 return (match);
69 time_t
70 tls_peer_cert_notbefore(struct tls *ctx)
72 if (ctx->ssl_peer_cert == NULL)
73 return (-1);
74 if (ctx->conninfo == NULL)
75 return (-1);
76 return (ctx->conninfo->notbefore);
79 time_t
80 tls_peer_cert_notafter(struct tls *ctx)
82 if (ctx->ssl_peer_cert == NULL)
83 return (-1);
84 if (ctx->conninfo == NULL)
85 return (-1);
86 return (ctx->conninfo->notafter);
89 const uint8_t *
90 tls_peer_cert_chain_pem(struct tls *ctx, size_t *size)
92 if (ctx->ssl_peer_cert == NULL)
93 return (NULL);
94 if (ctx->conninfo == NULL)
95 return (NULL);
96 *size = ctx->conninfo->peer_cert_len;
97 return (ctx->conninfo->peer_cert);