cmp_local.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. /*
  2. * Copyright 2007-2024 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 OSSL_CRYPTO_CMP_LOCAL_H
  12. # define OSSL_CRYPTO_CMP_LOCAL_H
  13. # include "internal/cryptlib.h"
  14. # include <openssl/cmp.h>
  15. # include <openssl/err.h>
  16. /* explicit #includes not strictly needed since implied by the above: */
  17. # include <openssl/crmf.h>
  18. # include <openssl/types.h>
  19. # include <openssl/safestack.h>
  20. # include <openssl/x509.h>
  21. # include <openssl/x509v3.h>
  22. # include "crypto/x509.h"
  23. # define IS_NULL_DN(name) (X509_NAME_get_entry(name, 0) == NULL)
  24. /*
  25. * this structure is used to store the context for CMP sessions
  26. */
  27. struct ossl_cmp_ctx_st {
  28. OSSL_LIB_CTX *libctx;
  29. char *propq;
  30. OSSL_CMP_log_cb_t log_cb; /* log callback for error/debug/etc. output */
  31. OSSL_CMP_severity log_verbosity; /* level of verbosity of log output */
  32. /* message transfer */
  33. OSSL_CMP_transfer_cb_t transfer_cb; /* default: OSSL_CMP_MSG_http_perform */
  34. void *transfer_cb_arg; /* allows to store optional argument to cb */
  35. /* HTTP-based transfer */
  36. OSSL_HTTP_REQ_CTX *http_ctx;
  37. char *serverPath;
  38. char *server;
  39. int serverPort;
  40. char *proxy;
  41. char *no_proxy;
  42. int keep_alive; /* persistent connection: 0=no, 1=prefer, 2=require */
  43. int msg_timeout; /* max seconds to wait for each CMP message round trip */
  44. int total_timeout; /* max number of seconds an enrollment may take, incl. */
  45. int tls_used; /* whether to use TLS for client-side HTTP connections */
  46. /* attempts polling for a response if a 'waiting' PKIStatus is received */
  47. time_t end_time; /* session start time + totaltimeout */
  48. # ifndef OPENSSL_NO_HTTP
  49. OSSL_HTTP_bio_cb_t http_cb;
  50. void *http_cb_arg; /* allows to store optional argument to cb */
  51. # endif
  52. /* server authentication */
  53. /*
  54. * unprotectedErrors may be set as workaround for broken server responses:
  55. * accept missing or invalid protection of regular error messages, negative
  56. * certificate responses (ip/cp/kup), revocation responses (rp), and PKIConf
  57. */
  58. int unprotectedErrors;
  59. int noCacheExtraCerts;
  60. X509 *srvCert; /* certificate used to identify the server */
  61. X509 *validatedSrvCert; /* caches any already validated server cert */
  62. X509_NAME *expected_sender; /* expected sender in header of response */
  63. X509_STORE *trusted; /* trust store maybe w CRLs and cert verify callback */
  64. STACK_OF(X509) *untrusted; /* untrusted (intermediate CA) certs */
  65. int ignore_keyusage; /* ignore key usage entry when validating certs */
  66. /*
  67. * permitTAInExtraCertsForIR allows use of root certs in extracerts
  68. * when validating message protection; this is used for 3GPP-style E.7
  69. */
  70. int permitTAInExtraCertsForIR;
  71. /* client authentication */
  72. int unprotectedSend; /* send unprotected PKI messages */
  73. X509 *cert; /* protection cert used to identify and sign for MSG_SIG_ALG */
  74. STACK_OF(X509) *chain; /* (cached) chain of protection cert including it */
  75. EVP_PKEY *pkey; /* the key pair corresponding to cert */
  76. ASN1_OCTET_STRING *referenceValue; /* optional username for MSG_MAC_ALG */
  77. ASN1_OCTET_STRING *secretValue; /* password/shared secret for MSG_MAC_ALG */
  78. /* PBMParameters for MSG_MAC_ALG */
  79. size_t pbm_slen; /* salt length, currently fixed to 16 */
  80. EVP_MD *pbm_owf; /* one-way function (OWF), default: SHA256 */
  81. int pbm_itercnt; /* OWF iteration count, currently fixed to 500 */
  82. int pbm_mac; /* NID of MAC algorithm, default: HMAC-SHA1 as per RFC 4210 */
  83. /* CMP message header and extra certificates */
  84. X509_NAME *recipient; /* to set in recipient in pkiheader */
  85. EVP_MD *digest; /* digest used in MSG_SIG_ALG and POPO, default SHA256 */
  86. ASN1_OCTET_STRING *transactionID; /* the current transaction ID */
  87. ASN1_OCTET_STRING *senderNonce; /* last nonce sent */
  88. ASN1_OCTET_STRING *recipNonce; /* last nonce received */
  89. ASN1_OCTET_STRING *first_senderNonce; /* sender nonce when starting to poll */
  90. ASN1_UTF8STRING *freeText; /* optional string to include each msg */
  91. STACK_OF(OSSL_CMP_ITAV) *geninfo_ITAVs;
  92. int implicitConfirm; /* set implicitConfirm in IR/KUR/CR messages */
  93. int disableConfirm; /* disable certConf in IR/KUR/CR for broken servers */
  94. STACK_OF(X509) *extraCertsOut; /* to be included in request messages */
  95. /* certificate template */
  96. EVP_PKEY *newPkey; /* explicit new private/public key for cert enrollment */
  97. int newPkey_priv; /* flag indicating if newPkey contains private key */
  98. X509_NAME *issuer; /* issuer name to used in cert template, also in rr */
  99. ASN1_INTEGER *serialNumber; /* certificate serial number to use in rr */
  100. int days; /* Number of days new certificates are asked to be valid for */
  101. X509_NAME *subjectName; /* subject name to be used in cert template */
  102. STACK_OF(GENERAL_NAME) *subjectAltNames; /* to add to the cert template */
  103. int SubjectAltName_nodefault;
  104. int setSubjectAltNameCritical;
  105. X509_EXTENSIONS *reqExtensions; /* exts to be added to cert template */
  106. CERTIFICATEPOLICIES *policies; /* policies to be included in extensions */
  107. int setPoliciesCritical;
  108. int popoMethod; /* Proof-of-possession mechanism; default: signature */
  109. X509 *oldCert; /* cert to be updated (via KUR) or to be revoked (via RR) */
  110. X509_REQ *p10CSR; /* for P10CR: PKCS#10 CSR to be sent */
  111. /* misc body contents */
  112. int revocationReason; /* revocation reason code to be included in RR */
  113. STACK_OF(OSSL_CMP_ITAV) *genm_ITAVs; /* content of general message */
  114. /* result returned in responses, so far supporting only one certResponse */
  115. int status; /* PKIStatus of last received IP/CP/KUP/RP/error or -1 */
  116. OSSL_CMP_PKIFREETEXT *statusString; /* of last IP/CP/KUP/RP/error */
  117. int failInfoCode; /* failInfoCode of last received IP/CP/KUP/error, or -1 */
  118. X509 *newCert; /* newly enrolled cert received from the CA */
  119. STACK_OF(X509) *newChain; /* chain of newly enrolled cert received */
  120. STACK_OF(X509) *caPubs; /* CA certs received from server (in IP message) */
  121. STACK_OF(X509) *extraCertsIn; /* extraCerts received from server */
  122. /* certificate confirmation */
  123. OSSL_CMP_certConf_cb_t certConf_cb; /* callback for app checking new cert */
  124. void *certConf_cb_arg; /* allows to store an argument individual to cb */
  125. } /* OSSL_CMP_CTX */;
  126. /*
  127. * ##########################################################################
  128. * ASN.1 DECLARATIONS
  129. * ##########################################################################
  130. */
  131. /*-
  132. * RevAnnContent ::= SEQUENCE {
  133. * status PKIStatus,
  134. * certId CertId,
  135. * willBeRevokedAt GeneralizedTime,
  136. * badSinceDate GeneralizedTime,
  137. * crlDetails Extensions OPTIONAL
  138. * -- extra CRL details (e.g., crl number, reason, location, etc.)
  139. * }
  140. */
  141. typedef struct ossl_cmp_revanncontent_st {
  142. ASN1_INTEGER *status;
  143. OSSL_CRMF_CERTID *certId;
  144. ASN1_GENERALIZEDTIME *willBeRevokedAt;
  145. ASN1_GENERALIZEDTIME *badSinceDate;
  146. X509_EXTENSIONS *crlDetails;
  147. } OSSL_CMP_REVANNCONTENT;
  148. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVANNCONTENT)
  149. /*-
  150. * Challenge ::= SEQUENCE {
  151. * owf AlgorithmIdentifier OPTIONAL,
  152. *
  153. * -- MUST be present in the first Challenge; MAY be omitted in
  154. * -- any subsequent Challenge in POPODecKeyChallContent (if
  155. * -- omitted, then the owf used in the immediately preceding
  156. * -- Challenge is to be used).
  157. *
  158. * witness OCTET STRING,
  159. * -- the result of applying the one-way function (owf) to a
  160. * -- randomly-generated INTEGER, A. [Note that a different
  161. * -- INTEGER MUST be used for each Challenge.]
  162. * challenge OCTET STRING
  163. * -- the encryption (under the public key for which the cert.
  164. * -- request is being made) of Rand, where Rand is specified as
  165. * -- Rand ::= SEQUENCE {
  166. * -- int INTEGER,
  167. * -- - the randomly-generated INTEGER A (above)
  168. * -- sender GeneralName
  169. * -- - the sender's name (as included in PKIHeader)
  170. * -- }
  171. * }
  172. */
  173. typedef struct ossl_cmp_challenge_st {
  174. X509_ALGOR *owf;
  175. ASN1_OCTET_STRING *witness;
  176. ASN1_OCTET_STRING *challenge;
  177. } OSSL_CMP_CHALLENGE;
  178. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CHALLENGE)
  179. /*-
  180. * CAKeyUpdAnnContent ::= SEQUENCE {
  181. * oldWithNew Certificate,
  182. * newWithOld Certificate,
  183. * newWithNew Certificate
  184. * }
  185. */
  186. typedef struct ossl_cmp_cakeyupdanncontent_st {
  187. X509 *oldWithNew;
  188. X509 *newWithOld;
  189. X509 *newWithNew;
  190. } OSSL_CMP_CAKEYUPDANNCONTENT;
  191. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CAKEYUPDANNCONTENT)
  192. typedef struct ossl_cmp_rootcakeyupdate_st OSSL_CMP_ROOTCAKEYUPDATE;
  193. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ROOTCAKEYUPDATE)
  194. /*-
  195. * declared already here as it will be used in OSSL_CMP_MSG (nested) and
  196. * infoType and infoValue
  197. */
  198. typedef STACK_OF(OSSL_CMP_MSG) OSSL_CMP_MSGS;
  199. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_MSGS)
  200. /*-
  201. * InfoTypeAndValue ::= SEQUENCE {
  202. * infoType OBJECT IDENTIFIER,
  203. * infoValue ANY DEFINED BY infoType OPTIONAL
  204. * }
  205. */
  206. struct ossl_cmp_itav_st {
  207. ASN1_OBJECT *infoType;
  208. union {
  209. char *ptr;
  210. /* NID_id_it_caProtEncCert - CA Protocol Encryption Certificate */
  211. X509 *caProtEncCert;
  212. /* NID_id_it_signKeyPairTypes - Signing Key Pair Types */
  213. STACK_OF(X509_ALGOR) *signKeyPairTypes;
  214. /* NID_id_it_encKeyPairTypes - Encryption/Key Agreement Key Pair Types */
  215. STACK_OF(X509_ALGOR) *encKeyPairTypes;
  216. /* NID_id_it_preferredSymmAlg - Preferred Symmetric Algorithm */
  217. X509_ALGOR *preferredSymmAlg;
  218. /* NID_id_it_caKeyUpdateInfo - Updated CA Key Pair */
  219. OSSL_CMP_CAKEYUPDANNCONTENT *caKeyUpdateInfo;
  220. /* NID_id_it_currentCRL - CRL */
  221. X509_CRL *currentCRL;
  222. /* NID_id_it_unsupportedOIDs - Unsupported Object Identifiers */
  223. STACK_OF(ASN1_OBJECT) *unsupportedOIDs;
  224. /* NID_id_it_keyPairParamReq - Key Pair Parameters Request */
  225. ASN1_OBJECT *keyPairParamReq;
  226. /* NID_id_it_keyPairParamRep - Key Pair Parameters Response */
  227. X509_ALGOR *keyPairParamRep;
  228. /* NID_id_it_revPassphrase - Revocation Passphrase */
  229. OSSL_CRMF_ENCRYPTEDVALUE *revPassphrase;
  230. /* NID_id_it_implicitConfirm - ImplicitConfirm */
  231. ASN1_NULL *implicitConfirm;
  232. /* NID_id_it_confirmWaitTime - ConfirmWaitTime */
  233. ASN1_GENERALIZEDTIME *confirmWaitTime;
  234. /* NID_id_it_origPKIMessage - origPKIMessage */
  235. OSSL_CMP_MSGS *origPKIMessage;
  236. /* NID_id_it_suppLangTags - Supported Language Tags */
  237. STACK_OF(ASN1_UTF8STRING) *suppLangTagsValue;
  238. /* NID_id_it_certProfile - Certificate Profile */
  239. STACK_OF(ASN1_UTF8STRING) *certProfile;
  240. /* NID_id_it_caCerts - CA Certificates */
  241. STACK_OF(X509) *caCerts;
  242. /* NID_id_it_rootCaCert - Root CA Certificate */
  243. X509 *rootCaCert;
  244. /* NID_id_it_rootCaKeyUpdate - Root CA Certificate Update */
  245. OSSL_CMP_ROOTCAKEYUPDATE *rootCaKeyUpdate;
  246. /* this is to be used for so far undeclared objects */
  247. ASN1_TYPE *other;
  248. } infoValue;
  249. } /* OSSL_CMP_ITAV */;
  250. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ITAV)
  251. typedef struct ossl_cmp_certorenccert_st {
  252. int type;
  253. union {
  254. X509 *certificate;
  255. OSSL_CRMF_ENCRYPTEDVALUE *encryptedCert;
  256. } value;
  257. } OSSL_CMP_CERTORENCCERT;
  258. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTORENCCERT)
  259. /*-
  260. * CertifiedKeyPair ::= SEQUENCE {
  261. * certOrEncCert CertOrEncCert,
  262. * privateKey [0] EncryptedValue OPTIONAL,
  263. * -- see [CRMF] for comment on encoding
  264. * publicationInfo [1] PKIPublicationInfo OPTIONAL
  265. * }
  266. */
  267. typedef struct ossl_cmp_certifiedkeypair_st {
  268. OSSL_CMP_CERTORENCCERT *certOrEncCert;
  269. OSSL_CRMF_ENCRYPTEDVALUE *privateKey;
  270. OSSL_CRMF_PKIPUBLICATIONINFO *publicationInfo;
  271. } OSSL_CMP_CERTIFIEDKEYPAIR;
  272. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTIFIEDKEYPAIR)
  273. /*-
  274. * PKIStatusInfo ::= SEQUENCE {
  275. * status PKIStatus,
  276. * statusString PKIFreeText OPTIONAL,
  277. * failInfo PKIFailureInfo OPTIONAL
  278. * }
  279. */
  280. struct ossl_cmp_pkisi_st {
  281. OSSL_CMP_PKISTATUS *status;
  282. OSSL_CMP_PKIFREETEXT *statusString;
  283. OSSL_CMP_PKIFAILUREINFO *failInfo;
  284. } /* OSSL_CMP_PKISI */;
  285. /*-
  286. * RevReqContent ::= SEQUENCE OF RevDetails
  287. *
  288. * RevDetails ::= SEQUENCE {
  289. * certDetails CertTemplate,
  290. * crlEntryDetails Extensions OPTIONAL
  291. * }
  292. */
  293. struct ossl_cmp_revdetails_st {
  294. OSSL_CRMF_CERTTEMPLATE *certDetails;
  295. X509_EXTENSIONS *crlEntryDetails;
  296. } /* OSSL_CMP_REVDETAILS */;
  297. typedef struct ossl_cmp_revdetails_st OSSL_CMP_REVDETAILS;
  298. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVDETAILS)
  299. DEFINE_STACK_OF(OSSL_CMP_REVDETAILS)
  300. /*-
  301. * RevRepContent ::= SEQUENCE {
  302. * status SEQUENCE SIZE (1..MAX) OF PKIStatusInfo,
  303. * -- in same order as was sent in RevReqContent
  304. * revCerts [0] SEQUENCE SIZE (1..MAX) OF CertId
  305. * OPTIONAL,
  306. * -- IDs for which revocation was requested
  307. * -- (same order as status)
  308. * crls [1] SEQUENCE SIZE (1..MAX) OF CertificateList
  309. * OPTIONAL
  310. * -- the resulting CRLs (there may be more than one)
  311. * }
  312. */
  313. struct ossl_cmp_revrepcontent_st {
  314. STACK_OF(OSSL_CMP_PKISI) *status;
  315. STACK_OF(OSSL_CRMF_CERTID) *revCerts;
  316. STACK_OF(X509_CRL) *crls;
  317. } /* OSSL_CMP_REVREPCONTENT */;
  318. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVREPCONTENT)
  319. /*-
  320. * KeyRecRepContent ::= SEQUENCE {
  321. * status PKIStatusInfo,
  322. * newSigCert [0] Certificate OPTIONAL,
  323. * caCerts [1] SEQUENCE SIZE (1..MAX) OF
  324. * Certificate OPTIONAL,
  325. * keyPairHist [2] SEQUENCE SIZE (1..MAX) OF
  326. * CertifiedKeyPair OPTIONAL
  327. * }
  328. */
  329. typedef struct ossl_cmp_keyrecrepcontent_st {
  330. OSSL_CMP_PKISI *status;
  331. X509 *newSigCert;
  332. STACK_OF(X509) *caCerts;
  333. STACK_OF(OSSL_CMP_CERTIFIEDKEYPAIR) *keyPairHist;
  334. } OSSL_CMP_KEYRECREPCONTENT;
  335. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_KEYRECREPCONTENT)
  336. /*-
  337. * ErrorMsgContent ::= SEQUENCE {
  338. * pKIStatusInfo PKIStatusInfo,
  339. * errorCode INTEGER OPTIONAL,
  340. * -- implementation-specific error codes
  341. * errorDetails PKIFreeText OPTIONAL
  342. * -- implementation-specific error details
  343. * }
  344. */
  345. typedef struct ossl_cmp_errormsgcontent_st {
  346. OSSL_CMP_PKISI *pKIStatusInfo;
  347. ASN1_INTEGER *errorCode;
  348. OSSL_CMP_PKIFREETEXT *errorDetails;
  349. } OSSL_CMP_ERRORMSGCONTENT;
  350. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ERRORMSGCONTENT)
  351. /*-
  352. * CertConfirmContent ::= SEQUENCE OF CertStatus
  353. *
  354. * CertStatus ::= SEQUENCE {
  355. * certHash OCTET STRING,
  356. * -- the hash of the certificate, using the same hash algorithm
  357. * -- as is used to create and verify the certificate signature
  358. * certReqId INTEGER,
  359. * -- to match this confirmation with the corresponding req/rep
  360. * statusInfo PKIStatusInfo OPTIONAL,
  361. * hashAlg [0] AlgorithmIdentifier OPTIONAL
  362. * }
  363. */
  364. struct ossl_cmp_certstatus_st {
  365. ASN1_OCTET_STRING *certHash;
  366. ASN1_INTEGER *certReqId;
  367. OSSL_CMP_PKISI *statusInfo;
  368. X509_ALGOR *hashAlg; /* 0 */
  369. } /* OSSL_CMP_CERTSTATUS */;
  370. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTSTATUS)
  371. typedef STACK_OF(OSSL_CMP_CERTSTATUS) OSSL_CMP_CERTCONFIRMCONTENT;
  372. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTCONFIRMCONTENT)
  373. /*-
  374. * CertResponse ::= SEQUENCE {
  375. * certReqId INTEGER,
  376. * -- to match this response with corresponding request (a value
  377. * -- of -1 is to be used if certReqId is not specified in the
  378. * -- corresponding request)
  379. * status PKIStatusInfo,
  380. * certifiedKeyPair CertifiedKeyPair OPTIONAL,
  381. * rspInfo OCTET STRING OPTIONAL
  382. * -- analogous to the id-regInfo-utf8Pairs string defined
  383. * -- for regInfo in CertReqMsg [CRMF]
  384. * }
  385. */
  386. struct ossl_cmp_certresponse_st {
  387. ASN1_INTEGER *certReqId;
  388. OSSL_CMP_PKISI *status;
  389. OSSL_CMP_CERTIFIEDKEYPAIR *certifiedKeyPair;
  390. ASN1_OCTET_STRING *rspInfo;
  391. } /* OSSL_CMP_CERTRESPONSE */;
  392. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTRESPONSE)
  393. /*-
  394. * CertRepMessage ::= SEQUENCE {
  395. * caPubs [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
  396. * OPTIONAL,
  397. * response SEQUENCE OF CertResponse
  398. * }
  399. */
  400. struct ossl_cmp_certrepmessage_st {
  401. STACK_OF(X509) *caPubs;
  402. STACK_OF(OSSL_CMP_CERTRESPONSE) *response;
  403. } /* OSSL_CMP_CERTREPMESSAGE */;
  404. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTREPMESSAGE)
  405. /*-
  406. * PollReqContent ::= SEQUENCE OF SEQUENCE {
  407. * certReqId INTEGER
  408. * }
  409. */
  410. typedef struct ossl_cmp_pollreq_st {
  411. ASN1_INTEGER *certReqId;
  412. } OSSL_CMP_POLLREQ;
  413. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREQ)
  414. DEFINE_STACK_OF(OSSL_CMP_POLLREQ)
  415. typedef STACK_OF(OSSL_CMP_POLLREQ) OSSL_CMP_POLLREQCONTENT;
  416. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREQCONTENT)
  417. /*-
  418. * PollRepContent ::= SEQUENCE OF SEQUENCE {
  419. * certReqId INTEGER,
  420. * checkAfter INTEGER, -- time in seconds
  421. * reason PKIFreeText OPTIONAL
  422. * }
  423. */
  424. struct ossl_cmp_pollrep_st {
  425. ASN1_INTEGER *certReqId;
  426. ASN1_INTEGER *checkAfter;
  427. OSSL_CMP_PKIFREETEXT *reason;
  428. } /* OSSL_CMP_POLLREP */;
  429. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREP)
  430. DEFINE_STACK_OF(OSSL_CMP_POLLREP)
  431. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREPCONTENT)
  432. /*-
  433. * PKIHeader ::= SEQUENCE {
  434. * pvno INTEGER { cmp1999(1), cmp2000(2), cmp2021(3) },
  435. * sender GeneralName,
  436. * -- identifies the sender
  437. * recipient GeneralName,
  438. * -- identifies the intended recipient
  439. * messageTime [0] GeneralizedTime OPTIONAL,
  440. * -- time of production of this message (used when sender
  441. * -- believes that the transport will be "suitable"; i.e.,
  442. * -- that the time will still be meaningful upon receipt)
  443. * protectionAlg [1] AlgorithmIdentifier OPTIONAL,
  444. * -- algorithm used for calculation of protection bits
  445. * senderKID [2] KeyIdentifier OPTIONAL,
  446. * recipKID [3] KeyIdentifier OPTIONAL,
  447. * -- to identify specific keys used for protection
  448. * transactionID [4] OCTET STRING OPTIONAL,
  449. * -- identifies the transaction; i.e., this will be the same in
  450. * -- corresponding request, response, certConf, and PKIConf
  451. * -- messages
  452. * senderNonce [5] OCTET STRING OPTIONAL,
  453. * recipNonce [6] OCTET STRING OPTIONAL,
  454. * -- nonces used to provide replay protection, senderNonce
  455. * -- is inserted by the creator of this message; recipNonce
  456. * -- is a nonce previously inserted in a related message by
  457. * -- the intended recipient of this message
  458. * freeText [7] PKIFreeText OPTIONAL,
  459. * -- this may be used to indicate context-specific instructions
  460. * -- (this field is intended for human consumption)
  461. * generalInfo [8] SEQUENCE SIZE (1..MAX) OF
  462. * InfoTypeAndValue OPTIONAL
  463. * -- this may be used to convey context-specific information
  464. * -- (this field not primarily intended for human consumption)
  465. * }
  466. */
  467. struct ossl_cmp_pkiheader_st {
  468. ASN1_INTEGER *pvno;
  469. GENERAL_NAME *sender;
  470. GENERAL_NAME *recipient;
  471. ASN1_GENERALIZEDTIME *messageTime; /* 0 */
  472. X509_ALGOR *protectionAlg; /* 1 */
  473. ASN1_OCTET_STRING *senderKID; /* 2 */
  474. ASN1_OCTET_STRING *recipKID; /* 3 */
  475. ASN1_OCTET_STRING *transactionID; /* 4 */
  476. ASN1_OCTET_STRING *senderNonce; /* 5 */
  477. ASN1_OCTET_STRING *recipNonce; /* 6 */
  478. OSSL_CMP_PKIFREETEXT *freeText; /* 7 */
  479. STACK_OF(OSSL_CMP_ITAV) *generalInfo; /* 8 */
  480. } /* OSSL_CMP_PKIHEADER */;
  481. typedef STACK_OF(OSSL_CMP_CHALLENGE) OSSL_CMP_POPODECKEYCHALLCONTENT;
  482. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POPODECKEYCHALLCONTENT)
  483. typedef STACK_OF(ASN1_INTEGER) OSSL_CMP_POPODECKEYRESPCONTENT;
  484. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POPODECKEYRESPCONTENT)
  485. typedef STACK_OF(OSSL_CMP_REVDETAILS) OSSL_CMP_REVREQCONTENT;
  486. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVREQCONTENT)
  487. typedef STACK_OF(X509_CRL) OSSL_CMP_CRLANNCONTENT;
  488. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CRLANNCONTENT)
  489. typedef STACK_OF(OSSL_CMP_ITAV) OSSL_CMP_GENMSGCONTENT;
  490. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_GENMSGCONTENT)
  491. typedef STACK_OF(OSSL_CMP_ITAV) OSSL_CMP_GENREPCONTENT;
  492. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_GENREPCONTENT)
  493. /*-
  494. * PKIBody ::= CHOICE { -- message-specific body elements
  495. * ir [0] CertReqMessages, --Initialization Request
  496. * ip [1] CertRepMessage, --Initialization Response
  497. * cr [2] CertReqMessages, --Certification Request
  498. * cp [3] CertRepMessage, --Certification Response
  499. * p10cr [4] CertificationRequest, --imported from [PKCS10]
  500. * popdecc [5] POPODecKeyChallContent, --pop Challenge
  501. * popdecr [6] POPODecKeyRespContent, --pop Response
  502. * kur [7] CertReqMessages, --Key Update Request
  503. * kup [8] CertRepMessage, --Key Update Response
  504. * krr [9] CertReqMessages, --Key Recovery Request
  505. * krp [10] KeyRecRepContent, --Key Recovery Response
  506. * rr [11] RevReqContent, --Revocation Request
  507. * rp [12] RevRepContent, --Revocation Response
  508. * ccr [13] CertReqMessages, --Cross-Cert. Request
  509. * ccp [14] CertRepMessage, --Cross-Cert. Response
  510. * ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
  511. * cann [16] CertAnnContent, --Certificate Ann.
  512. * rann [17] RevAnnContent, --Revocation Ann.
  513. * crlann [18] CRLAnnContent, --CRL Announcement
  514. * pkiconf [19] PKIConfirmContent, --Confirmation
  515. * nested [20] NestedMessageContent, --Nested Message
  516. * genm [21] GenMsgContent, --General Message
  517. * genp [22] GenRepContent, --General Response
  518. * error [23] ErrorMsgContent, --Error Message
  519. * certConf [24] CertConfirmContent, --Certificate confirm
  520. * pollReq [25] PollReqContent, --Polling request
  521. * pollRep [26] PollRepContent --Polling response
  522. * }
  523. */
  524. typedef struct ossl_cmp_pkibody_st {
  525. int type;
  526. union {
  527. OSSL_CRMF_MSGS *ir; /* 0 */
  528. OSSL_CMP_CERTREPMESSAGE *ip; /* 1 */
  529. OSSL_CRMF_MSGS *cr; /* 2 */
  530. OSSL_CMP_CERTREPMESSAGE *cp; /* 3 */
  531. /*-
  532. * p10cr [4] CertificationRequest, --imported from [PKCS10]
  533. *
  534. * PKCS10_CERTIFICATIONREQUEST is effectively X509_REQ
  535. * so it is used directly
  536. */
  537. X509_REQ *p10cr; /* 4 */
  538. /*-
  539. * popdecc [5] POPODecKeyChallContent, --pop Challenge
  540. *
  541. * POPODecKeyChallContent ::= SEQUENCE OF Challenge
  542. */
  543. OSSL_CMP_POPODECKEYCHALLCONTENT *popdecc; /* 5 */
  544. /*-
  545. * popdecr [6] POPODecKeyRespContent, --pop Response
  546. *
  547. * POPODecKeyRespContent ::= SEQUENCE OF INTEGER
  548. */
  549. OSSL_CMP_POPODECKEYRESPCONTENT *popdecr; /* 6 */
  550. OSSL_CRMF_MSGS *kur; /* 7 */
  551. OSSL_CMP_CERTREPMESSAGE *kup; /* 8 */
  552. OSSL_CRMF_MSGS *krr; /* 9 */
  553. /*-
  554. * krp [10] KeyRecRepContent, --Key Recovery Response
  555. */
  556. OSSL_CMP_KEYRECREPCONTENT *krp; /* 10 */
  557. /*-
  558. * rr [11] RevReqContent, --Revocation Request
  559. */
  560. OSSL_CMP_REVREQCONTENT *rr; /* 11 */
  561. /*-
  562. * rp [12] RevRepContent, --Revocation Response
  563. */
  564. OSSL_CMP_REVREPCONTENT *rp; /* 12 */
  565. /*-
  566. * ccr [13] CertReqMessages, --Cross-Cert. Request
  567. */
  568. OSSL_CRMF_MSGS *ccr; /* 13 */
  569. /*-
  570. * ccp [14] CertRepMessage, --Cross-Cert. Response
  571. */
  572. OSSL_CMP_CERTREPMESSAGE *ccp; /* 14 */
  573. /*-
  574. * ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
  575. */
  576. OSSL_CMP_CAKEYUPDANNCONTENT *ckuann; /* 15 */
  577. /*-
  578. * cann [16] CertAnnContent, --Certificate Ann.
  579. * OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly
  580. */
  581. X509 *cann; /* 16 */
  582. /*-
  583. * rann [17] RevAnnContent, --Revocation Ann.
  584. */
  585. OSSL_CMP_REVANNCONTENT *rann; /* 17 */
  586. /*-
  587. * crlann [18] CRLAnnContent, --CRL Announcement
  588. * CRLAnnContent ::= SEQUENCE OF CertificateList
  589. */
  590. OSSL_CMP_CRLANNCONTENT *crlann; /* 18 */
  591. /*-
  592. * PKIConfirmContent ::= NULL
  593. * pkiconf [19] PKIConfirmContent, --Confirmation
  594. * OSSL_CMP_PKICONFIRMCONTENT would be only a typedef of ASN1_NULL
  595. * OSSL_CMP_CONFIRMCONTENT *pkiconf;
  596. *
  597. * NOTE: this should ASN1_NULL according to the RFC
  598. * but there might be a struct in it when sent from faulty servers...
  599. */
  600. ASN1_TYPE *pkiconf; /* 19 */
  601. /*-
  602. * nested [20] NestedMessageContent, --Nested Message
  603. * NestedMessageContent ::= PKIMessages
  604. */
  605. OSSL_CMP_MSGS *nested; /* 20 */
  606. /*-
  607. * genm [21] GenMsgContent, --General Message
  608. * GenMsgContent ::= SEQUENCE OF InfoTypeAndValue
  609. */
  610. OSSL_CMP_GENMSGCONTENT *genm; /* 21 */
  611. /*-
  612. * genp [22] GenRepContent, --General Response
  613. * GenRepContent ::= SEQUENCE OF InfoTypeAndValue
  614. */
  615. OSSL_CMP_GENREPCONTENT *genp; /* 22 */
  616. /*-
  617. * error [23] ErrorMsgContent, --Error Message
  618. */
  619. OSSL_CMP_ERRORMSGCONTENT *error; /* 23 */
  620. /*-
  621. * certConf [24] CertConfirmContent, --Certificate confirm
  622. */
  623. OSSL_CMP_CERTCONFIRMCONTENT *certConf; /* 24 */
  624. /*-
  625. * pollReq [25] PollReqContent, --Polling request
  626. */
  627. OSSL_CMP_POLLREQCONTENT *pollReq; /* 25 */
  628. /*-
  629. * pollRep [26] PollRepContent --Polling response
  630. */
  631. OSSL_CMP_POLLREPCONTENT *pollRep; /* 26 */
  632. } value;
  633. } OSSL_CMP_PKIBODY;
  634. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKIBODY)
  635. /*-
  636. * PKIProtection ::= BIT STRING
  637. *
  638. * PKIMessages ::= SEQUENCE SIZE (1..MAX) OF PKIMessage
  639. *
  640. * PKIMessage ::= SEQUENCE {
  641. * header PKIHeader,
  642. * body PKIBody,
  643. * protection [0] PKIProtection OPTIONAL,
  644. * extraCerts [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
  645. * OPTIONAL
  646. * }
  647. */
  648. struct ossl_cmp_msg_st {
  649. OSSL_CMP_PKIHEADER *header;
  650. OSSL_CMP_PKIBODY *body;
  651. ASN1_BIT_STRING *protection; /* 0 */
  652. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  653. STACK_OF(X509) *extraCerts; /* 1 */
  654. OSSL_LIB_CTX *libctx;
  655. char *propq;
  656. } /* OSSL_CMP_MSG */;
  657. OSSL_CMP_MSG *OSSL_CMP_MSG_new(OSSL_LIB_CTX *libctx, const char *propq);
  658. void OSSL_CMP_MSG_free(OSSL_CMP_MSG *msg);
  659. /*-
  660. * ProtectedPart ::= SEQUENCE {
  661. * header PKIHeader,
  662. * body PKIBody
  663. * }
  664. */
  665. typedef struct ossl_cmp_protectedpart_st {
  666. OSSL_CMP_PKIHEADER *header;
  667. OSSL_CMP_PKIBODY *body;
  668. } OSSL_CMP_PROTECTEDPART;
  669. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PROTECTEDPART)
  670. /*-
  671. * this is not defined here as it is already in CRMF:
  672. * id-PasswordBasedMac OBJECT IDENTIFIER ::= {1 2 840 113533 7 66 13}
  673. * PBMParameter ::= SEQUENCE {
  674. * salt OCTET STRING,
  675. * -- note: implementations MAY wish to limit acceptable sizes
  676. * -- of this string to values appropriate for their environment
  677. * -- in order to reduce the risk of denial-of-service attacks
  678. * owf AlgorithmIdentifier,
  679. * -- AlgId for a One-Way Function (SHA-1 recommended)
  680. * iterationCount INTEGER,
  681. * -- number of times the OWF is applied
  682. * -- note: implementations MAY wish to limit acceptable sizes
  683. * -- of this integer to values appropriate for their environment
  684. * -- in order to reduce the risk of denial-of-service attacks
  685. * mac AlgorithmIdentifier
  686. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  687. * } -- or HMAC [RFC2104, RFC2202])
  688. */
  689. /*-
  690. * Not supported:
  691. * id-DHBasedMac OBJECT IDENTIFIER ::= {1 2 840 113533 7 66 30}
  692. * DHBMParameter ::= SEQUENCE {
  693. * owf AlgorithmIdentifier,
  694. * -- AlgId for a One-Way Function (SHA-1 recommended)
  695. * mac AlgorithmIdentifier
  696. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  697. * } -- or HMAC [RFC2104, RFC2202])
  698. */
  699. /*-
  700. * The following is not cared for, because it is described in section 5.2.5
  701. * that this is beyond the scope of CMP
  702. * OOBCert ::= CMPCertificate
  703. *
  704. * OOBCertHash ::= SEQUENCE {
  705. * hashAlg [0] AlgorithmIdentifier OPTIONAL,
  706. * certId [1] CertId OPTIONAL,
  707. * hashVal BIT STRING
  708. * -- hashVal is calculated over the DER encoding of the
  709. * -- self-signed certificate with the identifier certID.
  710. * }
  711. */
  712. /*
  713. * RootCaKeyUpdateContent ::= SEQUENCE {
  714. * newWithNew CMPCertificate,
  715. * newWithOld [0] CMPCertificate OPTIONAL,
  716. * oldWithNew [1] CMPCertificate OPTIONAL
  717. * }
  718. */
  719. struct ossl_cmp_rootcakeyupdate_st {
  720. X509 *newWithNew;
  721. X509 *newWithOld;
  722. X509 *oldWithNew;
  723. } /* OSSL_CMP_ROOTCAKEYUPDATE */;
  724. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ROOTCAKEYUPDATE)
  725. /* from cmp_asn.c */
  726. int ossl_cmp_asn1_get_int(const ASN1_INTEGER *a);
  727. /* from cmp_util.c */
  728. const char *ossl_cmp_log_parse_metadata(const char *buf,
  729. OSSL_CMP_severity *level, char **func,
  730. char **file, int *line);
  731. # define ossl_cmp_add_error_data(txt) ERR_add_error_txt(" : ", txt)
  732. # define ossl_cmp_add_error_line(txt) ERR_add_error_txt("\n", txt)
  733. /* The two functions manipulating X509_STORE could be generally useful */
  734. int ossl_cmp_X509_STORE_add1_certs(X509_STORE *store, STACK_OF(X509) *certs,
  735. int only_self_issued);
  736. STACK_OF(X509) *ossl_cmp_X509_STORE_get1_certs(X509_STORE *store);
  737. int ossl_cmp_sk_ASN1_UTF8STRING_push_str(STACK_OF(ASN1_UTF8STRING) *sk,
  738. const char *text, int len);
  739. int ossl_cmp_asn1_octet_string_set1(ASN1_OCTET_STRING **tgt,
  740. const ASN1_OCTET_STRING *src);
  741. int ossl_cmp_asn1_octet_string_set1_bytes(ASN1_OCTET_STRING **tgt,
  742. const unsigned char *bytes, int len);
  743. /* from cmp_ctx.c */
  744. int ossl_cmp_print_log(OSSL_CMP_severity level, const OSSL_CMP_CTX *ctx,
  745. const char *func, const char *file, int line,
  746. const char *level_str, const char *format, ...);
  747. # define ossl_cmp_log(level, ctx, msg) \
  748. ossl_cmp_print_log(OSSL_CMP_LOG_##level, ctx, OPENSSL_FUNC, OPENSSL_FILE, \
  749. OPENSSL_LINE, #level, "%s", msg)
  750. # define ossl_cmp_log1(level, ctx, fmt, arg1) \
  751. ossl_cmp_print_log(OSSL_CMP_LOG_##level, ctx, OPENSSL_FUNC, OPENSSL_FILE, \
  752. OPENSSL_LINE, #level, fmt, arg1)
  753. # define ossl_cmp_log2(level, ctx, fmt, arg1, arg2) \
  754. ossl_cmp_print_log(OSSL_CMP_LOG_##level, ctx, OPENSSL_FUNC, OPENSSL_FILE, \
  755. OPENSSL_LINE, #level, fmt, arg1, arg2)
  756. # define ossl_cmp_log3(level, ctx, fmt, arg1, arg2, arg3) \
  757. ossl_cmp_print_log(OSSL_CMP_LOG_##level, ctx, OPENSSL_FUNC, OPENSSL_FILE, \
  758. OPENSSL_LINE, #level, fmt, arg1, arg2, arg3)
  759. # define ossl_cmp_log4(level, ctx, fmt, arg1, arg2, arg3, arg4) \
  760. ossl_cmp_print_log(OSSL_CMP_LOG_##level, ctx, OPENSSL_FUNC, OPENSSL_FILE, \
  761. OPENSSL_LINE, #level, fmt, arg1, arg2, arg3, arg4)
  762. # define OSSL_CMP_LOG_ERROR OSSL_CMP_LOG_ERR
  763. # define OSSL_CMP_LOG_WARN OSSL_CMP_LOG_WARNING
  764. # define ossl_cmp_alert(ctx, msg) ossl_cmp_log(ALERT, ctx, msg)
  765. # define ossl_cmp_err(ctx, msg) ossl_cmp_log(ERROR, ctx, msg)
  766. # define ossl_cmp_warn(ctx, msg) ossl_cmp_log(WARN, ctx, msg)
  767. # define ossl_cmp_info(ctx, msg) ossl_cmp_log(INFO, ctx, msg)
  768. # define ossl_cmp_debug(ctx, msg) ossl_cmp_log(DEBUG, ctx, msg)
  769. # define ossl_cmp_trace(ctx, msg) ossl_cmp_log(TRACE, ctx, msg)
  770. int ossl_cmp_ctx_set1_validatedSrvCert(OSSL_CMP_CTX *ctx, X509 *cert);
  771. int ossl_cmp_ctx_set_status(OSSL_CMP_CTX *ctx, int status);
  772. int ossl_cmp_ctx_set0_statusString(OSSL_CMP_CTX *ctx,
  773. OSSL_CMP_PKIFREETEXT *text);
  774. int ossl_cmp_ctx_set_failInfoCode(OSSL_CMP_CTX *ctx, int fail_info);
  775. int ossl_cmp_ctx_set0_newCert(OSSL_CMP_CTX *ctx, X509 *cert);
  776. int ossl_cmp_ctx_set1_newChain(OSSL_CMP_CTX *ctx, STACK_OF(X509) *newChain);
  777. int ossl_cmp_ctx_set1_caPubs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *caPubs);
  778. int ossl_cmp_ctx_set1_extraCertsIn(OSSL_CMP_CTX *ctx,
  779. STACK_OF(X509) *extraCertsIn);
  780. int ossl_cmp_ctx_set1_recipNonce(OSSL_CMP_CTX *ctx,
  781. const ASN1_OCTET_STRING *nonce);
  782. EVP_PKEY *ossl_cmp_ctx_get0_newPubkey(const OSSL_CMP_CTX *ctx);
  783. int ossl_cmp_ctx_set1_first_senderNonce(OSSL_CMP_CTX *ctx,
  784. const ASN1_OCTET_STRING *nonce);
  785. /* from cmp_status.c */
  786. int ossl_cmp_pkisi_get_status(const OSSL_CMP_PKISI *si);
  787. const char *ossl_cmp_PKIStatus_to_string(int status);
  788. OSSL_CMP_PKIFREETEXT *ossl_cmp_pkisi_get0_statusString(const OSSL_CMP_PKISI *s);
  789. int ossl_cmp_pkisi_get_pkifailureinfo(const OSSL_CMP_PKISI *si);
  790. int ossl_cmp_pkisi_check_pkifailureinfo(const OSSL_CMP_PKISI *si, int index);
  791. /* from cmp_hdr.c */
  792. int ossl_cmp_hdr_set_pvno(OSSL_CMP_PKIHEADER *hdr, int pvno);
  793. int ossl_cmp_hdr_get_pvno(const OSSL_CMP_PKIHEADER *hdr);
  794. int ossl_cmp_hdr_get_protection_nid(const OSSL_CMP_PKIHEADER *hdr);
  795. ASN1_OCTET_STRING *ossl_cmp_hdr_get0_senderNonce(const OSSL_CMP_PKIHEADER *hdr);
  796. int ossl_cmp_general_name_is_NULL_DN(GENERAL_NAME *name);
  797. int ossl_cmp_hdr_set1_sender(OSSL_CMP_PKIHEADER *hdr, const X509_NAME *nm);
  798. int ossl_cmp_hdr_set1_recipient(OSSL_CMP_PKIHEADER *hdr, const X509_NAME *nm);
  799. int ossl_cmp_hdr_update_messageTime(OSSL_CMP_PKIHEADER *hdr);
  800. int ossl_cmp_hdr_set1_senderKID(OSSL_CMP_PKIHEADER *hdr,
  801. const ASN1_OCTET_STRING *senderKID);
  802. int ossl_cmp_hdr_push0_freeText(OSSL_CMP_PKIHEADER *hdr, ASN1_UTF8STRING *text);
  803. int ossl_cmp_hdr_push1_freeText(OSSL_CMP_PKIHEADER *hdr, ASN1_UTF8STRING *text);
  804. int ossl_cmp_hdr_generalInfo_push0_item(OSSL_CMP_PKIHEADER *hdr,
  805. OSSL_CMP_ITAV *itav);
  806. int ossl_cmp_hdr_generalInfo_push1_items(OSSL_CMP_PKIHEADER *hdr,
  807. const STACK_OF(OSSL_CMP_ITAV) *itavs);
  808. int ossl_cmp_hdr_set_implicitConfirm(OSSL_CMP_PKIHEADER *hdr);
  809. int ossl_cmp_hdr_has_implicitConfirm(const OSSL_CMP_PKIHEADER *hdr);
  810. # define OSSL_CMP_TRANSACTIONID_LENGTH 16
  811. # define OSSL_CMP_SENDERNONCE_LENGTH 16
  812. int ossl_cmp_hdr_set_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr);
  813. int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr);
  814. /* from cmp_msg.c */
  815. /* OSSL_CMP_MSG bodytype ASN.1 choice IDs */
  816. # define OSSL_CMP_PKIBODY_IR 0
  817. # define OSSL_CMP_PKIBODY_IP 1
  818. # define OSSL_CMP_PKIBODY_CR 2
  819. # define OSSL_CMP_PKIBODY_CP 3
  820. # define OSSL_CMP_PKIBODY_P10CR 4
  821. # define OSSL_CMP_PKIBODY_POPDECC 5
  822. # define OSSL_CMP_PKIBODY_POPDECR 6
  823. # define OSSL_CMP_PKIBODY_KUR 7
  824. # define OSSL_CMP_PKIBODY_KUP 8
  825. # define OSSL_CMP_PKIBODY_KRR 9
  826. # define OSSL_CMP_PKIBODY_KRP 10
  827. # define OSSL_CMP_PKIBODY_RR 11
  828. # define OSSL_CMP_PKIBODY_RP 12
  829. # define OSSL_CMP_PKIBODY_CCR 13
  830. # define OSSL_CMP_PKIBODY_CCP 14
  831. # define OSSL_CMP_PKIBODY_CKUANN 15
  832. # define OSSL_CMP_PKIBODY_CANN 16
  833. # define OSSL_CMP_PKIBODY_RANN 17
  834. # define OSSL_CMP_PKIBODY_CRLANN 18
  835. # define OSSL_CMP_PKIBODY_PKICONF 19
  836. # define OSSL_CMP_PKIBODY_NESTED 20
  837. # define OSSL_CMP_PKIBODY_GENM 21
  838. # define OSSL_CMP_PKIBODY_GENP 22
  839. # define OSSL_CMP_PKIBODY_ERROR 23
  840. # define OSSL_CMP_PKIBODY_CERTCONF 24
  841. # define OSSL_CMP_PKIBODY_POLLREQ 25
  842. # define OSSL_CMP_PKIBODY_POLLREP 26
  843. # define OSSL_CMP_PKIBODY_TYPE_MAX OSSL_CMP_PKIBODY_POLLREP
  844. /* certReqId for the first - and so far only - certificate request */
  845. # define OSSL_CMP_CERTREQID 0
  846. # define OSSL_CMP_CERTREQID_NONE -1
  847. # define OSSL_CMP_CERTREQID_INVALID -2
  848. /* sequence id for the first - and so far only - revocation request */
  849. # define OSSL_CMP_REVREQSID 0
  850. int ossl_cmp_msg_set0_libctx(OSSL_CMP_MSG *msg, OSSL_LIB_CTX *libctx,
  851. const char *propq);
  852. const char *ossl_cmp_bodytype_to_string(int type);
  853. int ossl_cmp_msg_set_bodytype(OSSL_CMP_MSG *msg, int type);
  854. OSSL_CMP_MSG *ossl_cmp_msg_create(OSSL_CMP_CTX *ctx, int bodytype);
  855. OSSL_CMP_MSG *ossl_cmp_certreq_new(OSSL_CMP_CTX *ctx, int bodytype,
  856. const OSSL_CRMF_MSG *crm);
  857. OSSL_CMP_MSG *ossl_cmp_certrep_new(OSSL_CMP_CTX *ctx, int bodytype,
  858. int certReqId, const OSSL_CMP_PKISI *si,
  859. X509 *cert, const X509 *encryption_recip,
  860. STACK_OF(X509) *chain, STACK_OF(X509) *caPubs,
  861. int unprotectedErrors);
  862. OSSL_CMP_MSG *ossl_cmp_rr_new(OSSL_CMP_CTX *ctx);
  863. OSSL_CMP_MSG *ossl_cmp_rp_new(OSSL_CMP_CTX *ctx, const OSSL_CMP_PKISI *si,
  864. const OSSL_CRMF_CERTID *cid,
  865. int unprotectedErrors);
  866. OSSL_CMP_MSG *ossl_cmp_pkiconf_new(OSSL_CMP_CTX *ctx);
  867. OSSL_CMP_MSG *ossl_cmp_pollRep_new(OSSL_CMP_CTX *ctx, int crid,
  868. int64_t poll_after);
  869. int ossl_cmp_msg_gen_push0_ITAV(OSSL_CMP_MSG *msg, OSSL_CMP_ITAV *itav);
  870. int ossl_cmp_msg_gen_push1_ITAVs(OSSL_CMP_MSG *msg,
  871. const STACK_OF(OSSL_CMP_ITAV) *itavs);
  872. OSSL_CMP_MSG *ossl_cmp_genm_new(OSSL_CMP_CTX *ctx);
  873. OSSL_CMP_MSG *ossl_cmp_genp_new(OSSL_CMP_CTX *ctx,
  874. const STACK_OF(OSSL_CMP_ITAV) *itavs);
  875. OSSL_CMP_MSG *ossl_cmp_error_new(OSSL_CMP_CTX *ctx, const OSSL_CMP_PKISI *si,
  876. int64_t errorCode, const char *details,
  877. int unprotected);
  878. int ossl_cmp_certstatus_set0_certHash(OSSL_CMP_CERTSTATUS *certStatus,
  879. ASN1_OCTET_STRING *hash);
  880. OSSL_CMP_MSG *ossl_cmp_certConf_new(OSSL_CMP_CTX *ctx, int certReqId,
  881. int fail_info, const char *text);
  882. OSSL_CMP_MSG *ossl_cmp_pollReq_new(OSSL_CMP_CTX *ctx, int crid);
  883. OSSL_CMP_MSG *ossl_cmp_pollRep_new(OSSL_CMP_CTX *ctx, int crid,
  884. int64_t poll_after);
  885. OSSL_CMP_PKISI *
  886. ossl_cmp_revrepcontent_get_pkisi(OSSL_CMP_REVREPCONTENT *rrep, int rsid);
  887. OSSL_CRMF_CERTID *ossl_cmp_revrepcontent_get_CertId(OSSL_CMP_REVREPCONTENT *rc,
  888. int rsid);
  889. OSSL_CMP_POLLREP *
  890. ossl_cmp_pollrepcontent_get0_pollrep(const OSSL_CMP_POLLREPCONTENT *prc,
  891. int rid);
  892. OSSL_CMP_CERTRESPONSE *
  893. ossl_cmp_certrepmessage_get0_certresponse(const OSSL_CMP_CERTREPMESSAGE *crm,
  894. int rid);
  895. X509 *ossl_cmp_certresponse_get1_cert(const OSSL_CMP_CTX *ctx,
  896. const OSSL_CMP_CERTRESPONSE *crep);
  897. OSSL_CMP_MSG *ossl_cmp_msg_load(const char *file);
  898. int ossl_cmp_is_error_with_waiting(const OSSL_CMP_MSG *msg);
  899. /* from cmp_protect.c */
  900. int ossl_cmp_msg_add_extraCerts(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg);
  901. ASN1_BIT_STRING *ossl_cmp_calc_protection(const OSSL_CMP_CTX *ctx,
  902. const OSSL_CMP_MSG *msg);
  903. int ossl_cmp_msg_protect(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg);
  904. /* from cmp_vfy.c */
  905. typedef int (*ossl_cmp_allow_unprotected_cb_t)(const OSSL_CMP_CTX *ctx,
  906. const OSSL_CMP_MSG *msg,
  907. int invalid_protection, int arg);
  908. int ossl_cmp_msg_check_update(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg,
  909. ossl_cmp_allow_unprotected_cb_t cb, int cb_arg);
  910. int ossl_cmp_msg_check_received(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg,
  911. ossl_cmp_allow_unprotected_cb_t cb, int cb_arg);
  912. int ossl_cmp_verify_popo(const OSSL_CMP_CTX *ctx,
  913. const OSSL_CMP_MSG *msg, int accept_RAVerified);
  914. /* from cmp_client.c */
  915. /* expected max time per msg round trip, used for last try during polling: */
  916. # define OSSL_CMP_EXPECTED_RESP_TIME 2
  917. int ossl_cmp_exchange_certConf(OSSL_CMP_CTX *ctx, int certReqId,
  918. int fail_info, const char *txt);
  919. int ossl_cmp_exchange_error(OSSL_CMP_CTX *ctx, int status, int fail_info,
  920. const char *txt, int errorCode, const char *detail);
  921. #endif /* !defined(OSSL_CRYPTO_CMP_LOCAL_H) */