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
11 * CRMF implementation by Martin Peylo, Miikka Viljanen, and David von Oheimb.
14 #ifndef OSSL_CRYPTO_CRMF_LOCAL_H
15 # define OSSL_CRYPTO_CRMF_LOCAL_H
17 # include <openssl/crmf.h>
18 # include <openssl/err.h>
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>
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)
42 * -- the encrypted value itself
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 */;
55 * Attributes ::= SET OF Attribute
58 * PrivateKeyInfo ::= SEQUENCE {
60 * privateKeyAlgorithm AlgorithmIdentifier,
61 * privateKey OCTET STRING,
62 * attributes [0] IMPLICIT Attributes OPTIONAL
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
)
74 * section 4.2.1 Private Key Info Content Type
75 * id-ct-encKeyWithID OBJECT IDENTIFIER ::= {id-ct 21}
77 * EncKeyWithID ::= SEQUENCE {
78 * privateKey PrivateKeyInfo,
81 * generalName GeneralName
85 typedef struct ossl_crmf_enckeywithid_identifier_st
{
88 ASN1_UTF8STRING
*string
;
89 GENERAL_NAME
*generalName
;
91 } OSSL_CRMF_ENCKEYWITHID_IDENTIFIER
;
92 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER
)
94 typedef struct ossl_crmf_enckeywithid_st
{
95 OSSL_CRMF_PRIVATEKEYINFO
*privateKey
;
97 OSSL_CRMF_ENCKEYWITHID_IDENTIFIER
*identifier
;
98 } OSSL_CRMF_ENCKEYWITHID
;
99 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID
)
102 * CertId ::= SEQUENCE {
103 * issuer GeneralName,
104 * serialNumber INTEGER
107 struct ossl_crmf_certid_st
{
108 GENERAL_NAME
*issuer
;
109 ASN1_INTEGER
*serialNumber
;
110 } /* OSSL_CRMF_CERTID */;
113 * SinglePubInfo ::= SEQUENCE {
114 * pubMethod INTEGER {
119 * pubLocation GeneralName OPTIONAL
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
;
131 * PKIPublicationInfo ::= SEQUENCE {
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)
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
)
148 * PKMACValue ::= SEQUENCE {
149 * algId AlgorithmIdentifier,
150 * -- algorithm value shall be PasswordBasedMac {1 2 840 113533 7 66 13}
151 * -- parameter value is PBMParameter
155 typedef struct ossl_crmf_pkmacvalue_st
{
157 ASN1_BIT_STRING
*value
;
158 } OSSL_CRMF_PKMACVALUE
;
159 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PKMACVALUE
)
162 * SubsequentMessage ::= INTEGER {
164 * -- requests that resulting certificate be encrypted for the
165 * -- end entity (following which, POP will be proven in a
166 * -- confirmation message)
168 * -- requests that CA engage in challenge-response exchange with
169 * -- end entity in order to prove private key possession
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
184 typedef struct ossl_crmf_popoprivkey_st
{
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 */
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
196 ASN1_NULL
*encryptedKey
; /* 4 */
198 } OSSL_CRMF_POPOPRIVKEY
;
199 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOPRIVKEY
)
202 * PBMParameter ::= SEQUENCE {
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])
213 struct ossl_crmf_pbmparameter_st
{
214 ASN1_OCTET_STRING
*salt
;
216 ASN1_INTEGER
*iterationCount
;
218 } /* OSSL_CRMF_PBMPARAMETER */;
219 # define OSSL_CRMF_PBM_MAX_ITERATION_COUNT 100000 /* if too large allows DoS */
222 * POPOSigningKeyInput ::= SEQUENCE {
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
235 typedef struct ossl_crmf_poposigningkeyinput_authinfo_st
{
238 /* 0 */ GENERAL_NAME
*sender
;
239 /* 1 */ OSSL_CRMF_PKMACVALUE
*publicKeyMAC
;
241 } OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO
;
242 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO
)
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
)
251 * POPOSigningKey ::= SEQUENCE {
252 * poposkInput [0] POPOSigningKeyInput OPTIONAL,
253 * algorithmIdentifier AlgorithmIdentifier,
254 * signature BIT STRING
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
)
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
274 typedef struct ossl_crmf_popo_st
{
277 ASN1_NULL
*raVerified
; /* 0 */
278 OSSL_CRMF_POPOSIGNINGKEY
*signature
; /* 1 */
279 OSSL_CRMF_POPOPRIVKEY
*keyEncipherment
; /* 2 */
280 OSSL_CRMF_POPOPRIVKEY
*keyAgreement
; /* 3 */
283 DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPO
)
286 * OptionalValidity ::= SEQUENCE {
287 * notBefore [0] Time OPTIONAL,
288 * notAfter [1] Time OPTIONAL -- at least one MUST be present
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
)
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
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 */;
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
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
)
344 /* TODO: isn't there a better way to have this for ANY type? */
345 struct ossl_crmf_attributetypeandvalue_st
{
348 /* NID_id_regCtrl_regToken */
349 ASN1_UTF8STRING
*regToken
;
351 /* NID_id_regCtrl_authenticator */
352 ASN1_UTF8STRING
*authenticator
;
354 /* NID_id_regCtrl_pkiPublicationInfo */
355 OSSL_CRMF_PKIPUBLICATIONINFO
*pkiPublicationInfo
;
357 /* NID_id_regCtrl_oldCertID */
358 OSSL_CRMF_CERTID
*oldCertID
;
360 /* NID_id_regCtrl_protocolEncrKey */
361 X509_PUBKEY
*protocolEncrKey
;
363 /* NID_id_regInfo_utf8Pairs */
364 ASN1_UTF8STRING
*utf8Pairs
;
366 /* NID_id_regInfo_certReq */
367 OSSL_CRMF_CERTREQUEST
*certReq
;
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
)
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
385 struct ossl_crmf_msg_st
{
386 OSSL_CRMF_CERTREQUEST
*certReq
;
388 OSSL_CRMF_POPO
*popo
;
390 STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE
) *regInfo
;
391 } /* OSSL_CRMF_MSG */;
392 /* DEFINE_STACK_OF(OSSL_CRMF_MSG) */