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