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