TLS_CONN_VERSION(3)
π TLS_CONN_VERSION(3) β Library Functions Manual π
Hey bestie! β¨ Welcome to the glow-up guide for your TLS connection. This is the TLS_CONN_VERSION(3) page from the Library Functions Manual, and it's literally all about inspecting an established TLS connection after the handshake is done. No cap, these functions are the main characters when you need to know what's going on under the hood. Let's get into it! π
πΈ NAME πΈ
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_issuer, tls_peer_cert_subject, tls_peer_cert_common_name, tls_peer_cert_hash, tls_peer_cert_notbefore, tls_peer_cert_notafter β inspect an established TLS connection π
π SYNOPSIS π
#include <tls.h>
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 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);
π¦ DESCRIPTION π¦
Okay so here's the tea: these functions spill all the info about a TLS connection, but they only succeed after the handshake is complete. The connection info applies to both clients and servers, unless noted otherwise. π
tls_conn_version()β returns a string that tells you which TLS version you negotiated with the peer connected toctx. It's giving version reveal. β¨tls_conn_cipher()β returns a string for the cipher suite that got negotiated with the peer connected toctx. Slay. πtls_conn_cipher_strength()β returns the strength in bits for the symmetric cipher being used with the peer connected toctx. Big brain energy. π§tls_conn_alpn_selected()β returns a string that specifies the ALPN protocol selected for use with the peer connected toctx. If no protocol was selected, you getNULLback. No vibes selected, I guess. πtls_conn_servername()β returns a string for the servername that the client connected toctxrequested by sending a TLS Server Name Indication extension. This one is server only, bestie. πtls_conn_session_resumed()β tells you whether a TLS session has been resumed during the handshake with the server connected toctx. This one is client only. π₯tls_peer_cert_provided()β checks if the peer ofctxhas provided a certificate. Iconic. πtls_peer_cert_contains_name()β checks if the peer of a TLSctxhas provided a certificate that contains a SAN or CN that matchesname. It's giving "do you know this person?" energy. π«Άtls_peer_cert_chain_pem()β returns a pointer to memory containing a PEM-encoded certificate chain for the peer certificate fromctx. Chain mail but make it crypto. βtls_peer_cert_subject()β returns a string for the subject of the peer certificate fromctx. The who. πtls_peer_cert_issuer()β returns a string for the issuer of the peer certificate fromctx. The who-signed-it. π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. Sometimes it's just nothing, and that's valid. π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. Right now the hash used isSHA256, though this could change in the future. The hash string for a certificate in filemycert.crtcan be generated using these commands:
h=$(openssl x509 -outform der -in mycert.crt | sha256)
printf "SHA256:${h}\n"
tls_peer_cert_notbefore()β returns the time corresponding to the start of the validity period of the peer certificate fromctx. It's giving birthday. πtls_peer_cert_notafter()β returns the time corresponding to the end of the validity period of the peer certificate fromctx. Expiration date, but for your cert. π
π‘ Vibe check: All of these only work after the handshake is complete. Don't try to peek before the connection is ready β that's not the move. π
β¨ RETURN VALUES β¨
Here's what you get back, bestie:
tls_conn_session_resumed()returns1if a TLS session was resumed, or0if it was not. Simple. π₯tls_peer_cert_provided()andtls_peer_cert_contains_name()return1if the check succeeds, or0if it does not. Binary realness. πtls_peer_cert_notbefore()andtls_peer_cert_notafter()return a time in epoch-seconds on success, or-1on error. Epoch time is giving time traveler. π°οΈ- The functions that return a pointer return
NULLon error or an out of memory condition. No memory, no pointer. π
π SEE ALSO π
π HISTORY π
Let's take a lil walk down memory lane:
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. OG vibes. πtls_conn_servername()andtls_conn_alpn_selected()appeared in OpenBSD 6.1. Glow up. β¨tls_conn_session_resumed()appeared in OpenBSD 6.3. Renaissance. πΈtls_conn_cipher_strength()appeared in OpenBSD 6.7. Strength era. πͺtls_peer_cert_common_name()appeared in OpenBSD 7.7. Fresh off the press. π¦
π AUTHORS π
Big shoutout to the icons who wrote this:
- Bob Beck
<beck@openbsd.org> - Joel Sing
<jsing@openbsd.org>
And that's a wrap! π This page comes from Debian, dated December 10, 2024. Catch you on the flip side, bestie! π β¨π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· 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