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