SSL_GET_PEER_CERT_CHAIN(3ossl)
π SSL_GET_PEER_CERT_CHAIN π
okay bestie, welcome to the 3ossl corner of the OpenSSL manual β yes it's giving "certificate chain of the peer" and honestly? it's lowkey iconic. let's get into it π
β¨ NAME β¨
SSL_get_peer_cert_chain, SSL_get0_verified_chain β get the X509 certificate chain of the peer π¦
πΈ SYNOPSIS πΈ
#include <openssl/ssl.h>
STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *ssl);
STACK_OF(X509) *SSL_get0_verified_chain(const SSL *ssl);
π DESCRIPTION π
okay so, two functions, two whole vibes:
SSL_get_peer_cert_chain() hands you back a pointer to a STACK_OF(X509) β that's the certificate chain the peer literally sent you. and here's the tea π΅: if you call it on the client side, the stack also contains the peer's certificate. but if you call it on the server side? nope, the peer's certificate has to be obtained separately using SSL_get_peer_certificate(3). and if the peer just... didn't present a certificate at all? NULL comes back. sorry babe π
NB: SSL_get_peer_cert_chain() returns the peer chain as sent by the peer β it only consists of certificates the peer has sent, in the order the peer has sent them. it is not a verified chain. no cap. don't trust it like it's been checked, because it hasn't π
SSL_get0_verified_chain() is the glow-up version β¨ β it returns the verified certificate chain of the peer, including the peer's end entity certificate. but there's a catch: you must call it after a session has been successfully established. and if peer verification was not successful (which you can spot by SSL_get_verify_result() not returning X509_V_OK), then the chain may be incomplete or invalid. proceed with caution, bestie π
π NOTES π
- if the session is resumed, peers do not send certificates, so these functions return a
NULLpointer. apps can callSSL_session_reused()to figure out whether a session is resumed. handy, right? π«Ά - the reference count of each certificate in the returned
STACK_OF(X509)object is not incremented, and the returned stack may be invalidated by renegotiation. so if your app wants to hold onto any certificates in that chain indefinitely, you gotta bump those reference counts yourself usingX509_up_ref(), or grab a copy of the whole chain withX509_chain_up_ref(). do not skip this step, i'm begging π
π₯ RETURN VALUES π₯
here's what can come back at you:
NULLβ no certificate was presented by the peer, or no connection was established, or the certificate chain is no longer available when a session is reused. it's giving "nothing to see here" π- Pointer to a
STACK_OF(X509)β the return value points to the certificate chain presented by the peer. slay π
π SEE ALSO π
ssl(7), SSL_get_peer_certificate(3), X509_up_ref(3), X509_chain_up_ref(3)
π COPYRIGHT π
Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie!! this one's from OpenSSL 3.5.9, dated 2026-09-29, and it lives in the 3ossl manual family π go forth and chain those certs responsibly, mwah π«Άβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms