TLS_CONN_VERSION(3)
π NAME π
ok so bestie, this page is TLS_CONN_VERSION(3) from the Library Functions Manual, and it's literally the whole squad of functions that let you inspect an established TLS connection: tls_conn_version, tls_conn_cipher, tls_conn_cipher_strength, tls_conn_alpn_selected, tls_conn_servername, tls_conn_session_resumed, tls_peer_cert_provided, tls_peer_cert_contains_name, tls_peer_cert_chain_pem, tls_peer_cert_unverified_bundle_pem, tls_peer_cert_verified_chain_pem, tls_peer_cert_issuer, tls_peer_cert_subject, tls_peer_cert_common_name, tls_peer_cert_hash, tls_peer_cert_notbefore, and tls_peer_cert_notafter. yeah. all of them. they're a package deal π
β¨ SYNOPSIS β¨
the library situation is libtls, plus libssl and libcrypto, and you're gonna want:
#include <tls.h>
and then, one by one, the whole lineup:
const char *
tls_conn_version(struct tls *ctx);
const char *
tls_conn_cipher(struct tls *ctx);
int
tls_conn_cipher_strength(struct tls *ctx);
const char *
tls_conn_alpn_selected(struct tls *ctx);
const char *
tls_conn_servername(struct tls *ctx);
int
tls_conn_session_resumed(struct tls *ctx);
int
tls_peer_cert_provided(struct tls *ctx);
int
tls_peer_cert_contains_name(struct tls *ctx, const char *name);
const uint8_t *
tls_peer_cert_chain_pem(struct tls *ctx, size_t *size);
const uint8_t *
tls_peer_cert_unverified_bundle_pem(struct tls *ctx, size_t *size);
const uint8_t *
tls_peer_cert_verified_chain_pem(struct tls *ctx, size_t *size);
const char *
tls_peer_cert_issuer(struct tls *ctx);
const char *
tls_peer_cert_subject(struct tls *ctx);
const char *
tls_peer_cert_common_name(struct tls *ctx);
const char *
tls_peer_cert_hash(struct tls *ctx);
time_t
tls_peer_cert_notbefore(struct tls *ctx);
time_t
tls_peer_cert_notafter(struct tls *ctx);
like, all of them take a struct tls *ctx. that's the vibe. π«Ά
π¦ DESCRIPTION π¦
so these functions hand you info about a TLS connection, and the key thing: they will only succeed after the handshake is complete. the connection information applies to both clients and servers, unless noted otherwise. no shortcuts, no peeking early, periodt β
tls_conn_version()β returns a string for the TLS version that was negotiated with the peer connected toctx. slay.tls_conn_cipher()β returns a string for the cipher suite negotiated with the peer connected toctx. iconic.tls_conn_cipher_strength()β returns the strength, in bits, of the symmetric cipher being used with the peer connected toctx. numbers. we love her.tls_conn_alpn_selected()β returns a string specifying the ALPN protocol selected for use with the peer connected toctx. and if no protocol was selected?NULLis returned. no protocol, no problem πtls_conn_servername()β returns a string for the servername that the client connected toctxrequested by sending a TLS Server Name Indication extension. server only, bestie. π₯οΈtls_conn_session_resumed()β tells you whether a TLS session was resumed during the handshake with the server connected toctx. client only. πtls_peer_cert_provided()β checks if the peer ofctxhas provided a certificate.tls_peer_cert_contains_name()β checks if the peer of a TLSctxhas provided a certificate that contains a SAN or CN matchingname. yes, matching goes hard πtls_peer_cert_unverified_bundle_pem()β returns a pointer to memory containing the PEM-encoded, unverified bundle of certificates that was sent by the peer ofctxduring the TLS handshake. note the unverified, we'll get to that drama later πtls_peer_cert_chain_pem()β is equivalent totls_peer_cert_unverified_bundle_pem(). that's it. that's the whole thing. (and yes, the naming is a situation β see BUGS π)tls_peer_cert_verified_chain_pem()β returns a pointer to memory containing the PEM-encoded certificate chain that was verified for the peer ofctxduring the TLS handshake. the real one. the main character. πtls_peer_cert_subject()β returns a string for the subject of the peer certificate fromctx.tls_peer_cert_issuer()β returns a string for the issuer of the peer certificate fromctx.tls_peer_cert_common_name()β returns a string for the common name of the peer certificate fromctx, or the empty string if no common name is present. empty string, not NULL. important distinction, iykyk π§tls_peer_cert_hash()β returns a string for a hash of the raw peer certificate fromctx, prefixed by a hash name followed by a colon. the hash currently used isSHA256, though this could change in the future. so like, don't hardcode your whole personality on it, bestie. the hash string for a certificate in filemycert.crtcan be generated using the commands:
h=$(openssl x509 -outform der -in mycert.crt | sha256)
printf "SHA256:${h}\n"
look at that. chef's kiss β¨
tls_peer_cert_notbefore()β returns the time corresponding to the start of the validity period of the peer certificate fromctx. β°tls_peer_cert_notafter()β returns the time corresponding to the end of the validity period of the peer certificate fromctx. β³
π RETURN VALUES π
okay so here's what you actually get back:
tls_conn_session_resumed()returns1if a TLS session was resumed, or0if it was not.tls_peer_cert_provided()andtls_peer_cert_contains_name()return1if the check succeeds, or0if it does not.tls_peer_cert_notbefore()andtls_peer_cert_notafter()return a time in epoch-seconds on success, or-1on error.- the functions that return a pointer return
NULLon error or an out of memory condition. yes, both. keep that in mind π«
πΈ SEE ALSO πΈ
go read these next, bestie, they're all connected:
β HISTORY β
the lore drop, chronological order:
tls_conn_version(),tls_conn_cipher(),tls_peer_cert_provided(),tls_peer_cert_contains_name(),tls_peer_cert_issuer(),tls_peer_cert_subject(),tls_peer_cert_hash(),tls_peer_cert_notbefore(), andtls_peer_cert_notafter()appeared in OpenBSD 5.9.tls_conn_servername()andtls_conn_alpn_selected()appeared in OpenBSD 6.1.tls_conn_session_resumed()appeared in OpenBSD 6.3.tls_conn_cipher_strength()appeared in OpenBSD 6.7.tls_peer_cert_common_name()appeared in OpenBSD 7.7.tls_peer_cert_unverified_bundle_pem()andtls_peer_cert_verified_chain_pem()appeared in OpenBSD 8.0.
a whole glow-up timeline fr fr π
π AUTHORS π
the legends themselves:
- Bob Beck
<beck@openbsd.org> - Joel Sing
<jsing@openbsd.org>
thank you for your service π«‘π
π BUGS π
ok so tls_peer_cert_chain_pem() is poorly named: it returns the unverified bundle of certificates sent by the peer, not the chain that was verified during the handshake. so the name is lowkey lying to you π
it will be deprecated in a future release in favour oftls_peer_cert_unverified_bundle_pem()andtls_peer_cert_verified_chain_pem(). so like, migrate when you can, bestie.
and that's the whole page β¨ this gem comes to you from Debian, dated September 20, 2026, and it's TLS_CONN_VERSION(3) all the way down. mwah π
π¦ where this page comes from
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2015 Bob Beck <beck@openbsd.org>
- Copyright (c) 2016, 2018 Joel Sing <jsing@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms