cmp.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright Nokia 2007-2019
  4. * Copyright Siemens AG 2015-2019
  5. *
  6. * Licensed under the Apache License 2.0 (the "License"). You may not use
  7. * this file except in compliance with the License. You can obtain a copy
  8. * in the file LICENSE in the source distribution or at
  9. * https://www.openssl.org/source/license.html
  10. */
  11. #ifndef OPENSSL_CMP_H
  12. # define OPENSSL_CMP_H
  13. # include <openssl/opensslconf.h>
  14. # ifndef OPENSSL_NO_CMP
  15. # include <openssl/crmf.h>
  16. # include <openssl/cmperr.h>
  17. # include <openssl/cmp_util.h>
  18. /* explicit #includes not strictly needed since implied by the above: */
  19. # include <openssl/types.h>
  20. # include <openssl/safestack.h>
  21. # include <openssl/x509.h>
  22. # include <openssl/x509v3.h>
  23. # ifdef __cplusplus
  24. extern "C" {
  25. # endif
  26. # define OSSL_CMP_PVNO 2
  27. /*-
  28. * PKIFailureInfo ::= BIT STRING {
  29. * -- since we can fail in more than one way!
  30. * -- More codes may be added in the future if/when required.
  31. * badAlg (0),
  32. * -- unrecognized or unsupported Algorithm Identifier
  33. * badMessageCheck (1),
  34. * -- integrity check failed (e.g., signature did not verify)
  35. * badRequest (2),
  36. * -- transaction not permitted or supported
  37. * badTime (3),
  38. * -- messageTime was not sufficiently close to the system time,
  39. * -- as defined by local policy
  40. * badCertId (4),
  41. * -- no certificate could be found matching the provided criteria
  42. * badDataFormat (5),
  43. * -- the data submitted has the wrong format
  44. * wrongAuthority (6),
  45. * -- the authority indicated in the request is different from the
  46. * -- one creating the response token
  47. * incorrectData (7),
  48. * -- the requester's data is incorrect (for notary services)
  49. * missingTimeStamp (8),
  50. * -- when the timestamp is missing but should be there
  51. * -- (by policy)
  52. * badPOP (9),
  53. * -- the proof-of-possession failed
  54. * certRevoked (10),
  55. * -- the certificate has already been revoked
  56. * certConfirmed (11),
  57. * -- the certificate has already been confirmed
  58. * wrongIntegrity (12),
  59. * -- invalid integrity, password based instead of signature or
  60. * -- vice versa
  61. * badRecipientNonce (13),
  62. * -- invalid recipient nonce, either missing or wrong value
  63. * timeNotAvailable (14),
  64. * -- the TSA's time source is not available
  65. * unacceptedPolicy (15),
  66. * -- the requested TSA policy is not supported by the TSA.
  67. * unacceptedExtension (16),
  68. * -- the requested extension is not supported by the TSA.
  69. * addInfoNotAvailable (17),
  70. * -- the additional information requested could not be
  71. * -- understood or is not available
  72. * badSenderNonce (18),
  73. * -- invalid sender nonce, either missing or wrong size
  74. * badCertTemplate (19),
  75. * -- invalid cert. template or missing mandatory information
  76. * signerNotTrusted (20),
  77. * -- signer of the message unknown or not trusted
  78. * transactionIdInUse (21),
  79. * -- the transaction identifier is already in use
  80. * unsupportedVersion (22),
  81. * -- the version of the message is not supported
  82. * notAuthorized (23),
  83. * -- the sender was not authorized to make the preceding
  84. * -- request or perform the preceding action
  85. * systemUnavail (24),
  86. * -- the request cannot be handled due to system unavailability
  87. * systemFailure (25),
  88. * -- the request cannot be handled due to system failure
  89. * duplicateCertReq (26)
  90. * -- certificate cannot be issued because a duplicate
  91. * -- certificate already exists
  92. * }
  93. */
  94. # define OSSL_CMP_PKIFAILUREINFO_badAlg 0
  95. # define OSSL_CMP_PKIFAILUREINFO_badMessageCheck 1
  96. # define OSSL_CMP_PKIFAILUREINFO_badRequest 2
  97. # define OSSL_CMP_PKIFAILUREINFO_badTime 3
  98. # define OSSL_CMP_PKIFAILUREINFO_badCertId 4
  99. # define OSSL_CMP_PKIFAILUREINFO_badDataFormat 5
  100. # define OSSL_CMP_PKIFAILUREINFO_wrongAuthority 6
  101. # define OSSL_CMP_PKIFAILUREINFO_incorrectData 7
  102. # define OSSL_CMP_PKIFAILUREINFO_missingTimeStamp 8
  103. # define OSSL_CMP_PKIFAILUREINFO_badPOP 9
  104. # define OSSL_CMP_PKIFAILUREINFO_certRevoked 10
  105. # define OSSL_CMP_PKIFAILUREINFO_certConfirmed 11
  106. # define OSSL_CMP_PKIFAILUREINFO_wrongIntegrity 12
  107. # define OSSL_CMP_PKIFAILUREINFO_badRecipientNonce 13
  108. # define OSSL_CMP_PKIFAILUREINFO_timeNotAvailable 14
  109. # define OSSL_CMP_PKIFAILUREINFO_unacceptedPolicy 15
  110. # define OSSL_CMP_PKIFAILUREINFO_unacceptedExtension 16
  111. # define OSSL_CMP_PKIFAILUREINFO_addInfoNotAvailable 17
  112. # define OSSL_CMP_PKIFAILUREINFO_badSenderNonce 18
  113. # define OSSL_CMP_PKIFAILUREINFO_badCertTemplate 19
  114. # define OSSL_CMP_PKIFAILUREINFO_signerNotTrusted 20
  115. # define OSSL_CMP_PKIFAILUREINFO_transactionIdInUse 21
  116. # define OSSL_CMP_PKIFAILUREINFO_unsupportedVersion 22
  117. # define OSSL_CMP_PKIFAILUREINFO_notAuthorized 23
  118. # define OSSL_CMP_PKIFAILUREINFO_systemUnavail 24
  119. # define OSSL_CMP_PKIFAILUREINFO_systemFailure 25
  120. # define OSSL_CMP_PKIFAILUREINFO_duplicateCertReq 26
  121. # define OSSL_CMP_PKIFAILUREINFO_MAX 26
  122. # define OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN \
  123. ( (1<<(OSSL_CMP_PKIFAILUREINFO_MAX+1)) - 1)
  124. # if OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN > INT_MAX
  125. # error CMP_PKIFAILUREINFO_MAX bit pattern does not fit in type int
  126. # endif
  127. typedef ASN1_BIT_STRING OSSL_CMP_PKIFAILUREINFO;
  128. # define OSSL_CMP_CTX_FAILINFO_badAlg (1 << 0)
  129. # define OSSL_CMP_CTX_FAILINFO_badMessageCheck (1 << 1)
  130. # define OSSL_CMP_CTX_FAILINFO_badRequest (1 << 2)
  131. # define OSSL_CMP_CTX_FAILINFO_badTime (1 << 3)
  132. # define OSSL_CMP_CTX_FAILINFO_badCertId (1 << 4)
  133. # define OSSL_CMP_CTX_FAILINFO_badDataFormat (1 << 5)
  134. # define OSSL_CMP_CTX_FAILINFO_wrongAuthority (1 << 6)
  135. # define OSSL_CMP_CTX_FAILINFO_incorrectData (1 << 7)
  136. # define OSSL_CMP_CTX_FAILINFO_missingTimeStamp (1 << 8)
  137. # define OSSL_CMP_CTX_FAILINFO_badPOP (1 << 9)
  138. # define OSSL_CMP_CTX_FAILINFO_certRevoked (1 << 10)
  139. # define OSSL_CMP_CTX_FAILINFO_certConfirmed (1 << 11)
  140. # define OSSL_CMP_CTX_FAILINFO_wrongIntegrity (1 << 12)
  141. # define OSSL_CMP_CTX_FAILINFO_badRecipientNonce (1 << 13)
  142. # define OSSL_CMP_CTX_FAILINFO_timeNotAvailable (1 << 14)
  143. # define OSSL_CMP_CTX_FAILINFO_unacceptedPolicy (1 << 15)
  144. # define OSSL_CMP_CTX_FAILINFO_unacceptedExtension (1 << 16)
  145. # define OSSL_CMP_CTX_FAILINFO_addInfoNotAvailable (1 << 17)
  146. # define OSSL_CMP_CTX_FAILINFO_badSenderNonce (1 << 18)
  147. # define OSSL_CMP_CTX_FAILINFO_badCertTemplate (1 << 19)
  148. # define OSSL_CMP_CTX_FAILINFO_signerNotTrusted (1 << 20)
  149. # define OSSL_CMP_CTX_FAILINFO_transactionIdInUse (1 << 21)
  150. # define OSSL_CMP_CTX_FAILINFO_unsupportedVersion (1 << 22)
  151. # define OSSL_CMP_CTX_FAILINFO_notAuthorized (1 << 23)
  152. # define OSSL_CMP_CTX_FAILINFO_systemUnavail (1 << 24)
  153. # define OSSL_CMP_CTX_FAILINFO_systemFailure (1 << 25)
  154. # define OSSL_CMP_CTX_FAILINFO_duplicateCertReq (1 << 26)
  155. /*-
  156. * PKIStatus ::= INTEGER {
  157. * accepted (0),
  158. * -- you got exactly what you asked for
  159. * grantedWithMods (1),
  160. * -- you got something like what you asked for; the
  161. * -- requester is responsible for ascertaining the differences
  162. * rejection (2),
  163. * -- you don't get it, more information elsewhere in the message
  164. * waiting (3),
  165. * -- the request body part has not yet been processed; expect to
  166. * -- hear more later (note: proper handling of this status
  167. * -- response MAY use the polling req/rep PKIMessages specified
  168. * -- in Section 5.3.22; alternatively, polling in the underlying
  169. * -- transport layer MAY have some utility in this regard)
  170. * revocationWarning (4),
  171. * -- this message contains a warning that a revocation is
  172. * -- imminent
  173. * revocationNotification (5),
  174. * -- notification that a revocation has occurred
  175. * keyUpdateWarning (6)
  176. * -- update already done for the oldCertId specified in
  177. * -- CertReqMsg
  178. * }
  179. */
  180. # define OSSL_CMP_PKISTATUS_accepted 0
  181. # define OSSL_CMP_PKISTATUS_grantedWithMods 1
  182. # define OSSL_CMP_PKISTATUS_rejection 2
  183. # define OSSL_CMP_PKISTATUS_waiting 3
  184. # define OSSL_CMP_PKISTATUS_revocationWarning 4
  185. # define OSSL_CMP_PKISTATUS_revocationNotification 5
  186. # define OSSL_CMP_PKISTATUS_keyUpdateWarning 6
  187. typedef ASN1_INTEGER OSSL_CMP_PKISTATUS;
  188. DECLARE_ASN1_ITEM(OSSL_CMP_PKISTATUS)
  189. # define OSSL_CMP_CERTORENCCERT_CERTIFICATE 0
  190. # define OSSL_CMP_CERTORENCCERT_ENCRYPTEDCERT 1
  191. /* data type declarations */
  192. typedef struct ossl_cmp_ctx_st OSSL_CMP_CTX;
  193. typedef struct ossl_cmp_pkiheader_st OSSL_CMP_PKIHEADER;
  194. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKIHEADER)
  195. typedef struct ossl_cmp_msg_st OSSL_CMP_MSG;
  196. DECLARE_ASN1_ENCODE_FUNCTIONS(OSSL_CMP_MSG, OSSL_CMP_MSG, OSSL_CMP_MSG)
  197. typedef struct ossl_cmp_certstatus_st OSSL_CMP_CERTSTATUS;
  198. DEFINE_STACK_OF(OSSL_CMP_CERTSTATUS)
  199. typedef struct ossl_cmp_itav_st OSSL_CMP_ITAV;
  200. DEFINE_STACK_OF(OSSL_CMP_ITAV)
  201. typedef struct ossl_cmp_revrepcontent_st OSSL_CMP_REVREPCONTENT;
  202. typedef struct ossl_cmp_pkisi_st OSSL_CMP_PKISI;
  203. DEFINE_STACK_OF(OSSL_CMP_PKISI)
  204. typedef struct ossl_cmp_certrepmessage_st OSSL_CMP_CERTREPMESSAGE;
  205. DEFINE_STACK_OF(OSSL_CMP_CERTREPMESSAGE)
  206. typedef struct ossl_cmp_pollrep_st OSSL_CMP_POLLREP;
  207. typedef STACK_OF(OSSL_CMP_POLLREP) OSSL_CMP_POLLREPCONTENT;
  208. typedef struct ossl_cmp_certresponse_st OSSL_CMP_CERTRESPONSE;
  209. DEFINE_STACK_OF(OSSL_CMP_CERTRESPONSE)
  210. typedef STACK_OF(ASN1_UTF8STRING) OSSL_CMP_PKIFREETEXT;
  211. /*
  212. * function DECLARATIONS
  213. */
  214. /* from cmp_asn.c */
  215. OSSL_CMP_ITAV *OSSL_CMP_ITAV_create(ASN1_OBJECT *type, ASN1_TYPE *value);
  216. void OSSL_CMP_ITAV_set0(OSSL_CMP_ITAV *itav, ASN1_OBJECT *type,
  217. ASN1_TYPE *value);
  218. ASN1_OBJECT *OSSL_CMP_ITAV_get0_type(const OSSL_CMP_ITAV *itav);
  219. ASN1_TYPE *OSSL_CMP_ITAV_get0_value(const OSSL_CMP_ITAV *itav);
  220. int OSSL_CMP_ITAV_push0_stack_item(STACK_OF(OSSL_CMP_ITAV) **itav_sk_p,
  221. OSSL_CMP_ITAV *itav);
  222. void OSSL_CMP_ITAV_free(OSSL_CMP_ITAV *itav);
  223. void OSSL_CMP_MSG_free(OSSL_CMP_MSG *msg);
  224. /* from cmp_ctx.c */
  225. OSSL_CMP_CTX *OSSL_CMP_CTX_new(void);
  226. void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx);
  227. int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx);
  228. /* various CMP options: */
  229. # define OSSL_CMP_OPT_LOG_VERBOSITY 0
  230. # define OSSL_CMP_OPT_MSGTIMEOUT 1
  231. # define OSSL_CMP_OPT_TOTALTIMEOUT 2
  232. # define OSSL_CMP_OPT_VALIDITYDAYS 3
  233. # define OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT 4
  234. # define OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL 5
  235. # define OSSL_CMP_OPT_POLICIES_CRITICAL 6
  236. # define OSSL_CMP_OPT_POPOMETHOD 7
  237. # define OSSL_CMP_OPT_DIGEST_ALGNID 8
  238. # define OSSL_CMP_OPT_OWF_ALGNID 9
  239. # define OSSL_CMP_OPT_MAC_ALGNID 10
  240. # define OSSL_CMP_OPT_REVOCATION_REASON 11
  241. # define OSSL_CMP_OPT_IMPLICITCONFIRM 12
  242. # define OSSL_CMP_OPT_DISABLECONFIRM 13
  243. # define OSSL_CMP_OPT_UNPROTECTED_SEND 14
  244. # define OSSL_CMP_OPT_UNPROTECTED_ERRORS 15
  245. # define OSSL_CMP_OPT_IGNORE_KEYUSAGE 16
  246. # define OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR 17
  247. int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val);
  248. int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt);
  249. /* CMP-specific callback for logging and outputting the error queue: */
  250. int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_log_cb_t cb);
  251. #define OSSL_CMP_CTX_set_log_verbosity(ctx, level) \
  252. OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_LOG_VERBOSITY, level)
  253. void OSSL_CMP_CTX_print_errors(OSSL_CMP_CTX *ctx);
  254. /* message transfer: */
  255. int OSSL_CMP_CTX_set1_serverPath(OSSL_CMP_CTX *ctx, const char *path);
  256. int OSSL_CMP_CTX_set1_serverName(OSSL_CMP_CTX *ctx, const char *name);
  257. int OSSL_CMP_CTX_set_serverPort(OSSL_CMP_CTX *ctx, int port);
  258. int OSSL_CMP_CTX_set1_proxyName(OSSL_CMP_CTX *ctx, const char *name);
  259. int OSSL_CMP_CTX_set_proxyPort(OSSL_CMP_CTX *ctx, int port);
  260. # define OSSL_CMP_DEFAULT_PORT 80
  261. typedef BIO *(*OSSL_cmp_http_cb_t) (OSSL_CMP_CTX *ctx, BIO *hbio,
  262. unsigned long detail);
  263. int OSSL_CMP_CTX_set_http_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_http_cb_t cb);
  264. int OSSL_CMP_CTX_set_http_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
  265. void *OSSL_CMP_CTX_get_http_cb_arg(const OSSL_CMP_CTX *ctx);
  266. typedef int (*OSSL_cmp_transfer_cb_t) (OSSL_CMP_CTX *ctx,
  267. const OSSL_CMP_MSG *req,
  268. OSSL_CMP_MSG **res);
  269. int OSSL_CMP_CTX_set_transfer_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_transfer_cb_t cb);
  270. int OSSL_CMP_CTX_set_transfer_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
  271. void *OSSL_CMP_CTX_get_transfer_cb_arg(const OSSL_CMP_CTX *ctx);
  272. /* server authentication: */
  273. int OSSL_CMP_CTX_set1_srvCert(OSSL_CMP_CTX *ctx, X509 *cert);
  274. int OSSL_CMP_CTX_set1_expected_sender(OSSL_CMP_CTX *ctx, const X509_NAME *name);
  275. int OSSL_CMP_CTX_set0_trustedStore(OSSL_CMP_CTX *ctx, X509_STORE *store);
  276. X509_STORE *OSSL_CMP_CTX_get0_trustedStore(const OSSL_CMP_CTX *ctx);
  277. int OSSL_CMP_CTX_set1_untrusted_certs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *certs);
  278. STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted_certs(const OSSL_CMP_CTX *ctx);
  279. /* client authentication: */
  280. int OSSL_CMP_CTX_set1_clCert(OSSL_CMP_CTX *ctx, X509 *cert);
  281. int OSSL_CMP_CTX_set1_pkey(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey);
  282. int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx,
  283. const unsigned char *ref, int len);
  284. int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx, const unsigned char *sec,
  285. const int len);
  286. /* CMP message header and extra certificates: */
  287. int OSSL_CMP_CTX_set1_recipient(OSSL_CMP_CTX *ctx, const X509_NAME *name);
  288. int OSSL_CMP_CTX_push0_geninfo_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav);
  289. int OSSL_CMP_CTX_set1_extraCertsOut(OSSL_CMP_CTX *ctx,
  290. STACK_OF(X509) *extraCertsOut);
  291. /* certificate template: */
  292. int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey);
  293. EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv);
  294. int OSSL_CMP_CTX_set1_issuer(OSSL_CMP_CTX *ctx, const X509_NAME *name);
  295. int OSSL_CMP_CTX_set1_subjectName(OSSL_CMP_CTX *ctx, const X509_NAME *name);
  296. int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx, const GENERAL_NAME *name);
  297. int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts);
  298. int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx);
  299. int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo);
  300. int OSSL_CMP_CTX_set1_oldCert(OSSL_CMP_CTX *ctx, X509 *cert);
  301. int OSSL_CMP_CTX_set1_p10CSR(OSSL_CMP_CTX *ctx, const X509_REQ *csr);
  302. /* misc body contents: */
  303. int OSSL_CMP_CTX_push0_genm_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav);
  304. /* certificate confirmation: */
  305. typedef int (*OSSL_cmp_certConf_cb_t) (OSSL_CMP_CTX *ctx, X509 *cert,
  306. int fail_info, const char **txt);
  307. int OSSL_CMP_CTX_set_certConf_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_certConf_cb_t cb);
  308. int OSSL_CMP_CTX_set_certConf_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
  309. void *OSSL_CMP_CTX_get_certConf_cb_arg(const OSSL_CMP_CTX *ctx);
  310. /* result fetching: */
  311. int OSSL_CMP_CTX_get_status(const OSSL_CMP_CTX *ctx);
  312. OSSL_CMP_PKIFREETEXT *OSSL_CMP_CTX_get0_statusString(const OSSL_CMP_CTX *ctx);
  313. int OSSL_CMP_CTX_get_failInfoCode(const OSSL_CMP_CTX *ctx);
  314. # define OSSL_CMP_PKISI_BUFLEN 1024
  315. X509 *OSSL_CMP_CTX_get0_newCert(const OSSL_CMP_CTX *ctx);
  316. STACK_OF(X509) *OSSL_CMP_CTX_get1_caPubs(const OSSL_CMP_CTX *ctx);
  317. STACK_OF(X509) *OSSL_CMP_CTX_get1_extraCertsIn(const OSSL_CMP_CTX *ctx);
  318. /* support application-level CMP debugging in cmp.c: */
  319. int OSSL_CMP_CTX_set1_transactionID(OSSL_CMP_CTX *ctx,
  320. const ASN1_OCTET_STRING *id);
  321. int OSSL_CMP_CTX_set1_senderNonce(OSSL_CMP_CTX *ctx,
  322. const ASN1_OCTET_STRING *nonce);
  323. # ifdef __cplusplus
  324. }
  325. # endif
  326. # endif /* !defined OPENSSL_NO_CMP */
  327. #endif /* !defined OPENSSL_CMP_H */