X509_STORE_CTX_new.pod 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. =pod
  2. =head1 NAME
  3. X509_STORE_CTX_new_with_libctx, X509_STORE_CTX_new, X509_STORE_CTX_cleanup,
  4. X509_STORE_CTX_free, X509_STORE_CTX_init, X509_STORE_CTX_set0_trusted_stack,
  5. X509_STORE_CTX_set_cert, X509_STORE_CTX_set0_crls,
  6. X509_STORE_CTX_get0_chain, X509_STORE_CTX_set0_verified_chain,
  7. X509_STORE_CTX_get0_param, X509_STORE_CTX_set0_param,
  8. X509_STORE_CTX_get0_untrusted, X509_STORE_CTX_set0_untrusted,
  9. X509_STORE_CTX_get_num_untrusted,
  10. X509_STORE_CTX_set_default,
  11. X509_STORE_CTX_set_verify,
  12. X509_STORE_CTX_verify_fn
  13. - X509_STORE_CTX initialisation
  14. =head1 SYNOPSIS
  15. #include <openssl/x509_vfy.h>
  16. X509_STORE_CTX *X509_STORE_CTX_new_with_libctx(OPENSSL_CTX *libctx,
  17. const char *propq);
  18. X509_STORE_CTX *X509_STORE_CTX_new(void);
  19. void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
  20. void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
  21. int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
  22. X509 *x509, STACK_OF(X509) *chain);
  23. void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
  24. void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x);
  25. STACK_OF(X509) *X509_STORE_CTX_get0_chain(const X509_STORE_CTX *ctx);
  26. void X509_STORE_CTX_set0_verified_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *chain);
  27. void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk);
  28. X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(const X509_STORE_CTX *ctx);
  29. void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);
  30. int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
  31. STACK_OF(X509)* X509_STORE_CTX_get0_untrusted(const X509_STORE_CTX *ctx);
  32. void X509_STORE_CTX_set0_untrusted(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
  33. int X509_STORE_CTX_get_num_untrusted(const X509_STORE_CTX *ctx);
  34. typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *);
  35. void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, X509_STORE_CTX_verify_fn verify);
  36. =head1 DESCRIPTION
  37. These functions initialise an B<X509_STORE_CTX> structure for subsequent use
  38. by X509_verify_cert().
  39. X509_STORE_CTX_new_with_libctx() returns a newly initialised B<X509_STORE_CTX>
  40. structure associated with the specified library context I<libctx> and property
  41. query string I<propq>. Any cryptographic algorithms fetched while performing
  42. processing with the X509_STORE_CTX will use that library context and property
  43. query string.
  44. X509_STORE_CTX_new() is the same as X509_STORE_CTX_new_with_libctx() except that
  45. the default library context and a NULL property query string are used.
  46. X509_STORE_CTX_cleanup() internally cleans up an B<X509_STORE_CTX> structure.
  47. The context can then be reused with a new call to X509_STORE_CTX_init().
  48. X509_STORE_CTX_free() completely frees up I<ctx>. After this call I<ctx>
  49. is no longer valid.
  50. If I<ctx> is NULL nothing is done.
  51. X509_STORE_CTX_init() sets up I<ctx> for a subsequent verification operation.
  52. It must be called before each call to X509_verify_cert(), i.e. a I<ctx> is only
  53. good for one call to X509_verify_cert(); if you want to verify a second
  54. certificate with the same I<ctx> then you must call X509_STORE_CTX_cleanup()
  55. and then X509_STORE_CTX_init() again before the second call to
  56. X509_verify_cert(). The trusted certificate store is set to I<store>, the end
  57. entity certificate to be verified is set to I<x509> and a set of additional
  58. certificates (which will be untrusted but may be used to build the chain) in
  59. I<chain>. Any or all of the I<store>, I<x509> and I<chain> parameters can be
  60. B<NULL>.
  61. X509_STORE_CTX_set0_trusted_stack() sets the set of trusted certificates of
  62. I<ctx> to I<sk>. This is an alternative way of specifying trusted certificates
  63. instead of using an B<X509_STORE>.
  64. X509_STORE_CTX_set_cert() sets the certificate to be verified in I<ctx> to
  65. I<x>.
  66. X509_STORE_CTX_set0_verified_chain() sets the validated chain used
  67. by I<ctx> to be I<chain>.
  68. Ownership of the chain is transferred to I<ctx> and should not be
  69. free'd by the caller.
  70. X509_STORE_CTX_get0_chain() returns the internal pointer used by the
  71. I<ctx> that contains the validated chain.
  72. X509_STORE_CTX_set0_crls() sets a set of CRLs to use to aid certificate
  73. verification to I<sk>. These CRLs will only be used if CRL verification is
  74. enabled in the associated B<X509_VERIFY_PARAM> structure. This might be
  75. used where additional "useful" CRLs are supplied as part of a protocol,
  76. for example in a PKCS#7 structure.
  77. X509_STORE_CTX_get0_param() retrieves an internal pointer
  78. to the verification parameters associated with I<ctx>.
  79. X509_STORE_CTX_get0_untrusted() retrieves an internal pointer to the
  80. stack of untrusted certificates associated with I<ctx>.
  81. X509_STORE_CTX_set0_untrusted() sets the internal point to the stack
  82. of untrusted certificates associated with I<ctx> to I<sk>.
  83. X509_STORE_CTX_set0_param() sets the internal verification parameter pointer
  84. to I<param>. After this call B<param> should not be used.
  85. X509_STORE_CTX_set_default() looks up and sets the default verification
  86. method to I<name>. This uses the function X509_VERIFY_PARAM_lookup() to
  87. find an appropriate set of parameters from I<name>.
  88. X509_STORE_CTX_get_num_untrusted() returns the number of untrusted certificates
  89. that were used in building the chain following a call to X509_verify_cert().
  90. X509_STORE_CTX_set_verify() provides the capability for overriding the default
  91. verify function. This function is responsible for verifying chain signatures and
  92. expiration times.
  93. A verify function is defined as an X509_STORE_CTX_verify type which has the
  94. following signature:
  95. int (*verify)(X509_STORE_CTX *);
  96. This function should receive the current X509_STORE_CTX as a parameter and
  97. return 1 on success or 0 on failure.
  98. =head1 NOTES
  99. The certificates and CRLs in a store are used internally and should B<not>
  100. be freed up until after the associated B<X509_STORE_CTX> is freed.
  101. =head1 BUGS
  102. The certificates and CRLs in a context are used internally and should B<not>
  103. be freed up until after the associated B<X509_STORE_CTX> is freed. Copies
  104. should be made or reference counts increased instead.
  105. =head1 RETURN VALUES
  106. X509_STORE_CTX_new() returns a newly allocates context or B<NULL> is an
  107. error occurred.
  108. X509_STORE_CTX_init() returns 1 for success or 0 if an error occurred.
  109. X509_STORE_CTX_get0_param() returns a pointer to an B<X509_VERIFY_PARAM>
  110. structure or B<NULL> if an error occurred.
  111. X509_STORE_CTX_cleanup(), X509_STORE_CTX_free(),
  112. X509_STORE_CTX_set0_trusted_stack(),
  113. X509_STORE_CTX_set_cert(),
  114. X509_STORE_CTX_set0_crls() and X509_STORE_CTX_set0_param() do not return
  115. values.
  116. X509_STORE_CTX_set_default() returns 1 for success or 0 if an error occurred.
  117. X509_STORE_CTX_get_num_untrusted() returns the number of untrusted certificates
  118. used.
  119. =head1 SEE ALSO
  120. L<X509_verify_cert(3)>
  121. L<X509_VERIFY_PARAM_set_flags(3)>
  122. =head1 HISTORY
  123. The X509_STORE_CTX_set0_crls() function was added in OpenSSL 1.0.0.
  124. The X509_STORE_CTX_get_num_untrusted() function was added in OpenSSL 1.1.0.
  125. The X509_STORE_CTX_new_with_libctx() function was added in OpenSSL 3.0.
  126. =head1 COPYRIGHT
  127. Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved.
  128. Licensed under the Apache License 2.0 (the "License"). You may not use
  129. this file except in compliance with the License. You can obtain a copy
  130. in the file LICENSE in the source distribution or at
  131. L<https://www.openssl.org/source/license.html>.
  132. =cut