blob: f36329dca9f2adc3b3f9260216c36a87ef8e4335 [file] [log] [blame]
Richard Levitte4759abc2000-09-20 16:55:26 +00001=pod
2
3=head1 NAME
4
Dr. Stephen Henson696178e2016-02-06 03:17:23 +00005SSL_get_peer_cert_chain, SSL_get0_verified_chain - get the X509 certificate
6chain of the peer
Richard Levitte4759abc2000-09-20 16:55:26 +00007
8=head1 SYNOPSIS
9
10 #include <openssl/ssl.h>
11
Jeff Trawicke5676b82014-04-13 15:10:17 +020012 STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *ssl);
Dr. Stephen Henson696178e2016-02-06 03:17:23 +000013 STACK_OF(X509) *SSL_get0_verified_chain(const SSL *ssl);
Richard Levitte4759abc2000-09-20 16:55:26 +000014
15=head1 DESCRIPTION
16
Jeff Trawicke5676b82014-04-13 15:10:17 +020017SSL_get_peer_cert_chain() returns a pointer to STACK_OF(X509) certificates
Dr. Stephen Henson696178e2016-02-06 03:17:23 +000018forming the certificate chain sent by the peer. If called on the client side,
Richard Levitte4759abc2000-09-20 16:55:26 +000019the stack also contains the peer's certificate; if called on the server
Ulf Möller52d160d2001-02-16 02:09:53 +000020side, the peer's certificate must be obtained separately using
Rich Salz9b869742015-08-17 15:21:33 -040021L<SSL_get_peer_certificate(3)>.
Richard Levitte4759abc2000-09-20 16:55:26 +000022If the peer did not present a certificate, NULL is returned.
23
Markus Triska1f164c62017-01-18 01:40:36 +010024NB: SSL_get_peer_cert_chain() returns the peer chain as sent by the peer: it
Dr. Stephen Henson696178e2016-02-06 03:17:23 +000025only consists of certificates the peer has sent (in the order the peer
26has sent them) it is B<not> a verified chain.
27
28SSL_get0_verified_chain() returns the B<verified> certificate chain
29of the peer including the peer's end entity certificate. It must be called
30after a session has been successfully established. If peer verification was
31not successful (as indicated by SSL_get_verify_result() not returning
32X509_V_OK) the chain may be incomplete or invalid.
33
Richard Levitte4759abc2000-09-20 16:55:26 +000034=head1 NOTES
35
Dr. Stephen Henson99978d52016-02-07 23:20:53 +000036If the session is resumed peers do not send certificates so a NULL pointer
37is returned by these functions. Applications can call SSL_session_reused()
38to determine whether a session is resumed.
Richard Levitte4759abc2000-09-20 16:55:26 +000039
Dr. Stephen Henson696178e2016-02-06 03:17:23 +000040The reference count of each certificate in the returned STACK_OF(X509) object
41is not incremented and the returned stack may be invalidated by renegotiation.
42If applications wish to use any certificates in the returned chain
43indefinitely they must increase the reference counts using X509_up_ref() or
44obtain a copy of the whole chain with X509_chain_up_ref().
Richard Levitte4759abc2000-09-20 16:55:26 +000045
46=head1 RETURN VALUES
47
48The following return values can occur:
49
50=over 4
51
52=item NULL
53
54No certificate was presented by the peer or no connection was established
55or the certificate chain is no longer available when a session is reused.
56
Jeff Trawicke5676b82014-04-13 15:10:17 +020057=item Pointer to a STACK_OF(X509)
Richard Levitte4759abc2000-09-20 16:55:26 +000058
59The return value points to the certificate chain presented by the peer.
60
61=back
62
63=head1 SEE ALSO
64
Richard Levitteb97fdb52016-11-11 09:33:09 +010065L<ssl(7)>, L<SSL_get_peer_certificate(3)>, L<X509_up_ref(3)>,
Dr. Stephen Henson696178e2016-02-06 03:17:23 +000066L<X509_chain_up_ref(3)>
Richard Levitte4759abc2000-09-20 16:55:26 +000067
Rich Salze2f92612016-05-18 11:44:05 -040068=head1 COPYRIGHT
69
70Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
71
Richard Levitte4746f252018-12-06 14:04:44 +010072Licensed under the Apache License 2.0 (the "License"). You may not use
Rich Salze2f92612016-05-18 11:44:05 -040073this file except in compliance with the License. You can obtain a copy
74in the file LICENSE in the source distribution or at
75L<https://www.openssl.org/source/license.html>.
76
77=cut