import libtls (LibreSSL 2.5.4)
[unleashed.git] / lib / libtls / man / tls_conn_version.3
blob8ac2c9b6b3dfebdfab8627b1abb66682a51bf305
1 .\" $OpenBSD: tls_conn_version.3,v 1.4 2017/01/28 00:59:36 schwarze Exp $
2 .\"
3 .\" Copyright (c) 2015 Bob Beck <beck@openbsd.org>
4 .\" Copyright (c) 2016 Joel Sing <jsing@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 .\"
18 .Dd $Mdocdate: January 28 2017 $
19 .Dt TLS_CONN_VERSION 3
20 .Os
21 .Sh NAME
22 .Nm tls_conn_version ,
23 .Nm tls_conn_cipher ,
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
34 .Sh SYNOPSIS
35 .In tls.h
36 .Ft const char *
37 .Fn tls_conn_version "struct tls *ctx"
38 .Ft const char *
39 .Fn tls_conn_cipher "struct tls *ctx"
40 .Ft const char *
41 .Fn tls_conn_alpn_selected "struct tls *ctx"
42 .Ft const char *
43 .Fn tls_conn_servername "struct tls *ctx"
44 .Ft int
45 .Fn tls_peer_cert_provided "struct tls *ctx"
46 .Ft int
47 .Fo tls_peer_cert_contains_name
48 .Fa "struct tls *ctx"
49 .Fa "const char *name"
50 .Fc
51 .Ft const char *
52 .Fn tls_peer_cert_issuer "struct tls *ctx"
53 .Ft const char *
54 .Fn tls_peer_cert_subject "struct tls *ctx"
55 .Ft const char *
56 .Fn tls_peer_cert_hash "struct tls *ctx"
57 .Ft time_t
58 .Fn tls_peer_cert_notbefore "struct tls *ctx"
59 .Ft time_t
60 .Fn tls_peer_cert_notafter "struct tls *ctx"
61 .Sh DESCRIPTION
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):
65 .Pp
66 .Fn tls_conn_version
67 returns a string corresponding to a TLS version negotiated with the peer
68 connected to
69 .Ar ctx .
70 .Pp
71 .Fn tls_conn_cipher
72 returns a string corresponding to the cipher suite negotiated with the peer
73 connected to
74 .Ar ctx .
75 .Pp
76 .Fn tls_conn_alpn_selected
77 returns a string that specifies the ALPN protocol selected for use with the peer
78 connected to
79 .Ar ctx .
80 If no protocol was selected then NULL is returned.
81 .Pp
82 .Fn tls_conn_servername
83 returns a string corresponding to the servername that the client connected to
84 .Ar ctx
85 requested by sending a TLS Server Name Indication extension (server only).
86 .Pp
87 .Fn tls_peer_cert_provided
88 checks if the peer of
89 .Ar ctx
90 has provided a certificate.
91 .Pp
92 .Fn tls_peer_cert_contains_name
93 checks if the peer of a TLS
94 .Ar ctx
95 has provided a certificate that contains a
96 SAN or CN that matches
97 .Ar name .
98 .Pp
99 .Fn tls_peer_cert_subject
100 returns a string
101 corresponding to the subject of the peer certificate from
102 .Ar ctx .
104 .Fn tls_peer_cert_issuer
105 returns a string
106 corresponding to the issuer of the peer certificate from
107 .Ar ctx .
109 .Fn tls_peer_cert_hash
110 returns a string
111 corresponding to a hash of the raw peer certificate from
112 .Ar ctx
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
117 .Ar mycert.crt
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
127 .Ar ctx .
129 .Fn tls_peer_cert_notafter
130 returns the time corresponding to the end of the validity period of
131 the peer certificate from
132 .Ar ctx .
134 POINTER TO
135 .Xr tls_ocsp_process_response 3
136 .Sh RETURN VALUES
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
149 .Dv NULL
150 on error or an out of memory condition.
151 .Sh SEE ALSO
152 .Xr tls_configure 3 ,
153 .Xr tls_handshake 3 ,
154 .Xr tls_init 3 ,
155 .Xr tls_ocsp_process_response 3
156 .Sh HISTORY
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
167 appeared in
168 .Ox 5.9 .
170 .Fn tls_conn_servername
172 .Fn tls_conn_alpn_selected
173 appeared in
174 .Ox 6.1 .
175 .Sh AUTHORS
176 .An Bob Beck Aq Mt beck@openbsd.org
177 .An Joel Sing Aq Mt jsing@openbsd.org