xref: /openbsd-src/lib/libtls/man/tls_conn_version.3 (revision 5ad0d35887f8740419014a24ccba483e1d0e7f65)
1*5ad0d358Stb.\" $OpenBSD: tls_conn_version.3,v 1.11 2024/12/10 08:42:12 tb Exp $
2e690d60fSschwarze.\"
34801fc0bSschwarze.\" Copyright (c) 2015 Bob Beck <beck@openbsd.org>
4940f9ff5Sjsing.\" Copyright (c) 2016, 2018 Joel Sing <jsing@openbsd.org>
5e690d60fSschwarze.\"
6e690d60fSschwarze.\" Permission to use, copy, modify, and distribute this software for any
7e690d60fSschwarze.\" purpose with or without fee is hereby granted, provided that the above
8e690d60fSschwarze.\" copyright notice and this permission notice appear in all copies.
9e690d60fSschwarze.\"
10e690d60fSschwarze.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11e690d60fSschwarze.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12e690d60fSschwarze.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13e690d60fSschwarze.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14e690d60fSschwarze.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15e690d60fSschwarze.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16e690d60fSschwarze.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17e690d60fSschwarze.\"
18*5ad0d358Stb.Dd $Mdocdate: December 10 2024 $
19b52998d6Sjmc.Dt TLS_CONN_VERSION 3
20e690d60fSschwarze.Os
21e690d60fSschwarze.Sh NAME
22e690d60fSschwarze.Nm tls_conn_version ,
23e690d60fSschwarze.Nm tls_conn_cipher ,
248e0c7682Sjsing.Nm tls_conn_cipher_strength ,
25e690d60fSschwarze.Nm tls_conn_alpn_selected ,
26e690d60fSschwarze.Nm tls_conn_servername ,
27940f9ff5Sjsing.Nm tls_conn_session_resumed ,
28e690d60fSschwarze.Nm tls_peer_cert_provided ,
29e690d60fSschwarze.Nm tls_peer_cert_contains_name ,
306bcf209cSjsing.Nm tls_peer_cert_chain_pem ,
31e690d60fSschwarze.Nm tls_peer_cert_issuer ,
32e690d60fSschwarze.Nm tls_peer_cert_subject ,
33*5ad0d358Stb.Nm tls_peer_cert_common_name ,
34e690d60fSschwarze.Nm tls_peer_cert_hash ,
35e690d60fSschwarze.Nm tls_peer_cert_notbefore ,
36e690d60fSschwarze.Nm tls_peer_cert_notafter
37e690d60fSschwarze.Nd inspect an established TLS connection
38e690d60fSschwarze.Sh SYNOPSIS
39e690d60fSschwarze.In tls.h
40e690d60fSschwarze.Ft const char *
41e690d60fSschwarze.Fn tls_conn_version "struct tls *ctx"
42e690d60fSschwarze.Ft const char *
43e690d60fSschwarze.Fn tls_conn_cipher "struct tls *ctx"
448e0c7682Sjsing.Ft int
458e0c7682Sjsing.Fn tls_conn_cipher_strength "struct tls *ctx"
46e690d60fSschwarze.Ft const char *
47e690d60fSschwarze.Fn tls_conn_alpn_selected "struct tls *ctx"
48e690d60fSschwarze.Ft const char *
49e690d60fSschwarze.Fn tls_conn_servername "struct tls *ctx"
50e690d60fSschwarze.Ft int
51940f9ff5Sjsing.Fn tls_conn_session_resumed "struct tls *ctx"
52940f9ff5Sjsing.Ft int
53e690d60fSschwarze.Fn tls_peer_cert_provided "struct tls *ctx"
54e690d60fSschwarze.Ft int
55e690d60fSschwarze.Fo tls_peer_cert_contains_name
56e690d60fSschwarze.Fa "struct tls *ctx"
57e690d60fSschwarze.Fa "const char *name"
58e690d60fSschwarze.Fc
596bcf209cSjsing.Ft const uint8_t *
606bcf209cSjsing.Fo tls_peer_cert_chain_pem
61d4c5fc9dSschwarze.Fa "struct tls *ctx"
62d4c5fc9dSschwarze.Fa "size_t *size"
636bcf209cSjsing.Fc
64e690d60fSschwarze.Ft const char *
65e690d60fSschwarze.Fn tls_peer_cert_issuer "struct tls *ctx"
66e690d60fSschwarze.Ft const char *
67e690d60fSschwarze.Fn tls_peer_cert_subject "struct tls *ctx"
68e690d60fSschwarze.Ft const char *
69*5ad0d358Stb.Fn tls_peer_cert_common_name "struct tls *ctx"
70*5ad0d358Stb.Ft const char *
71e690d60fSschwarze.Fn tls_peer_cert_hash "struct tls *ctx"
72e690d60fSschwarze.Ft time_t
73e690d60fSschwarze.Fn tls_peer_cert_notbefore "struct tls *ctx"
74e690d60fSschwarze.Ft time_t
75e690d60fSschwarze.Fn tls_peer_cert_notafter "struct tls *ctx"
76e690d60fSschwarze.Sh DESCRIPTION
77e690d60fSschwarzeThese functions return information about a TLS connection and will only
78e690d60fSschwarzesucceed after the handshake is complete (the connection information applies
79e690d60fSschwarzeto both clients and servers, unless noted otherwise):
80e690d60fSschwarze.Pp
81e690d60fSschwarze.Fn tls_conn_version
82e690d60fSschwarzereturns a string corresponding to a TLS version negotiated with the peer
83e690d60fSschwarzeconnected to
84e690d60fSschwarze.Ar ctx .
85e690d60fSschwarze.Pp
86e690d60fSschwarze.Fn tls_conn_cipher
87e690d60fSschwarzereturns a string corresponding to the cipher suite negotiated with the peer
88e690d60fSschwarzeconnected to
89e690d60fSschwarze.Ar ctx .
90e690d60fSschwarze.Pp
918e0c7682Sjsing.Fn tls_conn_cipher_strength
928e0c7682Sjsingreturns the strength in bits for the symmetric cipher that is being
938e0c7682Sjsingused with the peer connected to
948e0c7682Sjsing.Ar ctx .
958e0c7682Sjsing.Pp
96e690d60fSschwarze.Fn tls_conn_alpn_selected
97e690d60fSschwarzereturns a string that specifies the ALPN protocol selected for use with the peer
98e690d60fSschwarzeconnected to
99e690d60fSschwarze.Ar ctx .
100e690d60fSschwarzeIf no protocol was selected then NULL is returned.
101e690d60fSschwarze.Pp
102e690d60fSschwarze.Fn tls_conn_servername
103e690d60fSschwarzereturns a string corresponding to the servername that the client connected to
104e690d60fSschwarze.Ar ctx
105e690d60fSschwarzerequested by sending a TLS Server Name Indication extension (server only).
106e690d60fSschwarze.Pp
107940f9ff5Sjsing.Fn tls_conn_session_resumed
108940f9ff5Sjsingindicates whether a TLS session has been resumed during the handshake with
109940f9ff5Sjsingthe server connected to
110940f9ff5Sjsing.Ar ctx
111940f9ff5Sjsing(client only).
112940f9ff5Sjsing.Pp
113e690d60fSschwarze.Fn tls_peer_cert_provided
114e690d60fSschwarzechecks if the peer of
115e690d60fSschwarze.Ar ctx
116e690d60fSschwarzehas provided a certificate.
117e690d60fSschwarze.Pp
118e690d60fSschwarze.Fn tls_peer_cert_contains_name
119e690d60fSschwarzechecks if the peer of a TLS
120e690d60fSschwarze.Ar ctx
121e690d60fSschwarzehas provided a certificate that contains a
122e690d60fSschwarzeSAN or CN that matches
123e690d60fSschwarze.Ar name .
124e690d60fSschwarze.Pp
1256bcf209cSjsing.Fn tls_peer_cert_chain_pem
12674a357a3Sjmcreturns a pointer to memory containing a PEM-encoded certificate chain for the
1276bcf209cSjsingpeer certificate from
1286bcf209cSjsing.Ar ctx .
1296bcf209cSjsing.Pp
130e690d60fSschwarze.Fn tls_peer_cert_subject
131e690d60fSschwarzereturns a string
132e690d60fSschwarzecorresponding to the subject of the peer certificate from
133e690d60fSschwarze.Ar ctx .
134e690d60fSschwarze.Pp
135e690d60fSschwarze.Fn tls_peer_cert_issuer
136e690d60fSschwarzereturns a string
137e690d60fSschwarzecorresponding to the issuer of the peer certificate from
138e690d60fSschwarze.Ar ctx .
139*5ad0d358Stb.Fn tls_peer_cert_common_name
140*5ad0d358Stbreturns a string
141*5ad0d358Stbcorresponding to the common name of the peer certificate from
142*5ad0d358Stb.Ar ctx
143*5ad0d358Stbor the empty string if no common name is present.
144e690d60fSschwarze.Pp
145e690d60fSschwarze.Fn tls_peer_cert_hash
146e690d60fSschwarzereturns a string
147e690d60fSschwarzecorresponding to a hash of the raw peer certificate from
148e690d60fSschwarze.Ar ctx
149e690d60fSschwarzeprefixed by a hash name followed by a colon.
150e690d60fSschwarzeThe hash currently used is SHA256, though this
151e690d60fSschwarzecould change in the future.
152e690d60fSschwarzeThe hash string for a certificate in file
153e690d60fSschwarze.Ar mycert.crt
154e690d60fSschwarzecan be generated using the commands:
155e690d60fSschwarze.Bd -literal -offset indent
156e690d60fSschwarzeh=$(openssl x509 -outform der -in mycert.crt | sha256)
157e690d60fSschwarzeprintf "SHA256:${h}\\n"
158e690d60fSschwarze.Ed
159e690d60fSschwarze.Pp
160e690d60fSschwarze.Fn tls_peer_cert_notbefore
161e690d60fSschwarzereturns the time corresponding to the start of the validity period of
162e690d60fSschwarzethe peer certificate from
163e690d60fSschwarze.Ar ctx .
164e690d60fSschwarze.Pp
165e690d60fSschwarze.Fn tls_peer_cert_notafter
166e690d60fSschwarzereturns the time corresponding to the end of the validity period of
167e690d60fSschwarzethe peer certificate from
168e690d60fSschwarze.Ar ctx .
169e690d60fSschwarze.Sh RETURN VALUES
170e690d60fSschwarzeThe
171940f9ff5Sjsing.Fn tls_conn_session_resumed
172940f9ff5Sjsingfunction returns 1 if a TLS session was resumed or 0 if it was not.
173940f9ff5Sjsing.Pp
174940f9ff5SjsingThe
175e690d60fSschwarze.Fn tls_peer_cert_provided
176e690d60fSschwarzeand
177e690d60fSschwarze.Fn tls_peer_cert_contains_name
178e690d60fSschwarzefunctions return 1 if the check succeeds or 0 if it does not.
179e690d60fSschwarze.Pp
180e690d60fSschwarze.Fn tls_peer_cert_notbefore
181e690d60fSschwarzeand
182e690d60fSschwarze.Fn tls_peer_cert_notafter
183e690d60fSschwarzereturn a time in epoch-seconds on success or -1 on error.
184e690d60fSschwarze.Pp
185e690d60fSschwarzeThe functions that return a pointer return
186e690d60fSschwarze.Dv NULL
187e690d60fSschwarzeon error or an out of memory condition.
188e690d60fSschwarze.Sh SEE ALSO
189e690d60fSschwarze.Xr tls_configure 3 ,
190e690d60fSschwarze.Xr tls_handshake 3 ,
191e690d60fSschwarze.Xr tls_init 3 ,
192e690d60fSschwarze.Xr tls_ocsp_process_response 3
1938b02f64eSschwarze.Sh HISTORY
1948b02f64eSschwarze.Fn tls_conn_version ,
1958b02f64eSschwarze.Fn tls_conn_cipher ,
1968b02f64eSschwarze.Fn tls_peer_cert_provided ,
1978b02f64eSschwarze.Fn tls_peer_cert_contains_name ,
1988b02f64eSschwarze.Fn tls_peer_cert_issuer ,
1998b02f64eSschwarze.Fn tls_peer_cert_subject ,
2008b02f64eSschwarze.Fn tls_peer_cert_hash ,
2018b02f64eSschwarze.Fn tls_peer_cert_notbefore ,
2028b02f64eSschwarzeand
2038b02f64eSschwarze.Fn tls_peer_cert_notafter
2048b02f64eSschwarzeappeared in
2058b02f64eSschwarze.Ox 5.9 .
2068b02f64eSschwarze.Pp
2078b02f64eSschwarze.Fn tls_conn_servername
2088b02f64eSschwarzeand
2098b02f64eSschwarze.Fn tls_conn_alpn_selected
2108b02f64eSschwarzeappeared in
2118b02f64eSschwarze.Ox 6.1 .
212940f9ff5Sjsing.Pp
213940f9ff5Sjsing.Fn tls_conn_session_resumed
214940f9ff5Sjsingappeared in
215940f9ff5Sjsing.Ox 6.3 .
2168e0c7682Sjsing.Pp
2178e0c7682Sjsing.Fn tls_conn_cipher_strength
2188e0c7682Sjsingappeared in
2198e0c7682Sjsing.Ox 6.7 .
220*5ad0d358Stb.Fn tls_peer_cert_common_name
221*5ad0d358Stbappeared in
222*5ad0d358Stb.Ox 7.7 .
2238b02f64eSschwarze.Sh AUTHORS
2248b02f64eSschwarze.An Bob Beck Aq Mt beck@openbsd.org
2258b02f64eSschwarze.An Joel Sing Aq Mt jsing@openbsd.org
226