Move decl of OSSL_CRMF_CERTID_dup from {crmf,cmp}_local.h to include/openssl/crmf.h
[oweals/openssl.git] / crypto / crmf / crmf_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  * CRMF implementation by Martin Peylo, Miikka Viljanen, and David von Oheimb.
12  */
13
14 #ifndef OSSL_CRYPTO_CRMF_LOCAL_H
15 # define OSSL_CRYPTO_CRMF_LOCAL_H
16
17 # include <openssl/crmf.h>
18 # include <openssl/err.h>
19
20 /* explicit #includes not strictly needed since implied by the above: */
21 # include <openssl/types.h>
22 # include <openssl/safestack.h>
23 # include <openssl/x509.h>
24 # include <openssl/x509v3.h>
25
26 /*-
27  * EncryptedValue ::= SEQUENCE {
28  * intendedAlg   [0] AlgorithmIdentifier  OPTIONAL,
29  *                  -- the intended algorithm for which the value will be used
30  * symmAlg       [1] AlgorithmIdentifier  OPTIONAL,
31  *                  -- the symmetric algorithm used to encrypt the value
32  * encSymmKey    [2] BIT STRING           OPTIONAL,
33  *                  -- the (encrypted) symmetric key used to encrypt the value
34  * keyAlg        [3] AlgorithmIdentifier  OPTIONAL,
35  *                  -- algorithm used to encrypt the symmetric key
36  * valueHint     [4] OCTET STRING         OPTIONAL,
37  *                  -- a brief description or identifier of the encValue content
38  *                  -- (may be meaningful only to the sending entity, and
39  *                  --  used only if EncryptedValue might be re-examined
40  *                  --  by the sending entity in the future)
41  * encValue      BIT STRING
42  *                  -- the encrypted value itself
43  * }
44  */
45 struct ossl_crmf_encryptedvalue_st {
46     X509_ALGOR *intendedAlg;      /* 0 */
47     X509_ALGOR *symmAlg;          /* 1 */
48     ASN1_BIT_STRING *encSymmKey;  /* 2 */
49     X509_ALGOR *keyAlg;           /* 3 */
50     ASN1_OCTET_STRING *valueHint; /* 4 */
51     ASN1_BIT_STRING *encValue;
52 } /* OSSL_CRMF_ENCRYPTEDVALUE */;
53
54 /*-
55  *  Attributes ::= SET OF Attribute
56  *  => X509_ATTRIBUTE
57  *
58  *  PrivateKeyInfo ::= SEQUENCE {
59  *     version                       INTEGER,
60  *     privateKeyAlgorithm           AlgorithmIdentifier,
61  *     privateKey                    OCTET STRING,
62  *     attributes                    [0] IMPLICIT Attributes OPTIONAL
63  *  }
64  */
65 typedef struct ossl_crmf_privatekeyinfo_st {
66     ASN1_INTEGER *version;
67     X509_ALGOR *privateKeyAlgorithm;
68     ASN1_OCTET_STRING *privateKey;
69     STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
70 } OSSL_CRMF_PRIVATEKEYINFO;
71 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PRIVATEKEYINFO)
72
73 /*-
74  * section 4.2.1 Private Key Info Content Type
75  * id-ct-encKeyWithID OBJECT IDENTIFIER ::= {id-ct 21}
76  *
77  * EncKeyWithID ::= SEQUENCE {
78  * privateKey     PrivateKeyInfo,
79  * identifier     CHOICE {
80  *                      string         UTF8String,
81  *                      generalName    GeneralName
82  *                } OPTIONAL
83  * }
84  */
85 typedef struct ossl_crmf_enckeywithid_identifier_st {
86     int type;
87     union {
88         ASN1_UTF8STRING *string;
89         GENERAL_NAME *generalName;
90     } value;
91 } OSSL_CRMF_ENCKEYWITHID_IDENTIFIER;
92 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER)
93
94 typedef struct ossl_crmf_enckeywithid_st {
95     OSSL_CRMF_PRIVATEKEYINFO *privateKey;
96     /* [0] */
97     OSSL_CRMF_ENCKEYWITHID_IDENTIFIER *identifier;
98 } OSSL_CRMF_ENCKEYWITHID;
99 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID)
100
101 /*-
102  * CertId ::= SEQUENCE {
103  *      issuer           GeneralName,
104  *      serialNumber     INTEGER
105  * }
106  */
107 struct ossl_crmf_certid_st {
108     GENERAL_NAME *issuer;
109     ASN1_INTEGER *serialNumber;
110 } /* OSSL_CRMF_CERTID */;
111
112 /*-
113  * SinglePubInfo ::= SEQUENCE {
114  *  pubMethod        INTEGER {
115  *      dontCare        (0),
116  *      x500            (1),
117  *      web             (2),
118  *      ldap            (3) },
119  *  pubLocation  GeneralName OPTIONAL
120  * }
121  */
122 struct ossl_crmf_singlepubinfo_st {
123     ASN1_INTEGER *pubMethod;
124     GENERAL_NAME *pubLocation;
125 } /* OSSL_CRMF_SINGLEPUBINFO */;
126 DEFINE_STACK_OF(OSSL_CRMF_SINGLEPUBINFO)
127 typedef STACK_OF(OSSL_CRMF_SINGLEPUBINFO) OSSL_CRMF_PUBINFOS;
128
129
130 /*-
131  * PKIPublicationInfo ::= SEQUENCE {
132  *      action     INTEGER {
133  *                   dontPublish (0),
134  *                   pleasePublish (1) },
135  *      pubInfos   SEQUENCE SIZE (1..MAX) OF SinglePubInfo OPTIONAL
136  *      -- pubInfos MUST NOT be present if action is "dontPublish"
137  *      -- (if action is "pleasePublish" and pubInfos is omitted,
138  *      -- "dontCare" is assumed)
139  * }
140  */
141 struct ossl_crmf_pkipublicationinfo_st {
142     ASN1_INTEGER *action;
143     OSSL_CRMF_PUBINFOS *pubInfos;
144 } /* OSSL_CRMF_PKIPUBLICATIONINFO */;
145 DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_PKIPUBLICATIONINFO)
146
147 /*-
148  * PKMACValue ::= SEQUENCE {
149  * algId  AlgorithmIdentifier,
150  * -- algorithm value shall be PasswordBasedMac {1 2 840 113533 7 66 13}
151  * -- parameter value is PBMParameter
152  * value  BIT STRING
153  * }
154  */
155 typedef struct ossl_crmf_pkmacvalue_st {
156     X509_ALGOR *algId;
157     ASN1_BIT_STRING *value;
158 } OSSL_CRMF_PKMACVALUE;
159 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PKMACVALUE)
160
161 /*-
162  * SubsequentMessage ::= INTEGER {
163  * encrCert (0),
164  * -- requests that resulting certificate be encrypted for the
165  * -- end entity (following which, POP will be proven in a
166  * -- confirmation message)
167  * challengeResp (1)
168  * -- requests that CA engage in challenge-response exchange with
169  * -- end entity in order to prove private key possession
170  * }
171  *
172  * POPOPrivKey ::= CHOICE {
173  * thisMessage       [0] BIT STRING,                 -- Deprecated
174  * -- possession is proven in this message (which contains the private
175  * -- key itself (encrypted for the CA))
176  * subsequentMessage [1] SubsequentMessage,
177  * -- possession will be proven in a subsequent message
178  * dhMAC             [2] BIT STRING,                 -- Deprecated
179  * agreeMAC          [3] PKMACValue,
180  * encryptedKey      [4] EnvelopedData
181  * }
182  */
183
184 typedef struct ossl_crmf_popoprivkey_st {
185     int type;
186     union {
187         ASN1_BIT_STRING *thisMessage; /* 0 */ /* Deprecated */
188         ASN1_INTEGER *subsequentMessage; /* 1 */
189         ASN1_BIT_STRING *dhMAC; /* 2 */ /* Deprecated */
190         OSSL_CRMF_PKMACVALUE *agreeMAC; /* 3 */
191         /*
192          * TODO: This is not ASN1_NULL but CMS_ENVELOPEDDATA which should be
193          * somehow taken from crypto/cms which exists now
194          * - this is not used anywhere so far
195          */
196         ASN1_NULL *encryptedKey; /* 4 */
197     } value;
198 } OSSL_CRMF_POPOPRIVKEY;
199 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOPRIVKEY)
200
201 /*-
202  * PBMParameter ::= SEQUENCE {
203  *    salt                    OCTET STRING,
204  *    owf                     AlgorithmIdentifier,
205  *    -- AlgId for a One-Way Function (SHA-1 recommended)
206  *    iterationCount          INTEGER,
207  *    -- number of times the OWF is applied
208  *    mac                     AlgorithmIdentifier
209  *    -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
210  *    -- or HMAC [HMAC, RFC2202])
211  * }
212  */
213 struct ossl_crmf_pbmparameter_st {
214     ASN1_OCTET_STRING *salt;
215     X509_ALGOR *owf;
216     ASN1_INTEGER *iterationCount;
217     X509_ALGOR *mac;
218 } /* OSSL_CRMF_PBMPARAMETER */;
219 # define OSSL_CRMF_PBM_MAX_ITERATION_COUNT 100000 /* if too large allows DoS */
220
221 /*-
222  * POPOSigningKeyInput ::= SEQUENCE {
223  * authInfo       CHOICE {
224  *     sender                 [0] GeneralName,
225  *   -- used only if an authenticated identity has been
226  *   -- established for the sender (e.g., a DN from a
227  *   -- previously-issued and currently-valid certificate)
228  *     publicKeyMAC           PKMACValue },
229  *   -- used if no authenticated GeneralName currently exists for
230  *   -- the sender; publicKeyMAC contains a password-based MAC
231  *   -- on the DER-encoded value of publicKey
232  * publicKey      SubjectPublicKeyInfo  -- from CertTemplate
233  * }
234  */
235 typedef struct ossl_crmf_poposigningkeyinput_authinfo_st {
236     int type;
237     union {
238         /* 0 */ GENERAL_NAME *sender;
239         /* 1 */ OSSL_CRMF_PKMACVALUE *publicKeyMAC;
240     } value;
241 } OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO;
242 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO)
243
244 typedef struct ossl_crmf_poposigningkeyinput_st {
245     OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO *authInfo;
246     X509_PUBKEY *publicKey;
247 } OSSL_CRMF_POPOSIGNINGKEYINPUT;
248 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT)
249
250 /*-
251  * POPOSigningKey ::= SEQUENCE {
252  *  poposkInput           [0] POPOSigningKeyInput OPTIONAL,
253  *  algorithmIdentifier   AlgorithmIdentifier,
254  *  signature             BIT STRING
255  * }
256  */
257 struct ossl_crmf_poposigningkey_st {
258     OSSL_CRMF_POPOSIGNINGKEYINPUT *poposkInput;
259     X509_ALGOR *algorithmIdentifier;
260     ASN1_BIT_STRING *signature;
261 } /* OSSL_CRMF_POPOSIGNINGKEY */;
262 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEY)
263
264 /*-
265  * ProofOfPossession ::= CHOICE {
266  *  raVerified        [0] NULL,
267  *  -- used if the RA has already verified that the requester is in
268  *  -- possession of the private key
269  *  signature         [1] POPOSigningKey,
270  *  keyEncipherment   [2] POPOPrivKey,
271  *  keyAgreement      [3] POPOPrivKey
272  * }
273  */
274 typedef struct ossl_crmf_popo_st {
275     int type;
276     union {
277         ASN1_NULL *raVerified; /* 0 */
278         OSSL_CRMF_POPOSIGNINGKEY *signature; /* 1 */
279         OSSL_CRMF_POPOPRIVKEY *keyEncipherment; /* 2 */
280         OSSL_CRMF_POPOPRIVKEY *keyAgreement; /* 3 */
281     } value;
282 } OSSL_CRMF_POPO;
283 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
284
285 /*-
286  * OptionalValidity ::= SEQUENCE {
287  *  notBefore      [0] Time OPTIONAL,
288  *  notAfter       [1] Time OPTIONAL  -- at least one MUST be present
289  * }
290  */
291 struct ossl_crmf_optionalvalidity_st {
292     /* 0 */ ASN1_TIME *notBefore;
293     /* 1 */ ASN1_TIME *notAfter;
294 } /* OSSL_CRMF_OPTIONALVALIDITY */;
295 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_OPTIONALVALIDITY)
296
297 /*-
298  * CertTemplate ::= SEQUENCE {
299  * version          [0] Version                   OPTIONAL,
300  * serialNumber     [1] INTEGER                   OPTIONAL,
301  * signingAlg       [2] AlgorithmIdentifier       OPTIONAL,
302  * issuer           [3] Name                      OPTIONAL,
303  * validity         [4] OptionalValidity          OPTIONAL,
304  * subject          [5] Name                      OPTIONAL,
305  * publicKey        [6] SubjectPublicKeyInfo      OPTIONAL,
306  * issuerUID        [7] UniqueIdentifier          OPTIONAL,
307  * subjectUID       [8] UniqueIdentifier          OPTIONAL,
308  * extensions       [9] Extensions                OPTIONAL
309  * }
310  */
311 struct ossl_crmf_certtemplate_st {
312     ASN1_INTEGER *version;
313     ASN1_INTEGER *serialNumber; /* serialNumber MUST be omitted */
314     /* This field is assigned by the CA during certificate creation */
315     X509_ALGOR *signingAlg; /* signingAlg MUST be omitted */
316     /* This field is assigned by the CA during certificate creation */
317     const X509_NAME *issuer;
318     OSSL_CRMF_OPTIONALVALIDITY *validity;
319     const X509_NAME *subject;
320     X509_PUBKEY *publicKey;
321     ASN1_BIT_STRING *issuerUID; /* deprecated in version 2 */
322     /* According to rfc 3280: UniqueIdentifier ::= BIT STRING */
323     ASN1_BIT_STRING *subjectUID; /* deprecated in version 2 */
324     /* Could be X509_EXTENSION*S*, but that's only cosmetic */
325     STACK_OF(X509_EXTENSION) *extensions;
326 } /* OSSL_CRMF_CERTTEMPLATE */;
327
328 /*-
329  * CertRequest ::= SEQUENCE {
330  *  certReqId        INTEGER,          -- ID for matching request and reply
331  *  certTemplate     CertTemplate,     -- Selected fields of cert to be issued
332  *  controls         Controls OPTIONAL -- Attributes affecting issuance
333  * }
334  */
335 struct ossl_crmf_certrequest_st {
336     ASN1_INTEGER *certReqId;
337     OSSL_CRMF_CERTTEMPLATE *certTemplate;
338     /* TODO: make OSSL_CRMF_CONTROLS out of that - but only cosmetical */
339     STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) *controls;
340 } /* OSSL_CRMF_CERTREQUEST */;
341 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_CERTREQUEST)
342 DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_CERTREQUEST)
343
344 /* TODO: isn't there a better way to have this for ANY type? */
345 struct ossl_crmf_attributetypeandvalue_st {
346     ASN1_OBJECT *type;
347     union {
348         /* NID_id_regCtrl_regToken */
349         ASN1_UTF8STRING *regToken;
350
351         /* NID_id_regCtrl_authenticator */
352         ASN1_UTF8STRING *authenticator;
353
354         /* NID_id_regCtrl_pkiPublicationInfo */
355         OSSL_CRMF_PKIPUBLICATIONINFO *pkiPublicationInfo;
356
357         /* NID_id_regCtrl_oldCertID */
358         OSSL_CRMF_CERTID *oldCertID;
359
360         /* NID_id_regCtrl_protocolEncrKey */
361         X509_PUBKEY *protocolEncrKey;
362
363         /* NID_id_regInfo_utf8Pairs */
364         ASN1_UTF8STRING *utf8Pairs;
365
366         /* NID_id_regInfo_certReq */
367         OSSL_CRMF_CERTREQUEST *certReq;
368
369         ASN1_TYPE *other;
370     } value;
371 } /* OSSL_CRMF_ATTRIBUTETYPEANDVALUE */;
372 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
373 DEFINE_STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
374 DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
375
376 /*-
377  * CertReqMessages ::= SEQUENCE SIZE (1..MAX) OF CertReqMsg
378  * CertReqMsg ::= SEQUENCE {
379  *  certReq        CertRequest,
380  *  popo           ProofOfPossession  OPTIONAL,
381  * -- content depends upon key type
382  *  regInfo   SEQUENCE SIZE(1..MAX) OF AttributeTypeAndValue OPTIONAL
383  * }
384  */
385 struct ossl_crmf_msg_st {
386     OSSL_CRMF_CERTREQUEST *certReq;
387     /* 0 */
388     OSSL_CRMF_POPO *popo;
389     /* 1 */
390     STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) *regInfo;
391 } /* OSSL_CRMF_MSG */;
392 /* DEFINE_STACK_OF(OSSL_CRMF_MSG) */
393 #endif