1 .\" $OpenBSD: tls_conn_version.3,v 1.4 2017/01/28 00:59:36 schwarze Exp $
3 .\" Copyright (c) 2015 Bob Beck <beck@openbsd.org>
4 .\" Copyright (c) 2016 Joel Sing <jsing@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.
18 .Dd $Mdocdate: January 28 2017 $
19 .Dt TLS_CONN_VERSION 3
22 .Nm tls_conn_version ,
24 .Nm tls_conn_alpn_selected ,
25 .Nm tls_conn_servername ,
26 .Nm tls_peer_cert_provided ,
27 .Nm tls_peer_cert_contains_name ,
28 .Nm tls_peer_cert_issuer ,
29 .Nm tls_peer_cert_subject ,
30 .Nm tls_peer_cert_hash ,
31 .Nm tls_peer_cert_notbefore ,
32 .Nm tls_peer_cert_notafter
33 .Nd inspect an established TLS connection
37 .Fn tls_conn_version "struct tls *ctx"
39 .Fn tls_conn_cipher "struct tls *ctx"
41 .Fn tls_conn_alpn_selected "struct tls *ctx"
43 .Fn tls_conn_servername "struct tls *ctx"
45 .Fn tls_peer_cert_provided "struct tls *ctx"
47 .Fo tls_peer_cert_contains_name
49 .Fa "const char *name"
52 .Fn tls_peer_cert_issuer "struct tls *ctx"
54 .Fn tls_peer_cert_subject "struct tls *ctx"
56 .Fn tls_peer_cert_hash "struct tls *ctx"
58 .Fn tls_peer_cert_notbefore "struct tls *ctx"
60 .Fn tls_peer_cert_notafter "struct tls *ctx"
62 These functions return information about a TLS connection and will only
63 succeed after the handshake is complete (the connection information applies
64 to both clients and servers, unless noted otherwise):
67 returns a string corresponding to a TLS version negotiated with the peer
72 returns a string corresponding to the cipher suite negotiated with the peer
76 .Fn tls_conn_alpn_selected
77 returns a string that specifies the ALPN protocol selected for use with the peer
80 If no protocol was selected then NULL is returned.
82 .Fn tls_conn_servername
83 returns a string corresponding to the servername that the client connected to
85 requested by sending a TLS Server Name Indication extension (server only).
87 .Fn tls_peer_cert_provided
90 has provided a certificate.
92 .Fn tls_peer_cert_contains_name
93 checks if the peer of a TLS
95 has provided a certificate that contains a
96 SAN or CN that matches
99 .Fn tls_peer_cert_subject
101 corresponding to the subject of the peer certificate from
104 .Fn tls_peer_cert_issuer
106 corresponding to the issuer of the peer certificate from
109 .Fn tls_peer_cert_hash
111 corresponding to a hash of the raw peer certificate from
113 prefixed by a hash name followed by a colon.
114 The hash currently used is SHA256, though this
115 could change in the future.
116 The hash string for a certificate in file
118 can be generated using the commands:
119 .Bd -literal -offset indent
120 h=$(openssl x509 -outform der -in mycert.crt | sha256)
121 printf "SHA256:${h}\\n"
124 .Fn tls_peer_cert_notbefore
125 returns the time corresponding to the start of the validity period of
126 the peer certificate from
129 .Fn tls_peer_cert_notafter
130 returns the time corresponding to the end of the validity period of
131 the peer certificate from
135 .Xr tls_ocsp_process_response 3
138 .Fn tls_peer_cert_provided
140 .Fn tls_peer_cert_contains_name
141 functions return 1 if the check succeeds or 0 if it does not.
143 .Fn tls_peer_cert_notbefore
145 .Fn tls_peer_cert_notafter
146 return a time in epoch-seconds on success or -1 on error.
148 The functions that return a pointer return
150 on error or an out of memory condition.
152 .Xr tls_configure 3 ,
153 .Xr tls_handshake 3 ,
155 .Xr tls_ocsp_process_response 3
157 .Fn tls_conn_version ,
158 .Fn tls_conn_cipher ,
159 .Fn tls_peer_cert_provided ,
160 .Fn tls_peer_cert_contains_name ,
161 .Fn tls_peer_cert_issuer ,
162 .Fn tls_peer_cert_subject ,
163 .Fn tls_peer_cert_hash ,
164 .Fn tls_peer_cert_notbefore ,
166 .Fn tls_peer_cert_notafter
170 .Fn tls_conn_servername
172 .Fn tls_conn_alpn_selected
176 .An Bob Beck Aq Mt beck@openbsd.org
177 .An Joel Sing Aq Mt jsing@openbsd.org