OSSL_CMP_exec_certreq.pod 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. =pod
  2. =head1 NAME
  3. OSSL_CMP_exec_certreq,
  4. OSSL_CMP_exec_IR_ses,
  5. OSSL_CMP_exec_CR_ses,
  6. OSSL_CMP_exec_P10CR_ses,
  7. OSSL_CMP_exec_KUR_ses,
  8. OSSL_CMP_IR,
  9. OSSL_CMP_CR,
  10. OSSL_CMP_P10CR,
  11. OSSL_CMP_KUR,
  12. OSSL_CMP_try_certreq,
  13. OSSL_CMP_exec_RR_ses,
  14. OSSL_CMP_exec_GENM_ses,
  15. OSSL_CMP_get1_caCerts,
  16. OSSL_CMP_get1_rootCaKeyUpdate
  17. - functions implementing CMP client transactions
  18. =head1 SYNOPSIS
  19. #include <openssl/cmp.h>
  20. X509 *OSSL_CMP_exec_certreq(OSSL_CMP_CTX *ctx, int req_type,
  21. const OSSL_CRMF_MSG *crm);
  22. X509 *OSSL_CMP_exec_IR_ses(OSSL_CMP_CTX *ctx);
  23. X509 *OSSL_CMP_exec_CR_ses(OSSL_CMP_CTX *ctx);
  24. X509 *OSSL_CMP_exec_P10CR_ses(OSSL_CMP_CTX *ctx);
  25. X509 *OSSL_CMP_exec_KUR_ses(OSSL_CMP_CTX *ctx);
  26. #define OSSL_CMP_IR
  27. #define OSSL_CMP_CR
  28. #define OSSL_CMP_P10CR
  29. #define OSSL_CMP_KUR
  30. int OSSL_CMP_try_certreq(OSSL_CMP_CTX *ctx, int req_type,
  31. const OSSL_CRMF_MSG *crm, int *checkAfter);
  32. int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx);
  33. STACK_OF(OSSL_CMP_ITAV) *OSSL_CMP_exec_GENM_ses(OSSL_CMP_CTX *ctx);
  34. int OSSL_CMP_get1_caCerts(OSSL_CMP_CTX *ctx, STACK_OF(X509) **out);
  35. int OSSL_CMP_get1_rootCaKeyUpdate(OSSL_CMP_CTX *ctx,
  36. const X509 *oldWithOld, X509 **newWithNew,
  37. X509 **newWithOld, X509 **oldWithNew);
  38. =head1 DESCRIPTION
  39. This is the OpenSSL API for doing CMP (Certificate Management Protocol)
  40. client-server transactions, i.e., sequences of CMP requests and responses.
  41. All functions take a populated OSSL_CMP_CTX structure as their first argument.
  42. Usually the server name, port, and path ("CMP alias") need to be set, as well as
  43. credentials the client can use for authenticating itself to the server.
  44. In order to authenticate the server the client typically needs a trust store.
  45. The functions return their respective main results directly, while there are
  46. also accessor functions for retrieving various results and status information
  47. from the I<ctx>. See L<OSSL_CMP_CTX_new(3)> etc. for details.
  48. The default conveying protocol is HTTP.
  49. Timeout values may be given per request-response pair and per transaction.
  50. See L<OSSL_CMP_MSG_http_perform(3)> for details.
  51. OSSL_CMP_exec_IR_ses() requests an initial certificate from the given PKI.
  52. OSSL_CMP_exec_CR_ses() requests an additional certificate.
  53. OSSL_CMP_exec_P10CR_ses() conveys a legacy PKCS#10 CSR requesting a certificate.
  54. OSSL_CMP_exec_KUR_ses() obtains an updated certificate.
  55. These four types of certificate enrollment are implemented as macros
  56. calling OSSL_CMP_exec_certreq().
  57. OSSL_CMP_exec_certreq() performs a certificate request of the type specified
  58. by the I<req_type> parameter, which may be IR, CR, P10CR, or KUR.
  59. For IR, CR, and KUR, the certificate template to be used in the request
  60. may be supplied via the I<crm> parameter pointing to a CRMF structure.
  61. Typically I<crm> is NULL, then the template ingredients are taken from I<ctx>
  62. and need to be filled in using L<OSSL_CMP_CTX_set1_subjectName(3)>,
  63. L<OSSL_CMP_CTX_set0_newPkey(3)>, L<OSSL_CMP_CTX_set1_oldCert(3)>, etc.
  64. For P10CR, L<OSSL_CMP_CTX_set1_p10CSR(3)> needs to be used instead.
  65. The enrollment session may be blocked (with polling and sleeping in between)
  66. until the server side can fully process and ultimately answer the request.
  67. OSSL_CMP_try_certreq() is an alternative to the above functions that is
  68. more flexible regarding what to do after receiving a checkAfter value.
  69. When called for the first time (with no certificate request in progress for
  70. the given I<ctx>) it starts a new transaction by sending a certificate request
  71. constructed as stated above using the I<req_type> and optional I<crm> parameter.
  72. Otherwise (when according to I<ctx> a 'waiting' status has been received before)
  73. it continues polling for the pending request
  74. unless the I<req_type> argument is < 0, which aborts the request.
  75. If the requested certificate is available the function returns 1 and the
  76. caller can use L<OSSL_CMP_CTX_get0_newCert(3)> to retrieve the new certificate.
  77. If no error occurred but no certificate is available yet then
  78. OSSL_CMP_try_certreq() remembers in the CMP context that it should be retried
  79. and returns -1 after assigning the received checkAfter value
  80. via the output pointer argument (unless it is NULL).
  81. The checkAfter value indicates the number of seconds the caller should let pass
  82. before trying again. The caller is free to sleep for the given number of seconds
  83. or for some other time and/or to do anything else before retrying by calling
  84. OSSL_CMP_try_certreq() again with the same parameter values as before.
  85. OSSL_CMP_try_certreq() then polls
  86. to see whether meanwhile the requested certificate is available.
  87. If the caller decides to abort the pending certificate request and provides
  88. a negative value as the I<req_type> argument then OSSL_CMP_try_certreq()
  89. aborts the CMP transaction by sending an error message to the server.
  90. OSSL_CMP_exec_RR_ses() requests the revocation of the certificate
  91. specified in the I<ctx> using the issuer DN and serial number set by
  92. OSSL_CMP_CTX_set1_issuer(3) and OSSL_CMP_CTX_set1_serialNumber(3), respectively,
  93. otherwise the issuer DN and serial number
  94. of the certificate set by L<OSSL_CMP_CTX_set1_oldCert(3)>,
  95. otherwise the subject DN and public key
  96. of the certificate signing request set by L<OSSL_CMP_CTX_set1_p10CSR(3)>.
  97. RFC 4210 is vague in which PKIStatus should be returned by the server.
  98. We take "accepted" and "grantedWithMods" as clear success and handle
  99. "revocationWarning" and "revocationNotification" just as warnings because CAs
  100. typically return them as an indication that the certificate was already revoked.
  101. "rejection" is a clear error. The values "waiting" and "keyUpdateWarning"
  102. make no sense for revocation and thus are treated as an error as well.
  103. The revocation session may be blocked (with polling and sleeping in between)
  104. until the server can fully process and ultimately answer the request.
  105. OSSL_CMP_exec_GENM_ses() sends a genm general message containing the sequence of
  106. infoType and infoValue pairs (InfoTypeAndValue; short: B<ITAV>)
  107. optionally provided in the I<ctx> using L<OSSL_CMP_CTX_push0_genm_ITAV(3)>.
  108. The message exchange may be blocked (with polling and sleeping in between)
  109. until the server can fully process and ultimately answer the request.
  110. On success the function records in I<ctx> status B<OSSL_CMP_PKISTATUS_accepted>
  111. and returns the list of B<ITAV>s received in a genp response message.
  112. This can be used, for instance,
  113. with infoType C<signKeyPairTypes> to obtain the set of signature
  114. algorithm identifiers that the CA will certify for subject public keys.
  115. See RFC 4210 section 5.3.19 and appendix E.5 for details.
  116. Functions implementing more specific genm/genp exchanges are described next.
  117. OSSL_CMP_get1_caCerts() uses a genm/genp message exchange with infoType caCerts
  118. to obtain a list of CA certificates from the CMP server referenced by I<ctx>.
  119. On success it assigns to I<*out> the list of certificates received,
  120. which must be freed by the caller.
  121. NULL output means that no CA certificates were provided by the server.
  122. OSSL_CMP_get1_rootCaKeyUpdate() uses a genm request message
  123. with infoType rootCaCert to obtain from the CMP server referenced by I<ctx>
  124. in a genp response message with infoType rootCaKeyUpdate any update of the
  125. given root CA certificate I<oldWithOld> and verifies it as far as possible.
  126. See RFC 4210 section 4.4 for details.
  127. On success it assigns to I<*newWithNew> the root certificate received.
  128. When the I<newWithOld> and I<oldWithNew> output parameters are not NULL,
  129. it assigns to them the corresponding transition certificates.
  130. NULL means that the respective certificate was not provided by the server.
  131. All certificates obtained this way must be freed by the caller.
  132. B<WARNING:>
  133. The I<newWithNew> certificate is meant to be a certificate that will be trusted.
  134. The trust placed in it cannot be stronger than the trust placed in
  135. the I<oldwithold> certificate if present, otherwise it cannot be stronger than
  136. the weakest trust in any of the certificates in the trust store of I<ctx>.
  137. =head1 NOTES
  138. CMP is defined in RFC 4210 (and CRMF in RFC 4211).
  139. The CMP client implementation is limited to one request per CMP message
  140. (and consequently to at most one response component per CMP message).
  141. When a client obtains from a CMP server CA certificates that it is going to
  142. trust, for instance via the caPubs field of a certificate response or using
  143. functions like OSSL_CMP_get1_caCerts() and OSSL_CMP_get1_rootCaKeyUpdate(),
  144. authentication of the CMP server is particularly critical.
  145. So special care must be taken setting up server authentication in I<ctx>
  146. using functions such as
  147. L<OSSL_CMP_CTX_set0_trusted(3)> (for certificate-based authentication) or
  148. L<OSSL_CMP_CTX_set1_secretValue(3)> (for MAC-based protection).
  149. If authentication is certificate-based, L<OSSL_CMP_CTX_get0_validatedSrvCert(3)>
  150. should be used to obtain the server validated certificate
  151. and perform an authorization check based on it.
  152. =head1 RETURN VALUES
  153. OSSL_CMP_exec_certreq(), OSSL_CMP_exec_IR_ses(), OSSL_CMP_exec_CR_ses(),
  154. OSSL_CMP_exec_P10CR_ses(), and OSSL_CMP_exec_KUR_ses() return a
  155. pointer to the newly obtained X509 certificate on success, NULL on error.
  156. This pointer will be freed implicitly by OSSL_CMP_CTX_free() or
  157. CSSL_CMP_CTX_reinit().
  158. OSSL_CMP_try_certreq() returns 1 if the requested certificate is available
  159. via L<OSSL_CMP_CTX_get0_newCert(3)>
  160. or on successfully aborting a pending certificate request, 0 on error, and -1
  161. in case a 'waiting' status has been received and checkAfter value is available.
  162. In the latter case L<OSSL_CMP_CTX_get0_newCert(3)> yields NULL
  163. and the output parameter I<checkAfter> has been used to
  164. assign the received value unless I<checkAfter> is NULL.
  165. OSSL_CMP_exec_RR_ses(), OSSL_CMP_get1_caCerts(),
  166. and OSSL_CMP_get1_rootCaKeyUpdate()
  167. return 1 on success, 0 on error.
  168. OSSL_CMP_exec_GENM_ses() returns NULL on error,
  169. otherwise a pointer to the sequence of B<ITAV> received, which may be empty.
  170. This pointer must be freed by the caller.
  171. =head1 EXAMPLES
  172. See OSSL_CMP_CTX for examples on how to prepare the context for these
  173. functions.
  174. =head1 SEE ALSO
  175. L<OSSL_CMP_CTX_new(3)>, L<OSSL_CMP_CTX_free(3)>,
  176. L<OSSL_CMP_CTX_set1_subjectName(3)>, L<OSSL_CMP_CTX_set0_newPkey(3)>,
  177. L<OSSL_CMP_CTX_set1_p10CSR(3)>, L<OSSL_CMP_CTX_set1_oldCert(3)>,
  178. L<OSSL_CMP_CTX_get0_newCert(3)>, L<OSSL_CMP_CTX_push0_genm_ITAV(3)>,
  179. L<OSSL_CMP_MSG_http_perform(3)>
  180. =head1 HISTORY
  181. The OpenSSL CMP support was added in OpenSSL 3.0.
  182. OSSL_CMP_get1_caCerts() and OSSL_CMP_get1_rootCaKeyUpdate()
  183. were added in OpenSSL 3.2.
  184. Support for delayed delivery of all types of response messages
  185. was added in OpenSSL 3.3.
  186. =head1 COPYRIGHT
  187. Copyright 2007-2023 The OpenSSL Project Authors. All Rights Reserved.
  188. Licensed under the Apache License 2.0 (the "License"). You may not use
  189. this file except in compliance with the License. You can obtain a copy
  190. in the file LICENSE in the source distribution or at
  191. L<https://www.openssl.org/source/license.html>.
  192. =cut