cmp_local.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 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. /*
  23. * this structure is used to store the context for CMP sessions
  24. */
  25. struct ossl_cmp_ctx_st {
  26. OSSL_cmp_log_cb_t log_cb; /* log callback for error/debug/etc. output */
  27. OSSL_CMP_severity log_verbosity; /* level of verbosity of log output */
  28. /* message transfer */
  29. OSSL_cmp_transfer_cb_t transfer_cb; /* default: OSSL_CMP_MSG_http_perform */
  30. void *transfer_cb_arg; /* allows to store optional argument to cb */
  31. /* HTTP-based transfer */
  32. char *serverPath;
  33. char *serverName;
  34. int serverPort;
  35. char *proxyName;
  36. int proxyPort;
  37. int msgtimeout; /* max seconds to wait for each CMP message round trip */
  38. int totaltimeout; /* maximum number seconds an enrollment may take, incl. */
  39. /* attempts polling for a response if a 'waiting' PKIStatus is received */
  40. time_t end_time; /* session start time + totaltimeout */
  41. OSSL_cmp_http_cb_t http_cb;
  42. void *http_cb_arg; /* allows to store optional argument to cb */
  43. /* server authentication */
  44. int unprotectedErrors; /* accept neg. response with no/invalid protection */
  45. /* to cope with broken server */
  46. X509 *srvCert; /* certificate used to identify the server */
  47. X509 *validatedSrvCert; /* caches any already validated server cert */
  48. X509_NAME *expected_sender; /* expected sender in pkiheader of response */
  49. X509_STORE *trusted; /* trust store maybe w CRLs and cert verify callback */
  50. STACK_OF(X509) *untrusted_certs; /* untrusted (intermediate) certs */
  51. int ignore_keyusage; /* ignore key usage entry when validating certs */
  52. int permitTAInExtraCertsForIR; /* allow use of root certs in extracerts */
  53. /* when validating message protection; used for 3GPP-style E.7 */
  54. /* client authentication */
  55. int unprotectedSend; /* send unprotected PKI messages */
  56. X509 *clCert; /* client cert used to identify and sign for MSG_SIG_ALG */
  57. EVP_PKEY *pkey; /* the key pair corresponding to clCert */
  58. ASN1_OCTET_STRING *referenceValue; /* optional user name for MSG_MAC_ALG */
  59. ASN1_OCTET_STRING *secretValue; /* password/shared secret for MSG_MAC_ALG */
  60. /* PBMParameters for MSG_MAC_ALG */
  61. size_t pbm_slen; /* currently fixed to 16 */
  62. int pbm_owf; /* NID of one-way function (OWF), default: SHA256 */
  63. int pbm_itercnt; /* currently fixed to 500 */
  64. int pbm_mac; /* NID of MAC algorithm, default: HMAC-SHA1 as per RFC 4210 */
  65. /* CMP message header and extra certificates */
  66. X509_NAME *recipient; /* to set in recipient in pkiheader */
  67. int digest; /* NID of digest used in MSG_SIG_ALG and POPO, default SHA256 */
  68. ASN1_OCTET_STRING *transactionID; /* the current transaction ID */
  69. ASN1_OCTET_STRING *senderNonce; /* last nonce sent */
  70. ASN1_OCTET_STRING *recipNonce; /* last nonce received */
  71. STACK_OF(OSSL_CMP_ITAV) *geninfo_ITAVs;
  72. int implicitConfirm; /* set implicitConfirm in IR/KUR/CR messages */
  73. int disableConfirm; /* disable certConf in IR/KUR/CR for broken servers */
  74. STACK_OF(X509) *extraCertsOut; /* to be included in request messages */
  75. /* certificate template */
  76. EVP_PKEY *newPkey; /* explicit new private/public key for cert enrollment */
  77. int newPkey_priv; /* flag indicating if newPkey contains private key */
  78. X509_NAME *issuer; /* issuer name to used in cert template */
  79. int days; /* Number of days new certificates are asked to be valid for */
  80. X509_NAME *subjectName; /* subject name to be used in the cert template */
  81. STACK_OF(GENERAL_NAME) *subjectAltNames; /* to add to the cert template */
  82. int SubjectAltName_nodefault;
  83. int setSubjectAltNameCritical;
  84. X509_EXTENSIONS *reqExtensions; /* exts to be added to cert template */
  85. CERTIFICATEPOLICIES *policies; /* policies to be included in extensions */
  86. int setPoliciesCritical;
  87. int popoMethod; /* Proof-of-possession mechanism; default: signature */
  88. X509 *oldCert; /* cert to be updated (via KUR) or to be revoked (via RR) */
  89. X509_REQ *p10CSR; /* for P10CR: PKCS#10 CSR to be sent */
  90. /* misc body contents */
  91. int revocationReason; /* revocation reason code to be included in RR */
  92. STACK_OF(OSSL_CMP_ITAV) *genm_ITAVs; /* content of general message */
  93. /* result returned in responses */
  94. int status; /* PKIStatus of last received IP/CP/KUP/RP/error or -1 */
  95. /* TODO: this should be a stack since there could be more than one */
  96. OSSL_CMP_PKIFREETEXT *statusString; /* of last IP/CP/KUP/RP/error */
  97. int failInfoCode; /* failInfoCode of last received IP/CP/KUP/error, or -1 */
  98. /* TODO: this should be a stack since there could be more than one */
  99. X509 *newCert; /* newly enrolled cert received from the CA */
  100. /* TODO: this should be a stack since there could be more than one */
  101. STACK_OF(X509) *caPubs; /* CA certs received from server (in IP message) */
  102. STACK_OF(X509) *extraCertsIn; /* extraCerts received from server */
  103. /* certificate confirmation */
  104. OSSL_cmp_certConf_cb_t certConf_cb; /* callback for app checking new cert */
  105. void *certConf_cb_arg; /* allows to store an argument individual to cb */
  106. } /* OSSL_CMP_CTX */;
  107. /*
  108. * ##########################################################################
  109. * ASN.1 DECLARATIONS
  110. * ##########################################################################
  111. */
  112. /*-
  113. * RevAnnContent ::= SEQUENCE {
  114. * status PKIStatus,
  115. * certId CertId,
  116. * willBeRevokedAt GeneralizedTime,
  117. * badSinceDate GeneralizedTime,
  118. * crlDetails Extensions OPTIONAL
  119. * -- extra CRL details (e.g., crl number, reason, location, etc.)
  120. * }
  121. */
  122. typedef struct ossl_cmp_revanncontent_st {
  123. ASN1_INTEGER *status;
  124. OSSL_CRMF_CERTID *certId;
  125. ASN1_GENERALIZEDTIME *willBeRevokedAt;
  126. ASN1_GENERALIZEDTIME *badSinceDate;
  127. X509_EXTENSIONS *crlDetails;
  128. } OSSL_CMP_REVANNCONTENT;
  129. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVANNCONTENT)
  130. /*-
  131. * Challenge ::= SEQUENCE {
  132. * owf AlgorithmIdentifier OPTIONAL,
  133. *
  134. * -- MUST be present in the first Challenge; MAY be omitted in
  135. * -- any subsequent Challenge in POPODecKeyChallContent (if
  136. * -- omitted, then the owf used in the immediately preceding
  137. * -- Challenge is to be used).
  138. *
  139. * witness OCTET STRING,
  140. * -- the result of applying the one-way function (owf) to a
  141. * -- randomly-generated INTEGER, A. [Note that a different
  142. * -- INTEGER MUST be used for each Challenge.]
  143. * challenge OCTET STRING
  144. * -- the encryption (under the public key for which the cert.
  145. * -- request is being made) of Rand, where Rand is specified as
  146. * -- Rand ::= SEQUENCE {
  147. * -- int INTEGER,
  148. * -- - the randomly-generated INTEGER A (above)
  149. * -- sender GeneralName
  150. * -- - the sender's name (as included in PKIHeader)
  151. * -- }
  152. * }
  153. */
  154. typedef struct ossl_cmp_challenge_st {
  155. X509_ALGOR *owf;
  156. ASN1_OCTET_STRING *witness;
  157. ASN1_OCTET_STRING *challenge;
  158. } OSSL_CMP_CHALLENGE;
  159. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CHALLENGE)
  160. /*-
  161. * CAKeyUpdAnnContent ::= SEQUENCE {
  162. * oldWithNew Certificate,
  163. * newWithOld Certificate,
  164. * newWithNew Certificate
  165. * }
  166. */
  167. typedef struct ossl_cmp_cakeyupdanncontent_st {
  168. X509 *oldWithNew;
  169. X509 *newWithOld;
  170. X509 *newWithNew;
  171. } OSSL_CMP_CAKEYUPDANNCONTENT;
  172. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CAKEYUPDANNCONTENT)
  173. /*-
  174. * declared already here as it will be used in OSSL_CMP_MSG (nested) and
  175. * infoType and infoValue
  176. */
  177. typedef STACK_OF(OSSL_CMP_MSG) OSSL_CMP_MSGS;
  178. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_MSGS)
  179. /*-
  180. * InfoTypeAndValue ::= SEQUENCE {
  181. * infoType OBJECT IDENTIFIER,
  182. * infoValue ANY DEFINED BY infoType OPTIONAL
  183. * }
  184. */
  185. struct ossl_cmp_itav_st {
  186. ASN1_OBJECT *infoType;
  187. union {
  188. char *ptr;
  189. /* NID_id_it_caProtEncCert - CA Protocol Encryption Certificate */
  190. X509 *caProtEncCert;
  191. /* NID_id_it_signKeyPairTypes - Signing Key Pair Types */
  192. STACK_OF(X509_ALGOR) *signKeyPairTypes;
  193. /* NID_id_it_encKeyPairTypes - Encryption/Key Agreement Key Pair Types */
  194. STACK_OF(X509_ALGOR) *encKeyPairTypes;
  195. /* NID_id_it_preferredSymmAlg - Preferred Symmetric Algorithm */
  196. X509_ALGOR *preferredSymmAlg;
  197. /* NID_id_it_caKeyUpdateInfo - Updated CA Key Pair */
  198. OSSL_CMP_CAKEYUPDANNCONTENT *caKeyUpdateInfo;
  199. /* NID_id_it_currentCRL - CRL */
  200. X509_CRL *currentCRL;
  201. /* NID_id_it_unsupportedOIDs - Unsupported Object Identifiers */
  202. STACK_OF(ASN1_OBJECT) *unsupportedOIDs;
  203. /* NID_id_it_keyPairParamReq - Key Pair Parameters Request */
  204. ASN1_OBJECT *keyPairParamReq;
  205. /* NID_id_it_keyPairParamRep - Key Pair Parameters Response */
  206. X509_ALGOR *keyPairParamRep;
  207. /* NID_id_it_revPassphrase - Revocation Passphrase */
  208. OSSL_CRMF_ENCRYPTEDVALUE *revPassphrase;
  209. /* NID_id_it_implicitConfirm - ImplicitConfirm */
  210. ASN1_NULL *implicitConfirm;
  211. /* NID_id_it_confirmWaitTime - ConfirmWaitTime */
  212. ASN1_GENERALIZEDTIME *confirmWaitTime;
  213. /* NID_id_it_origPKIMessage - origPKIMessage */
  214. OSSL_CMP_MSGS *origPKIMessage;
  215. /* NID_id_it_suppLangTags - Supported Language Tags */
  216. STACK_OF(ASN1_UTF8STRING) *suppLangTagsValue;
  217. /* this is to be used for so far undeclared objects */
  218. ASN1_TYPE *other;
  219. } infoValue;
  220. } /* OSSL_CMP_ITAV */;
  221. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ITAV)
  222. DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_ITAV)
  223. typedef struct ossl_cmp_certorenccert_st {
  224. int type;
  225. union {
  226. X509 *certificate;
  227. OSSL_CRMF_ENCRYPTEDVALUE *encryptedCert;
  228. } value;
  229. } OSSL_CMP_CERTORENCCERT;
  230. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTORENCCERT)
  231. /*-
  232. * CertifiedKeyPair ::= SEQUENCE {
  233. * certOrEncCert CertOrEncCert,
  234. * privateKey [0] EncryptedValue OPTIONAL,
  235. * -- see [CRMF] for comment on encoding
  236. * publicationInfo [1] PKIPublicationInfo OPTIONAL
  237. * }
  238. */
  239. typedef struct ossl_cmp_certifiedkeypair_st {
  240. OSSL_CMP_CERTORENCCERT *certOrEncCert;
  241. OSSL_CRMF_ENCRYPTEDVALUE *privateKey;
  242. OSSL_CRMF_PKIPUBLICATIONINFO *publicationInfo;
  243. } OSSL_CMP_CERTIFIEDKEYPAIR;
  244. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTIFIEDKEYPAIR)
  245. /*-
  246. * PKIStatusInfo ::= SEQUENCE {
  247. * status PKIStatus,
  248. * statusString PKIFreeText OPTIONAL,
  249. * failInfo PKIFailureInfo OPTIONAL
  250. * }
  251. */
  252. struct ossl_cmp_pkisi_st {
  253. OSSL_CMP_PKISTATUS *status;
  254. OSSL_CMP_PKIFREETEXT *statusString;
  255. OSSL_CMP_PKIFAILUREINFO *failInfo;
  256. } /* OSSL_CMP_PKISI */;
  257. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKISI)
  258. DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI)
  259. /*-
  260. * RevReqContent ::= SEQUENCE OF RevDetails
  261. *
  262. * RevDetails ::= SEQUENCE {
  263. * certDetails CertTemplate,
  264. * crlEntryDetails Extensions OPTIONAL
  265. * }
  266. */
  267. typedef struct ossl_cmp_revdetails_st {
  268. OSSL_CRMF_CERTTEMPLATE *certDetails;
  269. X509_EXTENSIONS *crlEntryDetails;
  270. } OSSL_CMP_REVDETAILS;
  271. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVDETAILS)
  272. DEFINE_STACK_OF(OSSL_CMP_REVDETAILS)
  273. /*-
  274. * RevRepContent ::= SEQUENCE {
  275. * status SEQUENCE SIZE (1..MAX) OF PKIStatusInfo,
  276. * -- in same order as was sent in RevReqContent
  277. * revCerts [0] SEQUENCE SIZE (1..MAX) OF CertId
  278. * OPTIONAL,
  279. * -- IDs for which revocation was requested
  280. * -- (same order as status)
  281. * crls [1] SEQUENCE SIZE (1..MAX) OF CertificateList
  282. * OPTIONAL
  283. * -- the resulting CRLs (there may be more than one)
  284. * }
  285. */
  286. struct ossl_cmp_revrepcontent_st {
  287. STACK_OF(OSSL_CMP_PKISI) *status;
  288. STACK_OF(OSSL_CRMF_CERTID) *revCerts;
  289. STACK_OF(X509_CRL) *crls;
  290. } /* OSSL_CMP_REVREPCONTENT */;
  291. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVREPCONTENT)
  292. /*-
  293. * KeyRecRepContent ::= SEQUENCE {
  294. * status PKIStatusInfo,
  295. * newSigCert [0] Certificate OPTIONAL,
  296. * caCerts [1] SEQUENCE SIZE (1..MAX) OF
  297. * Certificate OPTIONAL,
  298. * keyPairHist [2] SEQUENCE SIZE (1..MAX) OF
  299. * CertifiedKeyPair OPTIONAL
  300. * }
  301. */
  302. typedef struct ossl_cmp_keyrecrepcontent_st {
  303. OSSL_CMP_PKISI *status;
  304. X509 *newSigCert;
  305. STACK_OF(X509) *caCerts;
  306. STACK_OF(OSSL_CMP_CERTIFIEDKEYPAIR) *keyPairHist;
  307. } OSSL_CMP_KEYRECREPCONTENT;
  308. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_KEYRECREPCONTENT)
  309. /*-
  310. * ErrorMsgContent ::= SEQUENCE {
  311. * pKIStatusInfo PKIStatusInfo,
  312. * errorCode INTEGER OPTIONAL,
  313. * -- implementation-specific error codes
  314. * errorDetails PKIFreeText OPTIONAL
  315. * -- implementation-specific error details
  316. * }
  317. */
  318. typedef struct ossl_cmp_errormsgcontent_st {
  319. OSSL_CMP_PKISI *pKIStatusInfo;
  320. ASN1_INTEGER *errorCode;
  321. OSSL_CMP_PKIFREETEXT *errorDetails;
  322. } OSSL_CMP_ERRORMSGCONTENT;
  323. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ERRORMSGCONTENT)
  324. /*-
  325. * CertConfirmContent ::= SEQUENCE OF CertStatus
  326. *
  327. * CertStatus ::= SEQUENCE {
  328. * certHash OCTET STRING,
  329. * -- the hash of the certificate, using the same hash algorithm
  330. * -- as is used to create and verify the certificate signature
  331. * certReqId INTEGER,
  332. * -- to match this confirmation with the corresponding req/rep
  333. * statusInfo PKIStatusInfo OPTIONAL
  334. * }
  335. */
  336. struct ossl_cmp_certstatus_st {
  337. ASN1_OCTET_STRING *certHash;
  338. ASN1_INTEGER *certReqId;
  339. OSSL_CMP_PKISI *statusInfo;
  340. } /* OSSL_CMP_CERTSTATUS */;
  341. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTSTATUS)
  342. typedef STACK_OF(OSSL_CMP_CERTSTATUS) OSSL_CMP_CERTCONFIRMCONTENT;
  343. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTCONFIRMCONTENT)
  344. /*-
  345. * CertResponse ::= SEQUENCE {
  346. * certReqId INTEGER,
  347. * -- to match this response with corresponding request (a value
  348. * -- of -1 is to be used if certReqId is not specified in the
  349. * -- corresponding request)
  350. * status PKIStatusInfo,
  351. * certifiedKeyPair CertifiedKeyPair OPTIONAL,
  352. * rspInfo OCTET STRING OPTIONAL
  353. * -- analogous to the id-regInfo-utf8Pairs string defined
  354. * -- for regInfo in CertReqMsg [CRMF]
  355. * }
  356. */
  357. struct ossl_cmp_certresponse_st {
  358. ASN1_INTEGER *certReqId;
  359. OSSL_CMP_PKISI *status;
  360. OSSL_CMP_CERTIFIEDKEYPAIR *certifiedKeyPair;
  361. ASN1_OCTET_STRING *rspInfo;
  362. } /* OSSL_CMP_CERTRESPONSE */;
  363. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTRESPONSE)
  364. /*-
  365. * CertRepMessage ::= SEQUENCE {
  366. * caPubs [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
  367. * OPTIONAL,
  368. * response SEQUENCE OF CertResponse
  369. * }
  370. */
  371. struct ossl_cmp_certrepmessage_st {
  372. STACK_OF(X509) *caPubs;
  373. STACK_OF(OSSL_CMP_CERTRESPONSE) *response;
  374. } /* OSSL_CMP_CERTREPMESSAGE */;
  375. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTREPMESSAGE)
  376. /*-
  377. * PollReqContent ::= SEQUENCE OF SEQUENCE {
  378. * certReqId INTEGER
  379. * }
  380. */
  381. typedef struct ossl_cmp_pollreq_st {
  382. ASN1_INTEGER *certReqId;
  383. } OSSL_CMP_POLLREQ;
  384. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREQ)
  385. DEFINE_STACK_OF(OSSL_CMP_POLLREQ)
  386. typedef STACK_OF(OSSL_CMP_POLLREQ) OSSL_CMP_POLLREQCONTENT;
  387. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREQCONTENT)
  388. /*-
  389. * PollRepContent ::= SEQUENCE OF SEQUENCE {
  390. * certReqId INTEGER,
  391. * checkAfter INTEGER, -- time in seconds
  392. * reason PKIFreeText OPTIONAL
  393. * }
  394. */
  395. struct ossl_cmp_pollrep_st {
  396. ASN1_INTEGER *certReqId;
  397. ASN1_INTEGER *checkAfter;
  398. OSSL_CMP_PKIFREETEXT *reason;
  399. } /* OSSL_CMP_POLLREP */;
  400. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREP)
  401. DEFINE_STACK_OF(OSSL_CMP_POLLREP)
  402. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREPCONTENT)
  403. /*-
  404. * PKIHeader ::= SEQUENCE {
  405. * pvno INTEGER { cmp1999(1), cmp2000(2) },
  406. * sender GeneralName,
  407. * -- identifies the sender
  408. * recipient GeneralName,
  409. * -- identifies the intended recipient
  410. * messageTime [0] GeneralizedTime OPTIONAL,
  411. * -- time of production of this message (used when sender
  412. * -- believes that the transport will be "suitable"; i.e.,
  413. * -- that the time will still be meaningful upon receipt)
  414. * protectionAlg [1] AlgorithmIdentifier OPTIONAL,
  415. * -- algorithm used for calculation of protection bits
  416. * senderKID [2] KeyIdentifier OPTIONAL,
  417. * recipKID [3] KeyIdentifier OPTIONAL,
  418. * -- to identify specific keys used for protection
  419. * transactionID [4] OCTET STRING OPTIONAL,
  420. * -- identifies the transaction; i.e., this will be the same in
  421. * -- corresponding request, response, certConf, and PKIConf
  422. * -- messages
  423. * senderNonce [5] OCTET STRING OPTIONAL,
  424. * recipNonce [6] OCTET STRING OPTIONAL,
  425. * -- nonces used to provide replay protection, senderNonce
  426. * -- is inserted by the creator of this message; recipNonce
  427. * -- is a nonce previously inserted in a related message by
  428. * -- the intended recipient of this message
  429. * freeText [7] PKIFreeText OPTIONAL,
  430. * -- this may be used to indicate context-specific instructions
  431. * -- (this field is intended for human consumption)
  432. * generalInfo [8] SEQUENCE SIZE (1..MAX) OF
  433. * InfoTypeAndValue OPTIONAL
  434. * -- this may be used to convey context-specific information
  435. * -- (this field not primarily intended for human consumption)
  436. * }
  437. */
  438. struct ossl_cmp_pkiheader_st {
  439. ASN1_INTEGER *pvno;
  440. GENERAL_NAME *sender;
  441. GENERAL_NAME *recipient;
  442. ASN1_GENERALIZEDTIME *messageTime; /* 0 */
  443. X509_ALGOR *protectionAlg; /* 1 */
  444. ASN1_OCTET_STRING *senderKID; /* 2 */
  445. ASN1_OCTET_STRING *recipKID; /* 3 */
  446. ASN1_OCTET_STRING *transactionID; /* 4 */
  447. ASN1_OCTET_STRING *senderNonce; /* 5 */
  448. ASN1_OCTET_STRING *recipNonce; /* 6 */
  449. OSSL_CMP_PKIFREETEXT *freeText; /* 7 */
  450. STACK_OF(OSSL_CMP_ITAV) *generalInfo; /* 8 */
  451. } /* OSSL_CMP_PKIHEADER */;
  452. typedef STACK_OF(OSSL_CMP_CHALLENGE) OSSL_CMP_POPODECKEYCHALLCONTENT;
  453. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POPODECKEYCHALLCONTENT)
  454. typedef STACK_OF(ASN1_INTEGER) OSSL_CMP_POPODECKEYRESPCONTENT;
  455. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POPODECKEYRESPCONTENT)
  456. typedef STACK_OF(OSSL_CMP_REVDETAILS) OSSL_CMP_REVREQCONTENT;
  457. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVREQCONTENT)
  458. typedef STACK_OF(X509_CRL) OSSL_CMP_CRLANNCONTENT;
  459. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CRLANNCONTENT)
  460. typedef STACK_OF(OSSL_CMP_ITAV) OSSL_CMP_GENMSGCONTENT;
  461. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_GENMSGCONTENT)
  462. typedef STACK_OF(OSSL_CMP_ITAV) OSSL_CMP_GENREPCONTENT;
  463. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_GENREPCONTENT)
  464. /*-
  465. * PKIBody ::= CHOICE { -- message-specific body elements
  466. * ir [0] CertReqMessages, --Initialization Request
  467. * ip [1] CertRepMessage, --Initialization Response
  468. * cr [2] CertReqMessages, --Certification Request
  469. * cp [3] CertRepMessage, --Certification Response
  470. * p10cr [4] CertificationRequest, --imported from [PKCS10]
  471. * popdecc [5] POPODecKeyChallContent, --pop Challenge
  472. * popdecr [6] POPODecKeyRespContent, --pop Response
  473. * kur [7] CertReqMessages, --Key Update Request
  474. * kup [8] CertRepMessage, --Key Update Response
  475. * krr [9] CertReqMessages, --Key Recovery Request
  476. * krp [10] KeyRecRepContent, --Key Recovery Response
  477. * rr [11] RevReqContent, --Revocation Request
  478. * rp [12] RevRepContent, --Revocation Response
  479. * ccr [13] CertReqMessages, --Cross-Cert. Request
  480. * ccp [14] CertRepMessage, --Cross-Cert. Response
  481. * ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
  482. * cann [16] CertAnnContent, --Certificate Ann.
  483. * rann [17] RevAnnContent, --Revocation Ann.
  484. * crlann [18] CRLAnnContent, --CRL Announcement
  485. * pkiconf [19] PKIConfirmContent, --Confirmation
  486. * nested [20] NestedMessageContent, --Nested Message
  487. * genm [21] GenMsgContent, --General Message
  488. * genp [22] GenRepContent, --General Response
  489. * error [23] ErrorMsgContent, --Error Message
  490. * certConf [24] CertConfirmContent, --Certificate confirm
  491. * pollReq [25] PollReqContent, --Polling request
  492. * pollRep [26] PollRepContent --Polling response
  493. */
  494. typedef struct ossl_cmp_pkibody_st {
  495. int type;
  496. union {
  497. OSSL_CRMF_MSGS *ir; /* 0 */
  498. OSSL_CMP_CERTREPMESSAGE *ip; /* 1 */
  499. OSSL_CRMF_MSGS *cr; /* 2 */
  500. OSSL_CMP_CERTREPMESSAGE *cp; /* 3 */
  501. /* p10cr [4] CertificationRequest, --imported from [PKCS10] */
  502. /*
  503. * PKCS10_CERTIFICATIONREQUEST is effectively X509_REQ
  504. * so it is used directly
  505. */
  506. X509_REQ *p10cr; /* 4 */
  507. /* popdecc [5] POPODecKeyChallContent, --pop Challenge */
  508. /* POPODecKeyChallContent ::= SEQUENCE OF Challenge */
  509. OSSL_CMP_POPODECKEYCHALLCONTENT *popdecc; /* 5 */
  510. /* popdecr [6] POPODecKeyRespContent, --pop Response */
  511. /* POPODecKeyRespContent ::= SEQUENCE OF INTEGER */
  512. OSSL_CMP_POPODECKEYRESPCONTENT *popdecr; /* 6 */
  513. OSSL_CRMF_MSGS *kur; /* 7 */
  514. OSSL_CMP_CERTREPMESSAGE *kup; /* 8 */
  515. OSSL_CRMF_MSGS *krr; /* 9 */
  516. /* krp [10] KeyRecRepContent, --Key Recovery Response */
  517. OSSL_CMP_KEYRECREPCONTENT *krp; /* 10 */
  518. /* rr [11] RevReqContent, --Revocation Request */
  519. OSSL_CMP_REVREQCONTENT *rr; /* 11 */
  520. /* rp [12] RevRepContent, --Revocation Response */
  521. OSSL_CMP_REVREPCONTENT *rp; /* 12 */
  522. /* ccr [13] CertReqMessages, --Cross-Cert. Request */
  523. OSSL_CRMF_MSGS *ccr; /* 13 */
  524. /* ccp [14] CertRepMessage, --Cross-Cert. Response */
  525. OSSL_CMP_CERTREPMESSAGE *ccp; /* 14 */
  526. /* ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann. */
  527. OSSL_CMP_CAKEYUPDANNCONTENT *ckuann; /* 15 */
  528. /* cann [16] CertAnnContent, --Certificate Ann. */
  529. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  530. X509 *cann; /* 16 */
  531. /* rann [17] RevAnnContent, --Revocation Ann. */
  532. OSSL_CMP_REVANNCONTENT *rann; /* 17 */
  533. /* crlann [18] CRLAnnContent, --CRL Announcement */
  534. /* CRLAnnContent ::= SEQUENCE OF CertificateList */
  535. OSSL_CMP_CRLANNCONTENT *crlann;
  536. /* PKIConfirmContent ::= NULL */
  537. /* pkiconf [19] PKIConfirmContent, --Confirmation */
  538. /* OSSL_CMP_PKICONFIRMCONTENT would be only a typedef of ASN1_NULL */
  539. /* OSSL_CMP_CONFIRMCONTENT *pkiconf; */
  540. /*
  541. * NOTE: this should ASN1_NULL according to the RFC
  542. * but there might be a struct in it when sent from faulty servers...
  543. */
  544. ASN1_TYPE *pkiconf; /* 19 */
  545. /* nested [20] NestedMessageContent, --Nested Message */
  546. /* NestedMessageContent ::= PKIMessages */
  547. OSSL_CMP_MSGS *nested; /* 20 */
  548. /* genm [21] GenMsgContent, --General Message */
  549. /* GenMsgContent ::= SEQUENCE OF InfoTypeAndValue */
  550. OSSL_CMP_GENMSGCONTENT *genm; /* 21 */
  551. /* genp [22] GenRepContent, --General Response */
  552. /* GenRepContent ::= SEQUENCE OF InfoTypeAndValue */
  553. OSSL_CMP_GENREPCONTENT *genp; /* 22 */
  554. /* error [23] ErrorMsgContent, --Error Message */
  555. OSSL_CMP_ERRORMSGCONTENT *error; /* 23 */
  556. /* certConf [24] CertConfirmContent, --Certificate confirm */
  557. OSSL_CMP_CERTCONFIRMCONTENT *certConf; /* 24 */
  558. /* pollReq [25] PollReqContent, --Polling request */
  559. OSSL_CMP_POLLREQCONTENT *pollReq;
  560. /* pollRep [26] PollRepContent --Polling response */
  561. OSSL_CMP_POLLREPCONTENT *pollRep;
  562. } value;
  563. } OSSL_CMP_PKIBODY;
  564. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKIBODY)
  565. /*-
  566. * PKIProtection ::= BIT STRING
  567. *
  568. * PKIMessages ::= SEQUENCE SIZE (1..MAX) OF PKIMessage
  569. *
  570. * PKIMessage ::= SEQUENCE {
  571. * header PKIHeader,
  572. * body PKIBody,
  573. * protection [0] PKIProtection OPTIONAL,
  574. * extraCerts [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
  575. * OPTIONAL
  576. * }
  577. */
  578. struct ossl_cmp_msg_st {
  579. OSSL_CMP_PKIHEADER *header;
  580. OSSL_CMP_PKIBODY *body;
  581. ASN1_BIT_STRING *protection; /* 0 */
  582. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  583. STACK_OF(X509) *extraCerts; /* 1 */
  584. } /* OSSL_CMP_MSG */;
  585. DECLARE_ASN1_FUNCTIONS(OSSL_CMP_MSG)
  586. DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_MSG)
  587. /*-
  588. * ProtectedPart ::= SEQUENCE {
  589. * header PKIHeader,
  590. * body PKIBody
  591. * }
  592. */
  593. typedef struct cmp_protectedpart_st {
  594. OSSL_CMP_PKIHEADER *header;
  595. OSSL_CMP_PKIBODY *body;
  596. } CMP_PROTECTEDPART;
  597. DECLARE_ASN1_FUNCTIONS(CMP_PROTECTEDPART)
  598. /*-
  599. * this is not defined here as it is already in CRMF:
  600. * id-PasswordBasedMac OBJECT IDENTIFIER ::= {1 2 840 113533 7 66 13}
  601. * PBMParameter ::= SEQUENCE {
  602. * salt OCTET STRING,
  603. * -- note: implementations MAY wish to limit acceptable sizes
  604. * -- of this string to values appropriate for their environment
  605. * -- in order to reduce the risk of denial-of-service attacks
  606. * owf AlgorithmIdentifier,
  607. * -- AlgId for a One-Way Function (SHA-1 recommended)
  608. * iterationCount INTEGER,
  609. * -- number of times the OWF is applied
  610. * -- note: implementations MAY wish to limit acceptable sizes
  611. * -- of this integer to values appropriate for their environment
  612. * -- in order to reduce the risk of denial-of-service attacks
  613. * mac AlgorithmIdentifier
  614. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  615. * } -- or HMAC [RFC2104, RFC2202])
  616. */
  617. /*-
  618. * TODO: this is not yet defined here - but DH is anyway not used yet
  619. *
  620. * id-DHBasedMac OBJECT IDENTIFIER ::= {1 2 840 113533 7 66 30}
  621. * DHBMParameter ::= SEQUENCE {
  622. * owf AlgorithmIdentifier,
  623. * -- AlgId for a One-Way Function (SHA-1 recommended)
  624. * mac AlgorithmIdentifier
  625. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  626. * } -- or HMAC [RFC2104, RFC2202])
  627. */
  628. /*-
  629. * The following is not cared for, because it is described in section 5.2.5
  630. * that this is beyond the scope of CMP
  631. * OOBCert ::= CMPCertificate
  632. *
  633. * OOBCertHash ::= SEQUENCE {
  634. * hashAlg [0] AlgorithmIdentifier OPTIONAL,
  635. * certId [1] CertId OPTIONAL,
  636. * hashVal BIT STRING
  637. * -- hashVal is calculated over the DER encoding of the
  638. * -- self-signed certificate with the identifier certID.
  639. * }
  640. */
  641. /*
  642. * functions
  643. */
  644. /* from cmp_asn.c */
  645. int ossl_cmp_asn1_get_int(const ASN1_INTEGER *a);
  646. /* from cmp_util.c */
  647. const char *ossl_cmp_log_parse_metadata(const char *buf,
  648. OSSL_CMP_severity *level, char **func,
  649. char **file, int *line);
  650. /* workaround for 4096 bytes limitation of ERR_print_errors_cb() */
  651. void ossl_cmp_add_error_txt(const char *separator, const char *txt);
  652. # define ossl_cmp_add_error_data(txt) ossl_cmp_add_error_txt(" : ", txt)
  653. # define ossl_cmp_add_error_line(txt) ossl_cmp_add_error_txt("\n", txt)
  654. /* functions manipulating lists of certificates etc could be generally useful */
  655. int ossl_cmp_sk_X509_add1_cert (STACK_OF(X509) *sk, X509 *cert,
  656. int no_dup, int prepend);
  657. int ossl_cmp_sk_X509_add1_certs(STACK_OF(X509) *sk, STACK_OF(X509) *certs,
  658. int no_self_signed, int no_dups, int prepend);
  659. int ossl_cmp_X509_STORE_add1_certs(X509_STORE *store, STACK_OF(X509) *certs,
  660. int only_self_signed);
  661. STACK_OF(X509) *ossl_cmp_X509_STORE_get1_certs(X509_STORE *store);
  662. int ossl_cmp_asn1_octet_string_set1(ASN1_OCTET_STRING **tgt,
  663. const ASN1_OCTET_STRING *src);
  664. int ossl_cmp_asn1_octet_string_set1_bytes(ASN1_OCTET_STRING **tgt,
  665. const unsigned char *bytes, int len);
  666. STACK_OF(X509) *ossl_cmp_build_cert_chain(STACK_OF(X509) *certs, X509 *cert);
  667. /* from cmp_ctx.c */
  668. int ossl_cmp_ctx_set0_validatedSrvCert(OSSL_CMP_CTX *ctx, X509 *cert);
  669. int ossl_cmp_ctx_set_status(OSSL_CMP_CTX *ctx, int status);
  670. int ossl_cmp_ctx_set0_statusString(OSSL_CMP_CTX *ctx,
  671. OSSL_CMP_PKIFREETEXT *text);
  672. int ossl_cmp_ctx_set_failInfoCode(OSSL_CMP_CTX *ctx, int fail_info);
  673. int ossl_cmp_ctx_set0_newCert(OSSL_CMP_CTX *ctx, X509 *cert);
  674. int ossl_cmp_ctx_set1_caPubs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *caPubs);
  675. int ossl_cmp_ctx_set1_extraCertsIn(OSSL_CMP_CTX *ctx,
  676. STACK_OF(X509) *extraCertsIn);
  677. int ossl_cmp_ctx_set1_recipNonce(OSSL_CMP_CTX *ctx,
  678. const ASN1_OCTET_STRING *nonce);
  679. # define OSSL_CMP_TRANSACTIONID_LENGTH 16
  680. #endif /* !defined OSSL_CRYPTO_CMP_LOCAL_H */