xref: /freebsd/crypto/openssl/doc/man3/X509_STORE_add_cert.pod (revision e7be843b4a162e68651d3911f0357ed464915629)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
517f01e99SJung-uk KimX509_STORE,
6e71b7053SJung-uk KimX509_STORE_add_cert, X509_STORE_add_crl, X509_STORE_set_depth,
7e71b7053SJung-uk KimX509_STORE_set_flags, X509_STORE_set_purpose, X509_STORE_set_trust,
817f01e99SJung-uk KimX509_STORE_add_lookup,
9b077aed3SPierre ProncheryX509_STORE_load_file_ex, X509_STORE_load_file, X509_STORE_load_path,
10b077aed3SPierre ProncheryX509_STORE_load_store_ex, X509_STORE_load_store,
11b077aed3SPierre ProncheryX509_STORE_set_default_paths_ex, X509_STORE_set_default_paths,
12b077aed3SPierre ProncheryX509_STORE_load_locations_ex, X509_STORE_load_locations
13e71b7053SJung-uk Kim- X509_STORE manipulation
14e71b7053SJung-uk Kim
15e71b7053SJung-uk Kim=head1 SYNOPSIS
16e71b7053SJung-uk Kim
17e71b7053SJung-uk Kim #include <openssl/x509_vfy.h>
18e71b7053SJung-uk Kim
1917f01e99SJung-uk Kim typedef x509_store_st X509_STORE;
2017f01e99SJung-uk Kim
21*e7be843bSPierre Pronchery int X509_STORE_add_cert(X509_STORE *xs, X509 *x);
22*e7be843bSPierre Pronchery int X509_STORE_add_crl(X509_STORE *xs, X509_CRL *x);
23e71b7053SJung-uk Kim int X509_STORE_set_depth(X509_STORE *store, int depth);
24*e7be843bSPierre Pronchery int X509_STORE_set_flags(X509_STORE *xs, unsigned long flags);
25*e7be843bSPierre Pronchery int X509_STORE_set_purpose(X509_STORE *xs, int purpose);
26*e7be843bSPierre Pronchery int X509_STORE_set_trust(X509_STORE *xs, int trust);
27e71b7053SJung-uk Kim
2817f01e99SJung-uk Kim X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *store,
2917f01e99SJung-uk Kim                                    X509_LOOKUP_METHOD *meth);
3017f01e99SJung-uk Kim
31*e7be843bSPierre Pronchery int X509_STORE_set_default_paths_ex(X509_STORE *xs, OSSL_LIB_CTX *libctx,
32b077aed3SPierre Pronchery                                     const char *propq);
33*e7be843bSPierre Pronchery int X509_STORE_set_default_paths(X509_STORE *xs);
34*e7be843bSPierre Pronchery int X509_STORE_load_file_ex(X509_STORE *xs, const char *file,
35b077aed3SPierre Pronchery                             OSSL_LIB_CTX *libctx, const char *propq);
36*e7be843bSPierre Pronchery int X509_STORE_load_file(X509_STORE *xs, const char *file);
37*e7be843bSPierre Pronchery int X509_STORE_load_path(X509_STORE *xs, const char *dir);
38*e7be843bSPierre Pronchery int X509_STORE_load_store_ex(X509_STORE *xs, const char *uri,
39b077aed3SPierre Pronchery                              OSSL_LIB_CTX *libctx, const char *propq);
40*e7be843bSPierre Pronchery int X509_STORE_load_store(X509_STORE *xs, const char *uri);
41*e7be843bSPierre Pronchery int X509_STORE_load_locations_ex(X509_STORE *xs, const char *file,
42b077aed3SPierre Pronchery                                  const char *dir, OSSL_LIB_CTX *libctx,
43b077aed3SPierre Pronchery                                  const char *propq);
44*e7be843bSPierre Pronchery int X509_STORE_load_locations(X509_STORE *xs,
45e71b7053SJung-uk Kim                               const char *file, const char *dir);
46e71b7053SJung-uk Kim
47e71b7053SJung-uk Kim=head1 DESCRIPTION
48e71b7053SJung-uk Kim
49e71b7053SJung-uk KimThe B<X509_STORE> structure is intended to be a consolidated mechanism for
50e71b7053SJung-uk Kimholding information about X.509 certificates and CRLs, and constructing
51e71b7053SJung-uk Kimand validating chains of certificates terminating in trusted roots.
52e71b7053SJung-uk KimIt admits multiple lookup mechanisms and efficient scaling performance
53e71b7053SJung-uk Kimwith large numbers of certificates, and a great deal of flexibility in
54e71b7053SJung-uk Kimhow validation and policy checks are performed.
55e71b7053SJung-uk Kim
56b077aed3SPierre ProncheryDetails of the chain building and checking process are described in
57b077aed3SPierre ProncheryL<openssl-verification-options(1)/Certification Path Building> and
58b077aed3SPierre ProncheryL<openssl-verification-options(1)/Certification Path Validation>.
59b077aed3SPierre Pronchery
60e71b7053SJung-uk KimL<X509_STORE_new(3)> creates an empty B<X509_STORE> structure, which contains
61e71b7053SJung-uk Kimno information about trusted certificates or where such certificates
62e71b7053SJung-uk Kimare located on disk, and is generally not usable.  Normally, trusted
63e71b7053SJung-uk Kimcertificates will be added to the B<X509_STORE> to prepare it for use,
64e71b7053SJung-uk Kimvia mechanisms such as X509_STORE_add_lookup() and X509_LOOKUP_file(), or
65e71b7053SJung-uk KimPEM_read_bio_X509_AUX() and X509_STORE_add_cert().  CRLs can also be added,
66e71b7053SJung-uk Kimand many behaviors configured as desired.
67e71b7053SJung-uk Kim
68e71b7053SJung-uk KimOnce the B<X509_STORE> is suitably configured, X509_STORE_CTX_new() is
69e71b7053SJung-uk Kimused to instantiate a single-use B<X509_STORE_CTX> for each chain-building
70e71b7053SJung-uk Kimand verification operation.  That process includes providing the end-entity
71e71b7053SJung-uk Kimcertificate to be verified and an additional set of untrusted certificates
72e71b7053SJung-uk Kimthat may be used in chain-building.  As such, it is expected that the
73e71b7053SJung-uk Kimcertificates included in the B<X509_STORE> are certificates that represent
74e71b7053SJung-uk Kimtrusted entities such as root certificate authorities (CAs).
75e71b7053SJung-uk KimOpenSSL represents these trusted certificates internally as B<X509> objects
76e71b7053SJung-uk Kimwith an associated B<X509_CERT_AUX>, as are produced by
77e71b7053SJung-uk KimPEM_read_bio_X509_AUX() and similar routines that refer to X509_AUX.
78e71b7053SJung-uk KimThe public interfaces that operate on such trusted certificates still
79e71b7053SJung-uk Kimoperate on pointers to B<X509> objects, though.
80e71b7053SJung-uk Kim
81e71b7053SJung-uk KimX509_STORE_add_cert() and X509_STORE_add_crl() add the respective object
82e71b7053SJung-uk Kimto the B<X509_STORE>'s local storage.  Untrusted objects should not be
83da327cd2SJung-uk Kimadded in this way.  The added object's reference count is incremented by one,
84da327cd2SJung-uk Kimhence the caller retains ownership of the object and needs to free it when it
85da327cd2SJung-uk Kimis no longer needed.
86e71b7053SJung-uk Kim
87e71b7053SJung-uk KimX509_STORE_set_depth(), X509_STORE_set_flags(), X509_STORE_set_purpose(),
88e71b7053SJung-uk KimX509_STORE_set_trust(), and X509_STORE_set1_param() set the default values
89e71b7053SJung-uk Kimfor the corresponding values used in certificate chain validation.  Their
90e71b7053SJung-uk Kimbehavior is documented in the corresponding B<X509_VERIFY_PARAM> manual
91*e7be843bSPierre Proncherypages, e.g., L<X509_VERIFY_PARAM_set_depth(3)>. The B<X509_STORE> B<MUST NOT> be NULL.
92e71b7053SJung-uk Kim
9317f01e99SJung-uk KimX509_STORE_add_lookup() finds or creates a L<X509_LOOKUP(3)> with the
9417f01e99SJung-uk KimL<X509_LOOKUP_METHOD(3)> I<meth> and adds it to the B<X509_STORE>
9517f01e99SJung-uk KimI<store>.  This also associates the B<X509_STORE> with the lookup, so
9617f01e99SJung-uk KimB<X509_LOOKUP> functions can look up objects in that store.
9717f01e99SJung-uk Kim
98b077aed3SPierre ProncheryX509_STORE_load_file_ex() loads trusted certificate(s) into an
99b077aed3SPierre ProncheryB<X509_STORE> from a given file. The library context I<libctx> and property
100b077aed3SPierre Proncheryquery I<propq> are used when fetching algorithms from providers.
101e71b7053SJung-uk Kim
102b077aed3SPierre ProncheryX509_STORE_load_file() is similar to X509_STORE_load_file_ex() but
103b077aed3SPierre Proncheryuses NULL for the library context I<libctx> and property query I<propq>.
104b077aed3SPierre Pronchery
105b077aed3SPierre ProncheryX509_STORE_load_path() loads trusted certificate(s) into an
106b077aed3SPierre ProncheryB<X509_STORE> from a given directory path.
107b077aed3SPierre ProncheryThe certificates in the directory must be in hashed form, as
108b077aed3SPierre Proncherydocumented in L<X509_LOOKUP_hash_dir(3)>.
109b077aed3SPierre Pronchery
110b077aed3SPierre ProncheryX509_STORE_load_store_ex() loads trusted certificate(s) into an
111b077aed3SPierre ProncheryB<X509_STORE> from a store at a given URI. The library context I<libctx> and
112b077aed3SPierre Proncheryproperty query I<propq> are used when fetching algorithms from providers.
113b077aed3SPierre Pronchery
114b077aed3SPierre ProncheryX509_STORE_load_store() is similar to X509_STORE_load_store_ex() but
115b077aed3SPierre Proncheryuses NULL for the library context I<libctx> and property query I<propq>.
116b077aed3SPierre Pronchery
117b077aed3SPierre ProncheryX509_STORE_load_locations_ex() combines
118b077aed3SPierre ProncheryX509_STORE_load_file_ex() and X509_STORE_load_path() for a given file
119b077aed3SPierre Proncheryand/or directory path.
120b077aed3SPierre ProncheryIt is permitted to specify just a file, just a directory, or both
121e71b7053SJung-uk Kimpaths.
122e71b7053SJung-uk Kim
123b077aed3SPierre ProncheryX509_STORE_load_locations() is similar to X509_STORE_load_locations_ex()
124b077aed3SPierre Proncherybut uses NULL for the library context I<libctx> and property query I<propq>.
125b077aed3SPierre Pronchery
126b077aed3SPierre ProncheryX509_STORE_set_default_paths_ex() is somewhat misnamed, in that it does
127b077aed3SPierre Proncherynot set what default paths should be used for loading certificates.  Instead,
128b077aed3SPierre Proncheryit loads certificates into the B<X509_STORE> from the hardcoded default
129b077aed3SPierre Proncherypaths. The library context I<libctx> and property query I<propq> are used when
130b077aed3SPierre Proncheryfetching algorithms from providers.
131b077aed3SPierre Pronchery
132b077aed3SPierre ProncheryX509_STORE_set_default_paths() is similar to
133b077aed3SPierre ProncheryX509_STORE_set_default_paths_ex() but uses NULL for the library
134b077aed3SPierre Proncherycontext I<libctx> and property query I<propq>.
135b077aed3SPierre Pronchery
136e71b7053SJung-uk Kim=head1 RETURN VALUES
137e71b7053SJung-uk Kim
138e71b7053SJung-uk KimX509_STORE_add_cert(), X509_STORE_add_crl(), X509_STORE_set_depth(),
139b077aed3SPierre ProncheryX509_STORE_set_flags(), X509_STORE_set_purpose(), X509_STORE_set_trust(),
140b077aed3SPierre ProncheryX509_STORE_load_file_ex(), X509_STORE_load_file(),
141b077aed3SPierre ProncheryX509_STORE_load_path(),
142b077aed3SPierre ProncheryX509_STORE_load_store_ex(), X509_STORE_load_store(),
143b077aed3SPierre ProncheryX509_STORE_load_locations_ex(), X509_STORE_load_locations(),
144b077aed3SPierre ProncheryX509_STORE_set_default_paths_ex() and X509_STORE_set_default_paths()
145b077aed3SPierre Proncheryreturn 1 on success or 0 on failure.
146e71b7053SJung-uk Kim
14717f01e99SJung-uk KimX509_STORE_add_lookup() returns the found or created
14817f01e99SJung-uk KimL<X509_LOOKUP(3)>, or NULL on error.
14917f01e99SJung-uk Kim
150e71b7053SJung-uk Kim=head1 SEE ALSO
151e71b7053SJung-uk Kim
152e71b7053SJung-uk KimL<X509_LOOKUP_hash_dir(3)>.
153e71b7053SJung-uk KimL<X509_VERIFY_PARAM_set_depth(3)>.
154e71b7053SJung-uk KimL<X509_STORE_new(3)>,
155e71b7053SJung-uk KimL<X509_STORE_get0_param(3)>
156e71b7053SJung-uk Kim
157b077aed3SPierre Pronchery=head1 HISTORY
158b077aed3SPierre Pronchery
159b077aed3SPierre ProncheryThe functions X509_STORE_set_default_paths_ex(),
160b077aed3SPierre ProncheryX509_STORE_load_file_ex(), X509_STORE_load_store_ex() and
161b077aed3SPierre ProncheryX509_STORE_load_locations_ex() were added in OpenSSL 3.0.
162b077aed3SPierre Pronchery
163e71b7053SJung-uk Kim=head1 COPYRIGHT
164e71b7053SJung-uk Kim
165*e7be843bSPierre ProncheryCopyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
166e71b7053SJung-uk Kim
167b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
168e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
169e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
170e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
171e71b7053SJung-uk Kim
172e71b7053SJung-uk Kim=cut
173