cmp_local.h 32 KB

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