OSSL_CMP_CTX_new.pod 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. =pod
  2. =head1 NAME
  3. OSSL_CMP_CTX_new,
  4. OSSL_CMP_CTX_free,
  5. OSSL_CMP_CTX_reinit,
  6. OSSL_CMP_CTX_set_option,
  7. OSSL_CMP_CTX_get_option,
  8. OSSL_CMP_CTX_set_log_cb,
  9. OSSL_CMP_CTX_set_log_verbosity,
  10. OSSL_CMP_CTX_print_errors,
  11. OSSL_CMP_CTX_set1_serverPath,
  12. OSSL_CMP_CTX_set1_serverName,
  13. OSSL_CMP_CTX_set_serverPort,
  14. OSSL_CMP_CTX_set1_proxyName,
  15. OSSL_CMP_CTX_set_proxyPort,
  16. OSSL_CMP_DEFAULT_PORT,
  17. OSSL_CMP_CTX_set_http_cb,
  18. OSSL_CMP_CTX_set_http_cb_arg,
  19. OSSL_CMP_CTX_get_http_cb_arg,
  20. OSSL_cmp_transfer_cb_t,
  21. OSSL_CMP_CTX_set_transfer_cb,
  22. OSSL_CMP_CTX_set_transfer_cb_arg,
  23. OSSL_CMP_CTX_get_transfer_cb_arg,
  24. OSSL_CMP_CTX_set1_srvCert,
  25. OSSL_CMP_CTX_set1_expected_sender,
  26. OSSL_CMP_CTX_set0_trustedStore,
  27. OSSL_CMP_CTX_get0_trustedStore,
  28. OSSL_CMP_CTX_set1_untrusted_certs,
  29. OSSL_CMP_CTX_get0_untrusted_certs,
  30. OSSL_CMP_CTX_set1_clCert,
  31. OSSL_CMP_CTX_set1_pkey,
  32. OSSL_CMP_CTX_set1_referenceValue,
  33. OSSL_CMP_CTX_set1_secretValue,
  34. OSSL_CMP_CTX_set1_recipient,
  35. OSSL_CMP_CTX_push0_geninfo_ITAV,
  36. OSSL_CMP_CTX_set1_extraCertsOut,
  37. OSSL_CMP_CTX_set0_newPkey,
  38. OSSL_CMP_CTX_get0_newPkey,
  39. OSSL_CMP_CTX_set1_issuer,
  40. OSSL_CMP_CTX_set1_subjectName,
  41. OSSL_CMP_CTX_push1_subjectAltName,
  42. OSSL_CMP_CTX_set0_reqExtensions,
  43. OSSL_CMP_CTX_reqExtensions_have_SAN,
  44. OSSL_CMP_CTX_push0_policy,
  45. OSSL_CMP_CTX_set1_oldCert,
  46. OSSL_CMP_CTX_set1_p10CSR,
  47. OSSL_CMP_CTX_push0_genm_ITAV,
  48. OSSL_cmp_certConf_cb_t,
  49. OSSL_CMP_CTX_set_certConf_cb,
  50. OSSL_CMP_CTX_set_certConf_cb_arg,
  51. OSSL_CMP_CTX_get_certConf_cb_arg,
  52. OSSL_CMP_CTX_get_status,
  53. OSSL_CMP_CTX_get0_statusString,
  54. OSSL_CMP_CTX_get_failInfoCode,
  55. OSSL_CMP_CTX_get0_newCert,
  56. OSSL_CMP_CTX_get1_caPubs,
  57. OSSL_CMP_CTX_get1_extraCertsIn,
  58. OSSL_CMP_CTX_set1_transactionID,
  59. OSSL_CMP_CTX_set1_senderNonce
  60. - functions for managing the CMP client context data structure
  61. =head1 SYNOPSIS
  62. #include <openssl/cmp.h>
  63. OSSL_CMP_CTX *OSSL_CMP_CTX_new(void);
  64. void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx);
  65. int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx);
  66. int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val);
  67. int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt);
  68. /* logging and error reporting: */
  69. int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_log_cb_t cb);
  70. #define OSSL_CMP_CTX_set_log_verbosity(ctx, level)
  71. void OSSL_CMP_CTX_print_errors(OSSL_CMP_CTX *ctx);
  72. /* message transfer: */
  73. int OSSL_CMP_CTX_set1_serverPath(OSSL_CMP_CTX *ctx, const char *path);
  74. int OSSL_CMP_CTX_set1_serverName(OSSL_CMP_CTX *ctx, const char *name);
  75. int OSSL_CMP_CTX_set_serverPort(OSSL_CMP_CTX *ctx, int port);
  76. int OSSL_CMP_CTX_set1_proxyName(OSSL_CMP_CTX *ctx, const char *name);
  77. int OSSL_CMP_CTX_set_proxyPort(OSSL_CMP_CTX *ctx, int port);
  78. #define OSSL_CMP_DEFAULT_PORT 80
  79. int OSSL_CMP_CTX_set_http_cb(OSSL_CMP_CTX *ctx, HTTP_bio_cb_t cb);
  80. int OSSL_CMP_CTX_set_http_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
  81. void *OSSL_CMP_CTX_get_http_cb_arg(const OSSL_CMP_CTX *ctx);
  82. typedef OSSL_CMP_MSG *(*OSSL_cmp_transfer_cb_t)(OSSL_CMP_CTX *ctx,
  83. const OSSL_CMP_MSG *req);
  84. int OSSL_CMP_CTX_set_transfer_cb(OSSL_CMP_CTX *ctx,
  85. OSSL_cmp_transfer_cb_t cb);
  86. int OSSL_CMP_CTX_set_transfer_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
  87. void *OSSL_CMP_CTX_get_transfer_cb_arg(const OSSL_CMP_CTX *ctx);
  88. /* server authentication: */
  89. int OSSL_CMP_CTX_set1_srvCert(OSSL_CMP_CTX *ctx, X509 *cert);
  90. int OSSL_CMP_CTX_set1_expected_sender(OSSL_CMP_CTX *ctx,
  91. const X509_NAME *name);
  92. int OSSL_CMP_CTX_set0_trustedStore(OSSL_CMP_CTX *ctx, X509_STORE *store);
  93. X509_STORE *OSSL_CMP_CTX_get0_trustedStore(const OSSL_CMP_CTX *ctx);
  94. int OSSL_CMP_CTX_set1_untrusted_certs(OSSL_CMP_CTX *ctx,
  95. STACK_OF(X509) *certs);
  96. STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted_certs(const OSSL_CMP_CTX *ctx);
  97. /* client authentication: */
  98. int OSSL_CMP_CTX_set1_clCert(OSSL_CMP_CTX *ctx, X509 *cert);
  99. int OSSL_CMP_CTX_set1_pkey(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey);
  100. int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx,
  101. const unsigned char *ref, int len);
  102. int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx, const unsigned char *sec,
  103. const int len);
  104. /* CMP message header and extra certificates: */
  105. int OSSL_CMP_CTX_set1_recipient(OSSL_CMP_CTX *ctx, const X509_NAME *name);
  106. int OSSL_CMP_CTX_push0_geninfo_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav);
  107. int OSSL_CMP_CTX_set1_extraCertsOut(OSSL_CMP_CTX *ctx,
  108. STACK_OF(X509) *extraCertsOut);
  109. /* certificate template: */
  110. int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey);
  111. EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv);
  112. int OSSL_CMP_CTX_set1_issuer(OSSL_CMP_CTX *ctx, const X509_NAME *name);
  113. int OSSL_CMP_CTX_set1_subjectName(OSSL_CMP_CTX *ctx, const X509_NAME *name);
  114. int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx,
  115. const GENERAL_NAME *name);
  116. int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts);
  117. int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx);
  118. int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo);
  119. int OSSL_CMP_CTX_set1_oldCert(OSSL_CMP_CTX *ctx, X509 *cert);
  120. int OSSL_CMP_CTX_set1_p10CSR(OSSL_CMP_CTX *ctx, const X509_REQ *csr);
  121. /* misc body contents: */
  122. int OSSL_CMP_CTX_push0_genm_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav);
  123. /* certificate confirmation: */
  124. typedef int (*OSSL_cmp_certConf_cb_t)(OSSL_CMP_CTX *ctx, X509 *cert,
  125. int fail_info, const char **txt);
  126. int OSSL_CMP_CTX_set_certConf_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_certConf_cb_t cb);
  127. int OSSL_CMP_CTX_set_certConf_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
  128. void *OSSL_CMP_CTX_get_certConf_cb_arg(const OSSL_CMP_CTX *ctx);
  129. /* result fetching: */
  130. int OSSL_CMP_CTX_get_status(const OSSL_CMP_CTX *ctx);
  131. OSSL_CMP_PKIFREETEXT *OSSL_CMP_CTX_get0_statusString(const OSSL_CMP_CTX *ctx);
  132. int OSSL_CMP_CTX_get_failInfoCode(const OSSL_CMP_CTX *ctx);
  133. X509 *OSSL_CMP_CTX_get0_newCert(const OSSL_CMP_CTX *ctx);
  134. STACK_OF(X509) *OSSL_CMP_CTX_get1_caPubs(const OSSL_CMP_CTX *ctx);
  135. STACK_OF(X509) *OSSL_CMP_CTX_get1_extraCertsIn(const OSSL_CMP_CTX *ctx);
  136. /* for test purposes only: */
  137. int OSSL_CMP_CTX_set1_transactionID(OSSL_CMP_CTX *ctx,
  138. const ASN1_OCTET_STRING *id);
  139. int OSSL_CMP_CTX_set1_senderNonce(OSSL_CMP_CTX *ctx,
  140. const ASN1_OCTET_STRING *nonce);
  141. =head1 DESCRIPTION
  142. This is the context API for using CMP (Certificate Management Protocol) with
  143. OpenSSL.
  144. OSSL_CMP_CTX_new() allocates and initializes an OSSL_CMP_CTX structure to
  145. default values, e.g., proof-of-possession method is set to POPOSigningKey.
  146. OSSL_CMP_CTX_free() deallocates an OSSL_CMP_CTX structure.
  147. OSSL_CMP_CTX_reinit() prepares the given B<ctx> for a further transaction by
  148. clearing the internal CMP transaction (aka session) status, PKIStatusInfo,
  149. and any previous results (newCert, caPubs, and extraCertsIn)
  150. from the last executed transaction.
  151. All other field values (i.e., CMP options) are retained for potential re-use.
  152. OSSL_CMP_CTX_set_option() sets the given value for the given option
  153. (e.g., OSSL_CMP_OPT_IMPLICITCONFIRM) in the given OSSL_CMP_CTX structure.
  154. The following options can be set:
  155. =over 4
  156. =item B<OSSL_CMP_OPT_LOG_VERBOSITY>
  157. The level of severity needed for actually outputting log messages
  158. due to errors, warnings, general info, debugging, etc.
  159. Default is OSSL_CMP_LOG_INFO. See also L<OSSL_CMP_log_open(3)>.
  160. =item B<OSSL_CMP_OPT_MSGTIMEOUT>
  161. Number of seconds (or 0 for infinite) a CMP message round trip is
  162. allowed to take before a timeout error is returned. Default is 120.
  163. =item B<OSSL_CMP_OPT_TOTALTIMEOUT>
  164. Maximum total number of seconds an enrollment (including polling)
  165. may take. Default is 0 (infinite).
  166. =item B<OSSL_CMP_OPT_VALIDITYDAYS>
  167. Number of days new certificates are asked to be valid for.
  168. =item B<OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT>
  169. Do not take default Subject Alternative Names
  170. from the reference certificate.
  171. =item B<OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL>
  172. Demand that the given Subject Alternative Names are flagged as critical.
  173. =item B<OSSL_CMP_OPT_POLICIES_CRITICAL>
  174. Demand that the given policies are flagged as critical.
  175. =item B<OSSL_CMP_OPT_POPOMETHOD>
  176. Select the proof of possession method to use. Possible values are:
  177. OSSL_CRMF_POPO_NONE - ProofOfPossession field omitted
  178. OSSL_CRMF_POPO_RAVERIFIED - assert that the RA has already
  179. verified the PoPo
  180. OSSL_CRMF_POPO_SIGNATURE - sign a value with private key,
  181. which is the default.
  182. OSSL_CRMF_POPO_KEYENC - decrypt the encrypted certificate
  183. ("indirect method")
  184. Note that a signature-based POPO can only be produced if a private key
  185. is provided as the newPkey or client pkey component of the CMP context.
  186. =item B<OSSL_CMP_OPT_DIGEST_ALGNID>
  187. The digest algorithm NID to be used in RFC 4210's MSG_SIG_ALG,
  188. if applicable used for message protection and Proof-of-Possession.
  189. Default is SHA256.
  190. OSSL_CMP_OPT_OWF_ALGNID
  191. The digest algorithm NID to be used as one-way function (OWF)
  192. in RFC 4210's MSG_MAC_ALG, if applicable used for message protection.
  193. Default is SHA256.
  194. OSSL_CMP_OPT_MAC_ALGNID
  195. The MAC algorithm NID to be used in RFC 4210's MSG_MAC_ALG,
  196. if applicable used for message protection.
  197. Default is HMAC-SHA1 as per RFC 4210.
  198. =item B<OSSL_CMP_OPT_REVOCATION_REASON>
  199. The reason code to be included in a Revocation Request (RR);
  200. values: 0..10 (RFC 5210, 5.3.1) or -1 for none, which is the default.
  201. =item B<OSSL_CMP_OPT_IMPLICITCONFIRM>
  202. Request server to enable implicit confirm mode, where the client
  203. does not need to send confirmation upon receiving the
  204. certificate. If the server does not enable implicit confirmation
  205. in the return message, then confirmation is sent anyway.
  206. =item B<OSSL_CMP_OPT_DISABLECONFIRM>
  207. Do not confirm enrolled certificates, to cope with broken servers
  208. not supporting implicit confirmation correctly.
  209. B<WARNING:> This setting leads to unspecified behavior and it is meant
  210. exclusively to allow interoperability with server implementations violating
  211. RFC 4210.
  212. =item B<OSSL_CMP_OPT_UNPROTECTED_SEND>
  213. Send messages without CMP-level protection.
  214. =item B<OSSL_CMP_OPT_UNPROTECTED_ERRORS>
  215. Accept unprotected error responses which are either explicitly
  216. unprotected or where protection verification failed. Applies to regular
  217. error messages as well as certificate responses (IP/CP/KUP) and
  218. revocation responses (RP) with rejection.
  219. B<WARNING:> This setting leads to unspecified behavior and it is meant
  220. exclusively to allow interoperability with server implementations violating
  221. RFC 4210.
  222. =item B<OSSL_CMP_OPT_IGNORE_KEYUSAGE>
  223. Ignore key usage restrictions in signer certificate when
  224. validating signature-based protection in received CMP messages.
  225. Else, 'digitalSignature' must be allowed by CMP signer certificates.
  226. =item B<OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR>
  227. Allow retrieving a trust anchor from extraCerts and using that
  228. to validate the certificate chain of an IP message.
  229. =back
  230. OSSL_CMP_CTX_get_option() reads the current value of the given option
  231. (e.g., OSSL_CMP_OPT_IMPLICITCONFIRM) from the given OSSL_CMP_CTX structure.
  232. OSSL_CMP_CTX_set_log_cb() sets in B<ctx> the callback function C<cb>
  233. for handling error queue entries and logging messages.
  234. When C<cb> is NULL errors are printed to STDERR (if available, else ignored)
  235. any log messages are ignored.
  236. Alternatively, L<OSSL_CMP_log_open(3)> may be used to direct logging to STDOUT.
  237. OSSL_CMP_CTX_set_log_verbosity() is a macro setting the
  238. OSSL_CMP_OPT_LOG_VERBOSITY context option to the given level.
  239. OSSL_CMP_CTX_print_errors() outputs any entries in the OpenSSL error queue.
  240. It is similar to B<ERR_print_errors_cb()> but uses the CMP log callback function
  241. if set in the C<ctx> for uniformity with CMP logging if given. Otherwise it uses
  242. B<ERR_print_errors(3)> to print to STDERR (unless OPENSSL_NO_STDIO is defined).
  243. OSSL_CMP_CTX_set1_serverPath() sets the HTTP path of the CMP server on the host.
  244. OSSL_CMP_CTX_set1_serverName() sets the given server Address (as IP or name)
  245. in the given OSSL_CMP_CTX structure.
  246. OSSL_CMP_CTX_set_serverPort() sets the port of the CMP server to connect to.
  247. Port defaults to OSSL_CMP_DEFAULT_PORT = 80 if not set explicitly.
  248. OSSL_CMP_CTX_set1_proxyName() sets the hostname of the HTTP proxy to be used
  249. for connecting to the CA server.
  250. OSSL_CMP_CTX_set_proxyPort() sets the port of the HTTP proxy.
  251. Port defaults to OSSL_CMP_DEFAULT_PORT = 80 if not set explicitly.
  252. OSSL_CMP_CTX_set_http_cb() sets the optional BIO connect/disconnect callback
  253. function, which has the prototype
  254. typedef BIO *(*HTTP_bio_cb_t) (BIO *bio, void *ctx, int connect, int detail);
  255. The callback may modify the BIO B<bio> provided by OSSL_CMP_MSG_http_perform(),
  256. whereby it may make use of a custom defined argument B<ctx>
  257. stored in the OSSL_CMP_CTX by means of OSSL_CMP_CTX_set_http_cb_arg().
  258. During connection establishment, just after calling BIO_connect_retry(),
  259. the function is invoked with the B<connect> argument being 1 and the B<detail>
  260. argument being 1 if HTTPS is requested, i.e., SSL/TLS should be enabled. On
  261. disconnect B<connect> is 0 and B<detail> is 1 in case no error occurred, else 0.
  262. For instance, on connect the function may prepend a TLS BIO to implement HTTPS;
  263. after disconnect it may do some diagnostic output and/or specific cleanup.
  264. The function should return NULL to indicate failure.
  265. After disconnect the modified BIO will be deallocated using BIO_free_all().
  266. OSSL_CMP_CTX_set_http_cb_arg() sets an argument, respectively a pointer to
  267. a structure containing arguments,
  268. optionally to be used by the http connect/disconnect callback function.
  269. B<arg> is not consumed, and it must therefore explicitly be freed when not
  270. needed any more. B<arg> may be NULL to clear the entry.
  271. OSSL_CMP_CTX_get_http_cb_arg() gets the argument, respectively the pointer to a
  272. structure containing arguments, previously set by
  273. OSSL_CMP_CTX_set_http_cb_arg() or NULL if unset.
  274. OSSL_CMP_CTX_set_transfer_cb() sets the message transfer callback function,
  275. which has the type
  276. typedef OSSL_CMP_MSG *(*OSSL_cmp_transfer_cb_t) (OSSL_CMP_CTX *ctx,
  277. const OSSL_CMP_MSG *req);
  278. Returns 1 on success, 0 on error.
  279. Default is NULL, which implies the use of L<OSSL_CMP_MSG_http_perform(3)>.
  280. The callback should send the CMP request message it obtains via the B<req>
  281. parameter and on success return the response.
  282. The transfer callback may make use of a custom defined argument stored in
  283. the ctx by means of OSSL_CMP_CTX_set_transfer_cb_arg(), which may be retrieved
  284. again through OSSL_CMP_CTX_get_transfer_cb_arg().
  285. OSSL_CMP_CTX_set_transfer_cb_arg() sets an argument, respectively a pointer to a
  286. structure containing arguments, optionally to be used by the transfer callback.
  287. B<arg> is not consumed, and it must therefore explicitly be freed when not
  288. needed any more. B<arg> may be NULL to clear the entry.
  289. OSSL_CMP_CTX_get_transfer_cb_arg() gets the argument, respectively the pointer
  290. to a structure containing arguments, previously set by
  291. OSSL_CMP_CTX_set_transfer_cb_arg() or NULL if unset.
  292. OSSL_CMP_CTX_set1_srvCert() pins the server certificate to be directly trusted
  293. (even if it is expired) for verifying response messages.
  294. The cert pointer is not consumed. It may be NULL to clear the entry.
  295. OSSL_CMP_CTX_set1_expected_sender() sets the Distinguished Name (DN) expected to
  296. be given in the sender response for messages protected with MSG_SIG_ALG. This
  297. may be used to enforce that during validation of received messages the given DN
  298. matches the sender field of the PKIMessage header, which in turn is used to
  299. identify the server certificate.
  300. This can be used to ensure that only a particular entity is accepted to act as
  301. CMP server, and attackers are not able to use arbitrary certificates of a
  302. trusted PKI hierarchy to fraudulently pose as server.
  303. This defaults to the subject DN of the certificate set via
  304. OSSL_CMP_CTX_set1_srvCert(), if any.
  305. OSSL_CMP_CTX_set0_trustedStore() sets the X509_STORE type certificate store
  306. containing trusted (root) CA certificates. The certificate store may also hold
  307. CRLs and a certificate verification callback function used for CMP server
  308. authentication. Any already existing store entry is freed. When given a NULL
  309. parameter the entry is cleared.
  310. OSSL_CMP_CTX_get0_trustedStore() returns a pointer to the certificate store
  311. containing trusted root CA certificates, which may be empty if unset.
  312. OSSL_CMP_CTX_set1_untrusted_certs() takes over a list of certificates containing
  313. non-trusted intermediate certs used for path construction in authentication
  314. of the CMP server and potentially others (TLS server, newly enrolled cert).
  315. The reference counts of those certificates handled successfully are increased.
  316. OSSL_CMP_CTX_get0_untrusted_certs(OSSL_CMP_CTX *ctx) returns a pointer to the
  317. list of untrusted certs, which my be empty if unset.
  318. OSSL_CMP_CTX_set1_clCert() sets the client certificate in the given
  319. OSSL_CMP_CTX structure. The client certificate will then be used by the
  320. functions to set the "sender" field for outgoing messages and it will be
  321. included in the extraCerts field.
  322. OSSL_CMP_CTX_set1_pkey() sets the private key corresponding to the client
  323. certificate set with B<OSSL_CMP_CTX_set1_clCert()> in the given CMP context.
  324. Used to create the protection in case of MSG_SIG_ALG.
  325. OSSL_CMP_CTX_set1_referenceValue() sets the given referenceValue in the given
  326. B<ctx> or clears it if the B<ref> argument is NULL.
  327. OSSL_CMP_CTX_set1_secretValue() sets the B<sec> with the length B<len> in the
  328. given B<ctx> or clears it if the B<sec> argument is NULL.
  329. OSSL_CMP_CTX_set1_recipient() sets the recipient name that will be used in the
  330. PKIHeader of a request message, i.e. the X509 name of the (CA) server.
  331. Setting is overruled by subject of srvCert if set.
  332. If neither srvCert nor recipient are set, the recipient of the PKI message is
  333. determined in the following order: issuer, issuer of old cert (oldCert),
  334. issuer of client cert (clCert), else NULL-DN.
  335. When a response is received, its sender must match the recipient of the request.
  336. OSSL_CMP_CTX_push0_geninfo_ITAV() adds B<itav> to the stack in the B<ctx> to be
  337. added to the GeneralInfo field of the CMP PKIMessage header of a request
  338. message sent with this context. Consumes the pointer to B<itav>.
  339. OSSL_CMP_CTX_set1_extraCertsOut() sets the stack of extraCerts that will be
  340. sent to remote.
  341. OSSL_CMP_CTX_set0_newPkey() can be used to explicitly set the given EVP_PKEY
  342. structure as the private or public key to be certified in the CMP context.
  343. The B<priv> parameter must be 0 if and only if the given key is a public key.
  344. OSSL_CMP_CTX_get0_newPkey() gives the key to use for certificate enrollment
  345. dependent on fields of the CMP context structure:
  346. the newPkey (which may be a private or public key) if present,
  347. else the public key in the p10CSR if present, else the client private key.
  348. If the B<priv> parameter is not 0 and the selected key does not have a
  349. private component then NULL is returned.
  350. OSSL_CMP_CTX_set1_issuer() sets the name of the intended issuer that
  351. will be set in the CertTemplate, i.e., the X509 name of the CA server.
  352. OSSL_CMP_CTX_set1_subjectName() sets the subject DN that will be used in
  353. the CertTemplate structure when requesting a new cert. For Key Update Requests
  354. (KUR), it defaults to the subject DN of the reference certificate,
  355. see B<OSSL_CMP_CTX_set1_oldCert()>. This default is used for Initialization
  356. Requests (IR) and Certification Requests (CR) only if no SANs are set.
  357. If clCert is not set (e.g. in case of IR with MSG_MAC_ALG), the subject DN
  358. is also used as sender of the PKI message.
  359. OSSL_CMP_CTX_push1_subjectAltName() adds the given X509 name to the list of
  360. alternate names on the certificate template request. This cannot be used if
  361. any Subject Alternative Name extension is set via
  362. OSSL_CMP_CTX_set0_reqExtensions().
  363. By default, unless OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT has been set,
  364. the Subject Alternative Names are copied from the reference certificate,
  365. see OSSL_CMP_CTX_set1_oldCert().
  366. If set and the subject DN is not set with OSSL_CMP_CTX_set1_subjectName(), then
  367. the certificate template of an IR and CR will not be filled with the default
  368. subject DN from the reference certificate (see OSSL_CMP_CTX_set1_oldCert().
  369. If a subject DN is desired it needs to be set explicitly with
  370. OSSL_CMP_CTX_set1_subjectName().
  371. OSSL_CMP_CTX_set0_reqExtensions() sets the X.509v3 extensions to be used in
  372. IR/CR/KUR.
  373. OSSL_CMP_CTX_reqExtensions_have_SAN() returns 1 if the context contains
  374. a Subject Alternative Name extension, else 0 or -1 on error.
  375. OSSL_CMP_CTX_push0_policy() adds the certificate policy info object
  376. to the X509_EXTENSIONS of the requested certificate template.
  377. OSSL_CMP_CTX_set1_oldCert() sets the old certificate to be updated in
  378. Key Update Requests (KUR) or to be revoked in Revocation Requests (RR).
  379. It must be given for RR, else it defaults to B<clCert>.
  380. The reference certificate determined in this way, if any, is also used for
  381. deriving default subject DN and Subject Alternative Names for IR, CR, and KUR.
  382. Its issuer, if any, is used as default recipient in the CMP message header.
  383. OSSL_CMP_CTX_set1_p10CSR() sets the PKCS#10 CSR to be used in P10CR.
  384. OSSL_CMP_CTX_push0_genm_ITAV() adds B<itav> to the stack in the B<ctx> which
  385. will be the body of a General Message sent with this context.
  386. Consumes the pointer to B<itav>.
  387. OSSL_CMP_CTX_set_certConf_cb() sets the callback used for evaluating the newly
  388. enrolled certificate before the library sends, depending on its result,
  389. a positive or negative certConf message to the server. The callback has type
  390. typedef int (*OSSL_cmp_certConf_cb_t) (OSSL_CMP_CTX *ctx, X509 *cert,
  391. int fail_info, const char **txt);
  392. and should inspect the certificate it obtains via the B<cert> parameter and may
  393. overrule the pre-decision given in the B<fail_info> and B<*txt> parameters.
  394. If it accepts the certificate it must return 0, indicating success. Else it must
  395. return a bit field reflecting PKIFailureInfo with at least one failure bit and
  396. may set the B<*txt> output parameter to point to a string constant with more
  397. detail. The transfer callback may make use of a custom defined argument stored
  398. in the B<ctx> by means of OSSL_CMP_CTX_set_certConf_cb_arg(), which may be
  399. retrieved again through OSSL_CMP_CTX_get_certConf_cb_arg().
  400. Typically, the callback will check at least that the certificate can be verified
  401. using a set of trusted certificates.
  402. It also could compare the subject DN and other fields of the newly
  403. enrolled certificate with the certificate template of the request.
  404. OSSL_CMP_CTX_set_certConf_cb_arg() sets an argument, respectively a pointer to a
  405. structure containing arguments, optionally to be used by the certConf callback.
  406. B<arg> is not consumed, and it must therefore explicitly be freed when not
  407. needed any more. B<arg> may be NULL to clear the entry.
  408. OSSL_CMP_CTX_get_certConf_cb_arg() gets the argument, respectively the pointer
  409. to a structure containing arguments, previously set by
  410. OSSL_CMP_CTX_set_certConf_cb_arg(), or NULL if unset.
  411. OSSL_CMP_CTX_get_status() returns the PKIstatus from the last received
  412. CertRepMessage or Revocation Response or error message, or -1 if unset.
  413. OSSL_CMP_CTX_get0_statusString() returns the statusString from the last received
  414. CertRepMessage or Revocation Response or error message, or NULL if unset.
  415. OSSL_CMP_CTX_get_failInfoCode() returns the error code from the failInfo field
  416. of the last received CertRepMessage or Revocation Response or error message.
  417. This is a bit field and the flags for it are specified in the header file
  418. F<< <openssl/cmp.h> >>.
  419. The flags start with OSSL_CMP_CTX_FAILINFO, for example:
  420. OSSL_CMP_CTX_FAILINFO_badAlg. Returns -1 if the failInfoCode field is unset.
  421. OSSL_CMP_CTX_get0_newCert() returns the pointer to the newly obtained
  422. certificate in case it is available, else NULL.
  423. OSSL_CMP_CTX_get1_caPubs() returns a pointer to a duplicate of the stack of
  424. X.509 certificates received in the caPubs field of last received certificate
  425. response message IP/CP/KUP.
  426. OSSL_CMP_CTX_get1_extraCertsIn() returns a pointer to a duplicate of the stack
  427. of X.509 certificates received in the last received non-empty extraCerts field.
  428. Returns an empty stack if no extraCerts have been received in the current
  429. transaction.
  430. OSSL_CMP_CTX_set1_transactionID() sets the given transaction ID in the given
  431. OSSL_CMP_CTX structure.
  432. OSSL_CMP_CTX_set1_senderNonce() stores the last sent sender B<nonce> in
  433. the B<ctx>. This will be used to validate the recipNonce in incoming messages.
  434. =head1 NOTES
  435. CMP is defined in RFC 4210 (and CRMF in RFC 4211).
  436. =head1 RETURN VALUES
  437. OSSL_CMP_CTX_free() and OSSL_CMP_CTX_print_errors() do not return anything.
  438. OSSL_CMP_CTX_new(),
  439. OSSL_CMP_CTX_get_http_cb_arg(),
  440. OSSL_CMP_CTX_get_transfer_cb_arg(),
  441. OSSL_CMP_CTX_get0_trustedStore(),
  442. OSSL_CMP_CTX_get0_untrusted_certs(),
  443. OSSL_CMP_CTX_get0_newPkey(),
  444. OSSL_CMP_CTX_get_certConf_cb_arg(),
  445. OSSL_CMP_CTX_get0_statusString(),
  446. OSSL_CMP_CTX_get0_newCert(),
  447. OSSL_CMP_CTX_get1_caPubs(), and
  448. OSSL_CMP_CTX_get1_extraCertsIn()
  449. return the intended pointer value as described above or NULL on error.
  450. OSSL_CMP_CTX_get_option(),
  451. OSSL_CMP_CTX_reqExtensions_have_SAN(),
  452. OSSL_CMP_CTX_get_status(), and
  453. OSSL_CMP_CTX_get_failInfoCode()
  454. return the intended value as described above or -1 on error.
  455. All other functions return 1 on success, 0 on error.
  456. =head1 EXAMPLES
  457. The following code does an Initialization Request:
  458. cmp_ctx = OSSL_CMP_CTX_new();
  459. OSSL_CMP_CTX_set1_serverName(cmp_ctx, opt_serverName);
  460. OSSL_CMP_CTX_set1_referenceValue(cmp_ctx, ref, ref_len);
  461. OSSL_CMP_CTX_set1_secretValue(cmp_ctx, sec, sec_len);
  462. OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1);
  463. OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert);
  464. initialClCert = OSSL_CMP_exec_IR_ses(cmp_ctx);
  465. The following code does an Initialization Request using an
  466. external identity certificate (RFC 4210, Appendix E.7):
  467. cmp_ctx = OSSL_CMP_CTX_new();
  468. OSSL_CMP_CTX_set1_serverName(cmp_ctx, sname);
  469. OSSL_CMP_CTX_set1_clCert(cmp_ctx, cl_cert);
  470. OSSL_CMP_CTX_set1_pkey(cmp_ctx, pkey);
  471. OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1);
  472. OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert);
  473. initialClCert = OSSL_CMP_exec_IR_ses(cmp_ctx);
  474. Here externalCert is an X509 certificate granted to the EE by another CA
  475. which is trusted by the current CA the code will connect to.
  476. The following code does a Key Update Request:
  477. cmp_ctx = OSSL_CMP_CTX_new();
  478. OSSL_CMP_CTX_set1_serverName(cmp_ctx, sname);
  479. OSSL_CMP_CTX_set1_pkey(cmp_ctx, pkey);
  480. OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1);
  481. OSSL_CMP_CTX_set1_clCert(cmp_ctx, cl_cert);
  482. OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert);
  483. updatedClCert = OSSL_CMP_exec_KUR_ses(cmp_ctx);
  484. The following code (which omits error handling) sends a General Message
  485. including, as an example, the id-it-signKeyPairTypes OID and prints info on
  486. the General Response contents.
  487. cmp_ctx = OSSL_CMP_CTX_new();
  488. OSSL_CMP_CTX_set1_serverName(cmp_ctx, sname);
  489. OSSL_CMP_CTX_set1_referenceValue(cmp_ctx, ref, ref_len);
  490. OSSL_CMP_CTX_set1_secretValue(cmp_ctx, sec, sec_len);
  491. ASN1_OBJECT *type = OBJ_txt2obj("1.3.6.1.5.5.7.4.2", 1);
  492. OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new(type, NULL);
  493. OSSL_CMP_CTX_push0_genm_ITAV(cmp_ctx, itav);
  494. STACK_OF(OSSL_CMP_ITAV) *itavs;
  495. itavs = OSSL_CMP_exec_GENM_ses(cmp_ctx);
  496. print_itavs(itavs);
  497. sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free);
  498. =head1 SEE ALSO
  499. L<OSSL_CMP_exec_IR_ses(3)>, L<OSSL_CMP_exec_KUR_ses(3)>,
  500. L<OSSL_CMP_exec_GENM_ses(3)>
  501. =head1 HISTORY
  502. The OpenSSL CMP support was added in OpenSSL 3.0.
  503. =head1 COPYRIGHT
  504. Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
  505. Licensed under the Apache License 2.0 (the "License"). You may not use
  506. this file except in compliance with the License. You can obtain a copy
  507. in the file LICENSE in the source distribution or at
  508. L<https://www.openssl.org/source/license.html>.
  509. =cut