1b077aed3SPierre Pronchery=pod 2b077aed3SPierre Pronchery 3b077aed3SPierre Pronchery=head1 NAME 4b077aed3SPierre Pronchery 5b077aed3SPierre ProncheryOSSL_CMP_exec_certreq, 6b077aed3SPierre ProncheryOSSL_CMP_exec_IR_ses, 7b077aed3SPierre ProncheryOSSL_CMP_exec_CR_ses, 8b077aed3SPierre ProncheryOSSL_CMP_exec_P10CR_ses, 9b077aed3SPierre ProncheryOSSL_CMP_exec_KUR_ses, 10b077aed3SPierre ProncheryOSSL_CMP_IR, 11b077aed3SPierre ProncheryOSSL_CMP_CR, 12b077aed3SPierre ProncheryOSSL_CMP_P10CR, 13b077aed3SPierre ProncheryOSSL_CMP_KUR, 14b077aed3SPierre ProncheryOSSL_CMP_try_certreq, 15b077aed3SPierre ProncheryOSSL_CMP_exec_RR_ses, 16b077aed3SPierre ProncheryOSSL_CMP_exec_GENM_ses 17b077aed3SPierre Pronchery- functions implementing CMP client transactions 18b077aed3SPierre Pronchery 19b077aed3SPierre Pronchery=head1 SYNOPSIS 20b077aed3SPierre Pronchery 21b077aed3SPierre Pronchery #include <openssl/cmp.h> 22b077aed3SPierre Pronchery 23b077aed3SPierre Pronchery X509 *OSSL_CMP_exec_certreq(OSSL_CMP_CTX *ctx, int req_type, 24b077aed3SPierre Pronchery const OSSL_CRMF_MSG *crm); 25b077aed3SPierre Pronchery X509 *OSSL_CMP_exec_IR_ses(OSSL_CMP_CTX *ctx); 26b077aed3SPierre Pronchery X509 *OSSL_CMP_exec_CR_ses(OSSL_CMP_CTX *ctx); 27b077aed3SPierre Pronchery X509 *OSSL_CMP_exec_P10CR_ses(OSSL_CMP_CTX *ctx); 28b077aed3SPierre Pronchery X509 *OSSL_CMP_exec_KUR_ses(OSSL_CMP_CTX *ctx); 29b077aed3SPierre Pronchery #define OSSL_CMP_IR 30b077aed3SPierre Pronchery #define OSSL_CMP_CR 31b077aed3SPierre Pronchery #define OSSL_CMP_P10CR 32b077aed3SPierre Pronchery #define OSSL_CMP_KUR 33b077aed3SPierre Pronchery int OSSL_CMP_try_certreq(OSSL_CMP_CTX *ctx, int req_type, 34b077aed3SPierre Pronchery const OSSL_CRMF_MSG *crm, int *checkAfter); 35b077aed3SPierre Pronchery int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx); 36b077aed3SPierre Pronchery STACK_OF(OSSL_CMP_ITAV) *OSSL_CMP_exec_GENM_ses(OSSL_CMP_CTX *ctx); 37b077aed3SPierre Pronchery 38b077aed3SPierre Pronchery=head1 DESCRIPTION 39b077aed3SPierre Pronchery 40b077aed3SPierre ProncheryThis is the OpenSSL API for doing CMP (Certificate Management Protocol) 41b077aed3SPierre Proncheryclient-server transactions, i.e., sequences of CMP requests and responses. 42b077aed3SPierre Pronchery 43b077aed3SPierre ProncheryAll functions take a populated OSSL_CMP_CTX structure as their first argument. 44b077aed3SPierre ProncheryUsually the server name, port, and path ("CMP alias") need to be set, as well as 45*6f1af0d7SPierre Proncherycredentials the client can use for authenticating itself to the server. 46b077aed3SPierre ProncheryIn order to authenticate the server the client typically needs a trust store. 47b077aed3SPierre ProncheryThe functions return their respective main results directly, while there are 48b077aed3SPierre Proncheryalso accessor functions for retrieving various results and status information 49b077aed3SPierre Proncheryfrom the I<ctx>. See L<OSSL_CMP_CTX_new(3)> etc. for details. 50b077aed3SPierre Pronchery 51b077aed3SPierre ProncheryThe default conveying protocol is HTTP. 52b077aed3SPierre ProncheryTimeout values may be given per request-response pair and per transaction. 53b077aed3SPierre ProncherySee L<OSSL_CMP_MSG_http_perform(3)> for details. 54b077aed3SPierre Pronchery 55b077aed3SPierre ProncheryOSSL_CMP_exec_IR_ses() requests an initial certificate from the given PKI. 56b077aed3SPierre Pronchery 57b077aed3SPierre ProncheryOSSL_CMP_exec_CR_ses() requests an additional certificate. 58b077aed3SPierre Pronchery 59b077aed3SPierre ProncheryOSSL_CMP_exec_P10CR_ses() conveys a legacy PKCS#10 CSR requesting a certificate. 60b077aed3SPierre Pronchery 61b077aed3SPierre ProncheryOSSL_CMP_exec_KUR_ses() obtains an updated certificate. 62b077aed3SPierre Pronchery 63b077aed3SPierre ProncheryThese four types of certificate enrollment are implemented as macros 64b077aed3SPierre Proncherycalling OSSL_CMP_exec_certreq(). 65b077aed3SPierre Pronchery 66b077aed3SPierre ProncheryOSSL_CMP_exec_certreq() performs a certificate request of the type specified 67b077aed3SPierre Proncheryby the I<req_type> parameter, which may be IR, CR, P10CR, or KUR. 68b077aed3SPierre ProncheryFor IR, CR, and KUR, the certificate template to be used in the request 69b077aed3SPierre Proncherymay be supplied via the I<crm> parameter pointing to a CRMF structure. 70b077aed3SPierre ProncheryTypically I<crm> is NULL, then the template ingredients are taken from I<ctx> 71b077aed3SPierre Proncheryand need to be filled in using L<OSSL_CMP_CTX_set1_subjectName(3)>, 72b077aed3SPierre ProncheryL<OSSL_CMP_CTX_set0_newPkey(3)>, L<OSSL_CMP_CTX_set1_oldCert(3)>, etc. 73b077aed3SPierre ProncheryFor P10CR, L<OSSL_CMP_CTX_set1_p10CSR(3)> needs to be used instead. 74b077aed3SPierre ProncheryThe enrollment session may be blocked by sleeping until the addressed 75*6f1af0d7SPierre ProncheryCA (or an intermediate PKI component) can fully process and answer the request. 76b077aed3SPierre Pronchery 77b077aed3SPierre ProncheryOSSL_CMP_try_certreq() is an alternative to the above functions that is 78b077aed3SPierre Proncherymore flexible regarding what to do after receiving a checkAfter value. 79b077aed3SPierre ProncheryWhen called for the first time (with no certificate request in progress for 80b077aed3SPierre Proncherythe given I<ctx>) it starts a new transaction by sending a certificate request 81b077aed3SPierre Proncheryconstructed as stated above using the I<req_type> and optional I<crm> parameter. 82b077aed3SPierre ProncheryOtherwise (when according to I<ctx> a 'waiting' status has been received before) 83b077aed3SPierre Proncheryit continues polling for the pending request 84b077aed3SPierre Proncheryunless the I<req_type> argument is < 0, which aborts the request. 85b077aed3SPierre ProncheryIf the requested certificate is available the function returns 1 and the 86b077aed3SPierre Proncherycaller can use L<OSSL_CMP_CTX_get0_newCert(3)> to retrieve the new certificate. 87b077aed3SPierre ProncheryIf no error occurred but no certificate is available yet then 88b077aed3SPierre ProncheryOSSL_CMP_try_certreq() remembers in the CMP context that it should be retried 89b077aed3SPierre Proncheryand returns -1 after assigning the received checkAfter value 90b077aed3SPierre Proncheryvia the output pointer argument (unless it is NULL). 91b077aed3SPierre ProncheryThe checkAfter value indicates the number of seconds the caller should let pass 92b077aed3SPierre Proncherybefore trying again. The caller is free to sleep for the given number of seconds 93b077aed3SPierre Proncheryor for some other time and/or to do anything else before retrying by calling 94b077aed3SPierre ProncheryOSSL_CMP_try_certreq() again with the same parameter values as before. 95b077aed3SPierre ProncheryOSSL_CMP_try_certreq() then polls 96b077aed3SPierre Proncheryto see whether meanwhile the requested certificate is available. 97b077aed3SPierre ProncheryIf the caller decides to abort the pending certificate request and provides 98b077aed3SPierre Proncherya negative value as the I<req_type> argument then OSSL_CMP_try_certreq() 99b077aed3SPierre Proncheryaborts the CMP transaction by sending an error message to the server. 100b077aed3SPierre Pronchery 101b077aed3SPierre ProncheryOSSL_CMP_exec_RR_ses() requests the revocation of the certificate 102b077aed3SPierre Proncheryspecified in the I<ctx> using L<OSSL_CMP_CTX_set1_oldCert(3)>. 103b077aed3SPierre ProncheryRFC 4210 is vague in which PKIStatus should be returned by the server. 104b077aed3SPierre ProncheryWe take "accepted" and "grantedWithMods" as clear success and handle 105b077aed3SPierre Pronchery"revocationWarning" and "revocationNotification" just as warnings because CAs 106b077aed3SPierre Proncherytypically return them as an indication that the certificate was already revoked. 107b077aed3SPierre Pronchery"rejection" is a clear error. The values "waiting" and "keyUpdateWarning" 108b077aed3SPierre Proncherymake no sense for revocation and thus are treated as an error as well. 109b077aed3SPierre Pronchery 110b077aed3SPierre ProncheryOSSL_CMP_exec_GENM_ses() sends a general message containing the sequence of 111b077aed3SPierre ProncheryinfoType and infoValue pairs (InfoTypeAndValue; short: B<ITAV>) 112b077aed3SPierre Proncheryoptionally provided in the I<ctx> using L<OSSL_CMP_CTX_push0_genm_ITAV(3)>. 113b077aed3SPierre ProncheryOn success it records in I<ctx> the status B<OSSL_CMP_PKISTATUS_accepted> 114b077aed3SPierre Proncheryand returns the list of B<ITAV>s received in the GENP message. 115b077aed3SPierre ProncheryThis can be used, for instance, to poll for CRLs or CA Key Updates. 116b077aed3SPierre ProncherySee RFC 4210 section 5.3.19 and appendix E.5 for details. 117b077aed3SPierre Pronchery 118b077aed3SPierre Pronchery=head1 NOTES 119b077aed3SPierre Pronchery 120b077aed3SPierre ProncheryCMP is defined in RFC 4210 (and CRMF in RFC 4211). 121b077aed3SPierre Pronchery 122*6f1af0d7SPierre ProncheryThe CMP client implementation is limited to one request per CMP message 123b077aed3SPierre Pronchery(and consequently to at most one response component per CMP message). 124b077aed3SPierre Pronchery 125*6f1af0d7SPierre ProncheryWhen a client obtains from a CMP server CA certificates that it is going to 126*6f1af0d7SPierre Proncherytrust, for instance via the caPubs field of a certificate response, 127*6f1af0d7SPierre Proncheryauthentication of the CMP server is particularly critical. 128*6f1af0d7SPierre ProncherySo special care must be taken setting up server authentication in I<ctx> 129*6f1af0d7SPierre Proncheryusing functions such as 130*6f1af0d7SPierre ProncheryL<OSSL_CMP_CTX_set0_trustedStore(3)> (for certificate-based authentication) or 131*6f1af0d7SPierre ProncheryL<OSSL_CMP_CTX_set1_secretValue(3)> (for MAC-based protection). 132*6f1af0d7SPierre Pronchery 133b077aed3SPierre Pronchery=head1 RETURN VALUES 134b077aed3SPierre Pronchery 135b077aed3SPierre ProncheryOSSL_CMP_exec_certreq(), OSSL_CMP_exec_IR_ses(), OSSL_CMP_exec_CR_ses(), 136b077aed3SPierre ProncheryOSSL_CMP_exec_P10CR_ses(), and OSSL_CMP_exec_KUR_ses() return a 137b077aed3SPierre Proncherypointer to the newly obtained X509 certificate on success, NULL on error. 138b077aed3SPierre ProncheryThis pointer will be freed implicitly by OSSL_CMP_CTX_free() or 139b077aed3SPierre ProncheryCSSL_CMP_CTX_reinit(). 140b077aed3SPierre Pronchery 141b077aed3SPierre ProncheryOSSL_CMP_try_certreq() returns 1 if the requested certificate is available 142b077aed3SPierre Proncheryvia L<OSSL_CMP_CTX_get0_newCert(3)> 143b077aed3SPierre Proncheryor on successfully aborting a pending certificate request, 0 on error, and -1 144b077aed3SPierre Proncheryin case a 'waiting' status has been received and checkAfter value is available. 145b077aed3SPierre ProncheryIn the latter case L<OSSL_CMP_CTX_get0_newCert(3)> yields NULL 146b077aed3SPierre Proncheryand the output parameter I<checkAfter> has been used to 147b077aed3SPierre Proncheryassign the received value unless I<checkAfter> is NULL. 148b077aed3SPierre Pronchery 149b077aed3SPierre ProncheryOSSL_CMP_exec_RR_ses() returns 1 on success, 0 on error. 150b077aed3SPierre Pronchery 151b077aed3SPierre ProncheryOSSL_CMP_exec_GENM_ses() returns NULL on error, 152b077aed3SPierre Proncheryotherwise a pointer to the sequence of B<ITAV> received, which may be empty. 153b077aed3SPierre ProncheryThis pointer must be freed by the caller. 154b077aed3SPierre Pronchery 155b077aed3SPierre Pronchery=head1 EXAMPLES 156b077aed3SPierre Pronchery 157b077aed3SPierre ProncherySee OSSL_CMP_CTX for examples on how to prepare the context for these 158b077aed3SPierre Proncheryfunctions. 159b077aed3SPierre Pronchery 160b077aed3SPierre Pronchery=head1 SEE ALSO 161b077aed3SPierre Pronchery 162b077aed3SPierre ProncheryL<OSSL_CMP_CTX_new(3)>, L<OSSL_CMP_CTX_free(3)>, 163b077aed3SPierre ProncheryL<OSSL_CMP_CTX_set1_subjectName(3)>, L<OSSL_CMP_CTX_set0_newPkey(3)>, 164b077aed3SPierre ProncheryL<OSSL_CMP_CTX_set1_p10CSR(3)>, L<OSSL_CMP_CTX_set1_oldCert(3)>, 165b077aed3SPierre ProncheryL<OSSL_CMP_CTX_get0_newCert(3)>, L<OSSL_CMP_CTX_push0_genm_ITAV(3)>, 166b077aed3SPierre ProncheryL<OSSL_CMP_MSG_http_perform(3)> 167b077aed3SPierre Pronchery 168b077aed3SPierre Pronchery=head1 HISTORY 169b077aed3SPierre Pronchery 170b077aed3SPierre ProncheryThe OpenSSL CMP support was added in OpenSSL 3.0. 171b077aed3SPierre Pronchery 172b077aed3SPierre Pronchery=head1 COPYRIGHT 173b077aed3SPierre Pronchery 174*6f1af0d7SPierre ProncheryCopyright 2007-2023 The OpenSSL Project Authors. All Rights Reserved. 175b077aed3SPierre Pronchery 176b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 177b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 178b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 179b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 180b077aed3SPierre Pronchery 181b077aed3SPierre Pronchery=cut 182