1 | /** @file
|
---|
2 | * IPRT - PKCS \#7, Cryptographic Message Syntax Standard (aka CMS).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_crypto_pkcs7_h
|
---|
27 | #define IPRT_INCLUDED_crypto_pkcs7_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/asn1.h>
|
---|
33 | #include <iprt/crypto/x509.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | RT_C_DECLS_BEGIN
|
---|
37 |
|
---|
38 | struct RTCRPKCS7CONTENTINFO;
|
---|
39 |
|
---|
40 |
|
---|
41 | /** @defgroup grp_rt_crpkcs7 RTCrPkcs7 - PKCS \#7, Cryptographic Message Syntax Standard (aka CMS).
|
---|
42 | * @ingroup grp_rt_crypto
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 | /** PKCS \#7 data object ID.*/
|
---|
47 | #define RTCR_PKCS7_DATA_OID "1.2.840.113549.1.7.1"
|
---|
48 | /** PKCS \#7 signedData object ID. */
|
---|
49 | #define RTCR_PKCS7_SIGNED_DATA_OID "1.2.840.113549.1.7.2"
|
---|
50 | /** PKCS \#7 envelopedData object ID. */
|
---|
51 | #define RTCR_PKCS7_ENVELOPED_DATA_OID "1.2.840.113549.1.7.3"
|
---|
52 | /** PKCS \#7 signedAndEnvelopedData object ID. */
|
---|
53 | #define RTCR_PKCS7_SIGNED_AND_ENVELOPED_DATA_OID "1.2.840.113549.1.7.4"
|
---|
54 | /** PKCS \#7 digestedData object ID. */
|
---|
55 | #define RTCR_PKCS7_DIGESTED_DATA_OID "1.2.840.113549.1.7.5"
|
---|
56 | /** PKCS \#7 encryptedData object ID. */
|
---|
57 | #define RTCR_PKCS7_ENCRYPTED_DATA_OID "1.2.840.113549.1.7.6"
|
---|
58 |
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * PKCS \#7 IssuerAndSerialNumber (IPRT representation).
|
---|
62 | */
|
---|
63 | typedef struct RTCRPKCS7ISSUERANDSERIALNUMBER
|
---|
64 | {
|
---|
65 | /** Sequence core. */
|
---|
66 | RTASN1SEQUENCECORE SeqCore;
|
---|
67 | /** The certificate name. */
|
---|
68 | RTCRX509NAME Name;
|
---|
69 | /** The certificate serial number. */
|
---|
70 | RTASN1INTEGER SerialNumber;
|
---|
71 | } RTCRPKCS7ISSUERANDSERIALNUMBER;
|
---|
72 | /** Pointer to the IPRT representation of a PKCS \#7 IssuerAndSerialNumber. */
|
---|
73 | typedef RTCRPKCS7ISSUERANDSERIALNUMBER *PRTCRPKCS7ISSUERANDSERIALNUMBER;
|
---|
74 | /** Pointer to the const IPRT representation of a PKCS \#7
|
---|
75 | * IssuerAndSerialNumber. */
|
---|
76 | typedef RTCRPKCS7ISSUERANDSERIALNUMBER const *PCRTCRPKCS7ISSUERANDSERIALNUMBER;
|
---|
77 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7ISSUERANDSERIALNUMBER, RTDECL, RTCrPkcs7IssuerAndSerialNumber, SeqCore.Asn1Core);
|
---|
78 |
|
---|
79 |
|
---|
80 | /** Pointer to the IPRT representation of a PKCS \#7 SignerInfo. */
|
---|
81 | typedef struct RTCRPKCS7SIGNERINFO *PRTCRPKCS7SIGNERINFO;
|
---|
82 | /** Pointer to the const IPRT representation of a PKCS \#7 SignerInfo. */
|
---|
83 | typedef struct RTCRPKCS7SIGNERINFO const *PCRTCRPKCS7SIGNERINFO;
|
---|
84 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SIGNERINFOS, RTCRPKCS7SIGNERINFO, RTDECL, RTCrPkcs7SignerInfos);
|
---|
85 |
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Attribute value type (for the union).
|
---|
89 | */
|
---|
90 | typedef enum RTCRPKCS7ATTRIBUTETYPE
|
---|
91 | {
|
---|
92 | /** Zero is invalid. */
|
---|
93 | RTCRPKCS7ATTRIBUTETYPE_INVALID = 0,
|
---|
94 | /** Not present, union is NULL. */
|
---|
95 | RTCRPKCS7ATTRIBUTETYPE_NOT_PRESENT,
|
---|
96 | /** Unknown values, pCores. */
|
---|
97 | RTCRPKCS7ATTRIBUTETYPE_UNKNOWN,
|
---|
98 | /** Object IDs, use pObjIds. */
|
---|
99 | RTCRPKCS7ATTRIBUTETYPE_OBJ_IDS,
|
---|
100 | /** Octet strings, use pOctetStrings. */
|
---|
101 | RTCRPKCS7ATTRIBUTETYPE_OCTET_STRINGS,
|
---|
102 | /** Counter signatures (PKCS \#9), use pCounterSignatures. */
|
---|
103 | RTCRPKCS7ATTRIBUTETYPE_COUNTER_SIGNATURES,
|
---|
104 | /** Signing time (PKCS \#9), use pSigningTime. */
|
---|
105 | RTCRPKCS7ATTRIBUTETYPE_SIGNING_TIME,
|
---|
106 | /** Microsoft timestamp info (RFC-3161) signed data, use pContentInfo. */
|
---|
107 | RTCRPKCS7ATTRIBUTETYPE_MS_TIMESTAMP,
|
---|
108 | /** Microsoft nested PKCS\#7 signature (signtool /as). */
|
---|
109 | RTCRPKCS7ATTRIBUTETYPE_MS_NESTED_SIGNATURE,
|
---|
110 | /** Microsoft statement type, use pObjIdSeqs. */
|
---|
111 | RTCRPKCS7ATTRIBUTETYPE_MS_STATEMENT_TYPE,
|
---|
112 | /** Apple plist with the all code directory digests, use pOctetStrings. */
|
---|
113 | RTCRPKCS7ATTRIBUTETYPE_APPLE_MULTI_CD_PLIST,
|
---|
114 | /** Blow the type up to 32-bits. */
|
---|
115 | RTCRPKCS7ATTRIBUTETYPE_32BIT_HACK = 0x7fffffff
|
---|
116 | } RTCRPKCS7ATTRIBUTETYPE;
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * PKCS \#7 Attribute (IPRT representation).
|
---|
120 | */
|
---|
121 | typedef struct RTCRPKCS7ATTRIBUTE
|
---|
122 | {
|
---|
123 | /** Sequence core. */
|
---|
124 | RTASN1SEQUENCECORE SeqCore;
|
---|
125 | /** The attribute type (object ID). */
|
---|
126 | RTASN1OBJID Type;
|
---|
127 | /** The type of data found in the values union. */
|
---|
128 | RTCRPKCS7ATTRIBUTETYPE enmType;
|
---|
129 | /** Value allocation. */
|
---|
130 | RTASN1ALLOCATION Allocation;
|
---|
131 | /** Values. */
|
---|
132 | union
|
---|
133 | {
|
---|
134 | /** ASN.1 cores (RTCRPKCS7ATTRIBUTETYPE_UNKNOWN). */
|
---|
135 | PRTASN1SETOFCORES pCores;
|
---|
136 | /** ASN.1 object identifiers (RTCRPKCS7ATTRIBUTETYPE_OBJ_IDS). */
|
---|
137 | PRTASN1SETOFOBJIDS pObjIds;
|
---|
138 | /** Sequence of ASN.1 object identifiers (RTCRPKCS7ATTRIBUTETYPE_MS_STATEMENT_TYPE). */
|
---|
139 | PRTASN1SETOFOBJIDSEQS pObjIdSeqs;
|
---|
140 | /** ASN.1 octet strings (RTCRPKCS7ATTRIBUTETYPE_OCTET_STRINGS). */
|
---|
141 | PRTASN1SETOFOCTETSTRINGS pOctetStrings;
|
---|
142 | /** Counter signatures RTCRPKCS7ATTRIBUTETYPE_COUNTER_SIGNATURES(). */
|
---|
143 | PRTCRPKCS7SIGNERINFOS pCounterSignatures;
|
---|
144 | /** Signing time(s) (RTCRPKCS7ATTRIBUTETYPE_SIGNING_TIME). */
|
---|
145 | PRTASN1SETOFTIMES pSigningTime;
|
---|
146 | /** Microsoft timestamp (RFC-3161 signed data, RTCRPKCS7ATTRIBUTETYPE_MS_TIMESTAMP),
|
---|
147 | * Microsoft nested signature (RTCRPKCS7ATTRIBUTETYPE_MS_NESTED_SIGNATURE). */
|
---|
148 | struct RTCRPKCS7SETOFCONTENTINFOS *pContentInfos;
|
---|
149 | } uValues;
|
---|
150 | } RTCRPKCS7ATTRIBUTE;
|
---|
151 | /** Pointer to the IPRT representation of a PKCS \#7 Attribute. */
|
---|
152 | typedef RTCRPKCS7ATTRIBUTE *PRTCRPKCS7ATTRIBUTE;
|
---|
153 | /** Pointer to the const IPRT representation of a PKCS \#7 Attribute. */
|
---|
154 | typedef RTCRPKCS7ATTRIBUTE const *PCRTCRPKCS7ATTRIBUTE;
|
---|
155 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7ATTRIBUTE, RTDECL, RTCrPkcs7Attribute, SeqCore.Asn1Core);
|
---|
156 |
|
---|
157 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7ATTRIBUTES, RTCRPKCS7ATTRIBUTE, RTDECL, RTCrPkcs7Attributes);
|
---|
158 |
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * One PKCS \#7 SignerInfo (IPRT representation).
|
---|
162 | */
|
---|
163 | typedef struct RTCRPKCS7SIGNERINFO
|
---|
164 | {
|
---|
165 | /** Sequence core. */
|
---|
166 | RTASN1SEQUENCECORE SeqCore;
|
---|
167 | /** The structure version (RTCRPKCS7SIGNERINFO_V1). */
|
---|
168 | RTASN1INTEGER Version;
|
---|
169 | /** The issuer and serial number of the certificate used to produce the
|
---|
170 | * encrypted digest below. */
|
---|
171 | RTCRPKCS7ISSUERANDSERIALNUMBER IssuerAndSerialNumber;
|
---|
172 | /** The digest algorithm use to digest the signed content. */
|
---|
173 | RTCRX509ALGORITHMIDENTIFIER DigestAlgorithm;
|
---|
174 | /** Authenticated attributes, optional [0].
|
---|
175 | * @todo Check how other producers formats this. The microsoft one does not
|
---|
176 | * have explicit tags, but combines it with the SET OF. */
|
---|
177 | RTCRPKCS7ATTRIBUTES AuthenticatedAttributes;
|
---|
178 | /** The digest encryption algorithm use to encrypt the digest of the signed
|
---|
179 | * content. */
|
---|
180 | RTCRX509ALGORITHMIDENTIFIER DigestEncryptionAlgorithm;
|
---|
181 | /** The encrypted digest. */
|
---|
182 | RTASN1OCTETSTRING EncryptedDigest;
|
---|
183 | /** Unauthenticated attributes, optional [1].
|
---|
184 | * @todo Check how other producers formats this. The microsoft one does not
|
---|
185 | * have explicit tags, but combines it with the SET OF. */
|
---|
186 | RTCRPKCS7ATTRIBUTES UnauthenticatedAttributes;
|
---|
187 | } RTCRPKCS7SIGNERINFO;
|
---|
188 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7SIGNERINFO, RTDECL, RTCrPkcs7SignerInfo, SeqCore.Asn1Core);
|
---|
189 |
|
---|
190 | /** RTCRPKCS7SIGNERINFO::Version value. */
|
---|
191 | #define RTCRPKCS7SIGNERINFO_V1 1
|
---|
192 |
|
---|
193 | /** @name PKCS \#9 Attribute IDs
|
---|
194 | * @{ */
|
---|
195 | /** Content type (RFC-2630 11.1).
|
---|
196 | * Value: Object Identifier */
|
---|
197 | #define RTCR_PKCS9_ID_CONTENT_TYPE_OID "1.2.840.113549.1.9.3"
|
---|
198 | /** Message digest (RFC-2630 11.2).
|
---|
199 | * Value: Octet string. */
|
---|
200 | #define RTCR_PKCS9_ID_MESSAGE_DIGEST_OID "1.2.840.113549.1.9.4"
|
---|
201 | /** Signing time (RFC-2630 11.3).
|
---|
202 | * Value: Octet string. */
|
---|
203 | #define RTCR_PKCS9_ID_SIGNING_TIME_OID "1.2.840.113549.1.9.5"
|
---|
204 | /** Counter signature (RFC-2630 11.4).
|
---|
205 | * Value: SignerInfo. */
|
---|
206 | #define RTCR_PKCS9_ID_COUNTER_SIGNATURE_OID "1.2.840.113549.1.9.6"
|
---|
207 | /** Microsoft timestamp (RTF-3161) counter signature (SignedData).
|
---|
208 | * @remarks This isn't defined by PKCS \#9, but lumped in here for convenience. It's actually listed as SPC by MS. */
|
---|
209 | #define RTCR_PKCS9_ID_MS_TIMESTAMP "1.3.6.1.4.1.311.3.3.1"
|
---|
210 | /** Microsoft nested PKCS\#7 signature.
|
---|
211 | * @remarks This isn't defined by PKCS \#9, but lumped in here for convenience. */
|
---|
212 | #define RTCR_PKCS9_ID_MS_NESTED_SIGNATURE "1.3.6.1.4.1.311.2.4.1"
|
---|
213 | /** Microsoft statement type.
|
---|
214 | * @remarks This isn't defined by PKCS \#9, but lumped in here for convenience. It's actually listed as SPC by MS. */
|
---|
215 | #define RTCR_PKCS9_ID_MS_STATEMENT_TYPE "1.3.6.1.4.1.311.2.1.11"
|
---|
216 | /** Microsoft opus info.
|
---|
217 | * @remarks This isn't defined by PKCS \#9, but lumped in here for convenience. It's actually listed as SPC by MS. */
|
---|
218 | #define RTCR_PKCS9_ID_MS_SP_OPUS_INFO "1.3.6.1.4.1.311.2.1.12"
|
---|
219 | /** Apple code signing multi-code-directory plist.
|
---|
220 | * @remarks This isn't defined by PKCS \#9, but lumped in here for convenience. */
|
---|
221 | #define RTCR_PKCS9_ID_APPLE_MULTI_CD_PLIST "1.2.840.113635.100.9.1"
|
---|
222 | /** @} */
|
---|
223 |
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * Get the (next) signing time attribute from the specfied SignerInfo or one of
|
---|
227 | * the immediate counter signatures.
|
---|
228 | *
|
---|
229 | * @returns Pointer to the signing time if found, NULL if not.
|
---|
230 | * @param pThis The SignerInfo to search.
|
---|
231 | * @param ppSignerInfo Pointer to variable keeping track of the
|
---|
232 | * enumeration, optional.
|
---|
233 | *
|
---|
234 | * If specified the input value is taken to the be
|
---|
235 | * SignerInfo of the previously returned signing
|
---|
236 | * time. The value pointed to is NULL, the
|
---|
237 | * search/enum restarts.
|
---|
238 | *
|
---|
239 | * On successful return this is set to the
|
---|
240 | * SignerInfo which we found the signing time in.
|
---|
241 | */
|
---|
242 | RTDECL(PCRTASN1TIME) RTCrPkcs7SignerInfo_GetSigningTime(PCRTCRPKCS7SIGNERINFO pThis, PCRTCRPKCS7SIGNERINFO *ppSignerInfo);
|
---|
243 |
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Get the (first) timestamp from within a Microsoft timestamp server counter
|
---|
247 | * signature.
|
---|
248 | *
|
---|
249 | * @returns Pointer to the signing time if found, NULL if not.
|
---|
250 | * @param pThis The SignerInfo to search.
|
---|
251 | * @param ppContentInfoRet Where to return the pointer to the counter
|
---|
252 | * signature, optional.
|
---|
253 | */
|
---|
254 | RTDECL(PCRTASN1TIME) RTCrPkcs7SignerInfo_GetMsTimestamp(PCRTCRPKCS7SIGNERINFO pThis,
|
---|
255 | struct RTCRPKCS7CONTENTINFO const **ppContentInfoRet);
|
---|
256 |
|
---|
257 |
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * PKCS \#7 ContentInfo (IPRT representation).
|
---|
261 | */
|
---|
262 | typedef struct RTCRPKCS7CONTENTINFO
|
---|
263 | {
|
---|
264 | /** Sequence core. */
|
---|
265 | RTASN1SEQUENCECORE SeqCore;
|
---|
266 | /** Object ID identifying the content below. */
|
---|
267 | RTASN1OBJID ContentType;
|
---|
268 | /** Content, optional, explicit tag 0.
|
---|
269 | *
|
---|
270 | * Hack alert! This should've been an explict context tag 0 structure with a
|
---|
271 | * type selected according to ContentType. However, it's simpler to replace the
|
---|
272 | * explicit context with an OCTET STRING with implict tag 0. Then we can tag
|
---|
273 | * along on the encapsulation logic RTASN1OCTETSTRING provides for the dynamic
|
---|
274 | * inner type. The default decoder code will detect known structures as
|
---|
275 | * outlined in the union below, and decode the octet string content as an
|
---|
276 | * anonymous RTASN1CORE if not known.
|
---|
277 | *
|
---|
278 | * If the user want to decode the octet string content differently, it can do so
|
---|
279 | * by destroying and freeing the current encapsulated pointer, replacing it with
|
---|
280 | * it's own. (Of course following the RTASN1OCTETSTRING rules.) Just remember
|
---|
281 | * to also update the value in the union.
|
---|
282 | *
|
---|
283 | * @remarks What's signed and verified is Content.pEncapsulated->uData.pv.
|
---|
284 | */
|
---|
285 | RTASN1OCTETSTRING Content;
|
---|
286 | /** Pointer to the CMS octet string that's inside the Content, NULL if PKCS \#7.
|
---|
287 | *
|
---|
288 | * Hack alert! When transitioning from PKCS \#7 to CMS, the designers decided to
|
---|
289 | * change things and add another wrapper. This time we're talking about a real
|
---|
290 | * octet string, not like the one above which is really an explicit content tag.
|
---|
291 | * When constructing or decoding CMS content, this will be the same pointer as
|
---|
292 | * Content.pEncapsulated, while the union below will be holding the same pointer
|
---|
293 | * as pCmsContent->pEncapsulated.
|
---|
294 | */
|
---|
295 | PRTASN1OCTETSTRING pCmsContent;
|
---|
296 | /** Same as Content.pEncapsulated, except a choice of known types. */
|
---|
297 | union
|
---|
298 | {
|
---|
299 | /** ContentType is RTCRPKCS7SIGNEDDATA_OID. */
|
---|
300 | struct RTCRPKCS7SIGNEDDATA *pSignedData;
|
---|
301 | /** ContentType is RTCRSPCINDIRECTDATACONTENT_OID. */
|
---|
302 | struct RTCRSPCINDIRECTDATACONTENT *pIndirectDataContent;
|
---|
303 | /** ContentType is RTCRTSPTSTINFO_OID. */
|
---|
304 | struct RTCRTSPTSTINFO *pTstInfo;
|
---|
305 | /** Generic / Unknown / User. */
|
---|
306 | PRTASN1CORE pCore;
|
---|
307 | } u;
|
---|
308 | } RTCRPKCS7CONTENTINFO;
|
---|
309 | /** Pointer to the IPRT representation of a PKCS \#7 ContentInfo. */
|
---|
310 | typedef RTCRPKCS7CONTENTINFO *PRTCRPKCS7CONTENTINFO;
|
---|
311 | /** Pointer to the const IPRT representation of a PKCS \#7 ContentInfo. */
|
---|
312 | typedef RTCRPKCS7CONTENTINFO const *PCRTCRPKCS7CONTENTINFO;
|
---|
313 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7CONTENTINFO, RTDECL, RTCrPkcs7ContentInfo, SeqCore.Asn1Core);
|
---|
314 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFCONTENTINFOS, RTCRPKCS7CONTENTINFO, RTDECL, RTCrPkcs7SetOfContentInfos);
|
---|
315 |
|
---|
316 | RTDECL(bool) RTCrPkcs7ContentInfo_IsSignedData(PCRTCRPKCS7CONTENTINFO pThis);
|
---|
317 |
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * PKCS \#7 Certificate choice.
|
---|
321 | */
|
---|
322 | typedef enum RTCRPKCS7CERTCHOICE
|
---|
323 | {
|
---|
324 | RTCRPKCS7CERTCHOICE_INVALID = 0,
|
---|
325 | RTCRPKCS7CERTCHOICE_X509,
|
---|
326 | RTCRPKCS7CERTCHOICE_EXTENDED_PKCS6,
|
---|
327 | RTCRPKCS7CERTCHOICE_AC_V1,
|
---|
328 | RTCRPKCS7CERTCHOICE_AC_V2,
|
---|
329 | RTCRPKCS7CERTCHOICE_OTHER,
|
---|
330 | RTCRPKCS7CERTCHOICE_END,
|
---|
331 | RTCRPKCS7CERTCHOICE_32BIT_HACK = 0x7fffffff
|
---|
332 | } RTCRPKCS7CERTCHOICE;
|
---|
333 |
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * Common representation for PKCS \#7 ExtendedCertificateOrCertificate and the
|
---|
337 | * CMS CertificateChoices types.
|
---|
338 | */
|
---|
339 | typedef struct RTCRPKCS7CERT
|
---|
340 | {
|
---|
341 | /** Dummy ASN.1 record, not encoded. */
|
---|
342 | RTASN1DUMMY Dummy;
|
---|
343 | /** The value allocation. */
|
---|
344 | RTASN1ALLOCATION Allocation;
|
---|
345 | /** The choice of value. */
|
---|
346 | RTCRPKCS7CERTCHOICE enmChoice;
|
---|
347 | /** The value union. */
|
---|
348 | union
|
---|
349 | {
|
---|
350 | /** Standard X.509 certificate (RTCRCMSCERTIFICATECHOICE_X509). */
|
---|
351 | PRTCRX509CERTIFICATE pX509Cert;
|
---|
352 | /** Extended PKCS \#6 certificate (RTCRCMSCERTIFICATECHOICE_EXTENDED_PKCS6). */
|
---|
353 | PRTASN1CORE pExtendedCert;
|
---|
354 | /** Attribute certificate version 1 (RTCRCMSCERTIFICATECHOICE_AC_V1). */
|
---|
355 | PRTASN1CORE pAcV1;
|
---|
356 | /** Attribute certificate version 2 (RTCRCMSCERTIFICATECHOICE_AC_V2). */
|
---|
357 | PRTASN1CORE pAcV2;
|
---|
358 | /** Other certificate (RTCRCMSCERTIFICATECHOICE_OTHER). */
|
---|
359 | PRTASN1CORE pOtherCert;
|
---|
360 | } u;
|
---|
361 | } RTCRPKCS7CERT;
|
---|
362 | /** Pointer to the IPRT representation of PKCS \#7 or CMS certificate. */
|
---|
363 | typedef RTCRPKCS7CERT *PRTCRPKCS7CERT;
|
---|
364 | /** Pointer to the const IPRT representation of PKCS \#7 or CMS certificate. */
|
---|
365 | typedef RTCRPKCS7CERT const *PCRTCRPKCS7CERT;
|
---|
366 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7CERT, RTDECL, RTCrPkcs7Cert, Dummy.Asn1Core);
|
---|
367 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFCERTS, RTCRPKCS7CERT, RTDECL, RTCrPkcs7SetOfCerts);
|
---|
368 |
|
---|
369 | RTDECL(PCRTCRX509CERTIFICATE) RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(PCRTCRPKCS7SETOFCERTS pCertificates,
|
---|
370 | PCRTCRX509NAME pIssuer,
|
---|
371 | PCRTASN1INTEGER pSerialNumber);
|
---|
372 |
|
---|
373 |
|
---|
374 | /**
|
---|
375 | * PKCS \#7 SignedData (IPRT representation).
|
---|
376 | */
|
---|
377 | typedef struct RTCRPKCS7SIGNEDDATA
|
---|
378 | {
|
---|
379 | /** Sequence core. */
|
---|
380 | RTASN1SEQUENCECORE SeqCore;
|
---|
381 | /** The structure version value (1). */
|
---|
382 | RTASN1INTEGER Version;
|
---|
383 | /** The digest algorithms that are used to signed the content (ContentInfo). */
|
---|
384 | RTCRX509ALGORITHMIDENTIFIERS DigestAlgorithms;
|
---|
385 | /** The content that's being signed. */
|
---|
386 | RTCRPKCS7CONTENTINFO ContentInfo;
|
---|
387 | /** Certificates, optional, implicit tag 0. (Required by Authenticode.) */
|
---|
388 | RTCRPKCS7SETOFCERTS Certificates;
|
---|
389 | /** Certificate revocation lists, optional, implicit tag 1.
|
---|
390 | * Not used by Authenticode, so currently stubbed. */
|
---|
391 | RTASN1CORE Crls;
|
---|
392 | /** Signer infos. */
|
---|
393 | RTCRPKCS7SIGNERINFOS SignerInfos;
|
---|
394 | } RTCRPKCS7SIGNEDDATA;
|
---|
395 | /** Pointer to the IPRT representation of a PKCS \#7 SignedData. */
|
---|
396 | typedef RTCRPKCS7SIGNEDDATA *PRTCRPKCS7SIGNEDDATA;
|
---|
397 | /** Pointer to the const IPRT representation of a PKCS \#7 SignedData. */
|
---|
398 | typedef RTCRPKCS7SIGNEDDATA const *PCRTCRPKCS7SIGNEDDATA;
|
---|
399 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7SIGNEDDATA, RTDECL, RTCrPkcs7SignedData, SeqCore.Asn1Core);
|
---|
400 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFSIGNEDDATA, RTCRPKCS7SIGNEDDATA, RTDECL, RTCrPkcs7SetOfSignedData);
|
---|
401 |
|
---|
402 | /** PKCS \#7 SignedData object ID. */
|
---|
403 | #define RTCRPKCS7SIGNEDDATA_OID RTCR_PKCS7_SIGNED_DATA_OID
|
---|
404 |
|
---|
405 | /** PKCS \#7 SignedData version number 1. */
|
---|
406 | #define RTCRPKCS7SIGNEDDATA_V1 1
|
---|
407 | /* No version 2 seems to exist. */
|
---|
408 | /** CMS SignedData version number 3.
|
---|
409 | * This should only be used if there are version 1 attribute certificates
|
---|
410 | * present, or if there are version 3 SignerInfo items present, or if
|
---|
411 | * enmcCountInfo is not id-data (RFC-5652, section 5.1). */
|
---|
412 | #define RTCRPKCS7SIGNEDDATA_V3 3
|
---|
413 | /** CMS SignedData version number 4.
|
---|
414 | * This should only be used if there are version 2 attribute certificates
|
---|
415 | * present (RFC-5652, section 5.1). */
|
---|
416 | #define RTCRPKCS7SIGNEDDATA_V4 4
|
---|
417 | /** CMS SignedData version number 5.
|
---|
418 | * This should only be used if there are certificates or/and CRLs of the
|
---|
419 | * OTHER type present (RFC-5652, section 5.1). */
|
---|
420 | #define RTCRPKCS7SIGNEDDATA_V5 5
|
---|
421 |
|
---|
422 |
|
---|
423 | /** @name RTCRPKCS7SIGNEDDATA_SANITY_F_XXX - Flags for RTPkcs7SignedDataCheckSantiy.
|
---|
424 | * @{ */
|
---|
425 | /** Check for authenticode restrictions. */
|
---|
426 | #define RTCRPKCS7SIGNEDDATA_SANITY_F_AUTHENTICODE RT_BIT_32(0)
|
---|
427 | /** Check that all the hash algorithms are known to IPRT. */
|
---|
428 | #define RTCRPKCS7SIGNEDDATA_SANITY_F_ONLY_KNOWN_HASH RT_BIT_32(1)
|
---|
429 | /** Require signing certificate to be present. */
|
---|
430 | #define RTCRPKCS7SIGNEDDATA_SANITY_F_SIGNING_CERT_PRESENT RT_BIT_32(2)
|
---|
431 | /** @} */
|
---|
432 |
|
---|
433 |
|
---|
434 | /**
|
---|
435 | * PKCS \#7 DigestInfo (IPRT representation).
|
---|
436 | */
|
---|
437 | typedef struct RTCRPKCS7DIGESTINFO
|
---|
438 | {
|
---|
439 | /** Sequence core. */
|
---|
440 | RTASN1SEQUENCECORE SeqCore;
|
---|
441 | /** The digest algorithm use to digest the signed content. */
|
---|
442 | RTCRX509ALGORITHMIDENTIFIER DigestAlgorithm;
|
---|
443 | /** The digest. */
|
---|
444 | RTASN1OCTETSTRING Digest;
|
---|
445 | } RTCRPKCS7DIGESTINFO;
|
---|
446 | /** Pointer to the IPRT representation of a PKCS \#7 DigestInfo object. */
|
---|
447 | typedef RTCRPKCS7DIGESTINFO *PRTCRPKCS7DIGESTINFO;
|
---|
448 | /** Pointer to the const IPRT representation of a PKCS \#7 DigestInfo object. */
|
---|
449 | typedef RTCRPKCS7DIGESTINFO const *PCRTCRPKCS7DIGESTINFO;
|
---|
450 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7DIGESTINFO, RTDECL, RTCrPkcs7DigestInfo, SeqCore.Asn1Core);
|
---|
451 |
|
---|
452 |
|
---|
453 | /**
|
---|
454 | * Callback function for use with RTCrPkcs7VerifySignedData.
|
---|
455 | *
|
---|
456 | * @returns IPRT status code.
|
---|
457 | * @param pCert The certificate to verify.
|
---|
458 | * @param hCertPaths Unless the certificate is trusted directly, this
|
---|
459 | * is a reference to the certificate path builder
|
---|
460 | * and verifier instance that we used to establish
|
---|
461 | * at least valid trusted path to @a pCert. The
|
---|
462 | * callback can use this to enforce additional
|
---|
463 | * certificate lineage requirements, effective
|
---|
464 | * policy checks and whatnot.
|
---|
465 | * This is NIL_RTCRX509CERTPATHS if the certificate
|
---|
466 | * is directly trusted.
|
---|
467 | * @param fFlags Mix of the RTCRPKCS7VCC_F_XXX flags.
|
---|
468 | * @param pvUser The user argument.
|
---|
469 | * @param pErrInfo Optional error info buffer.
|
---|
470 | */
|
---|
471 | typedef DECLCALLBACK(int) FNRTCRPKCS7VERIFYCERTCALLBACK(PCRTCRX509CERTIFICATE pCert, RTCRX509CERTPATHS hCertPaths,
|
---|
472 | uint32_t fFlags, void *pvUser, PRTERRINFO pErrInfo);
|
---|
473 | /** Pointer to a FNRTCRPKCS7VERIFYCERTCALLBACK callback. */
|
---|
474 | typedef FNRTCRPKCS7VERIFYCERTCALLBACK *PFNRTCRPKCS7VERIFYCERTCALLBACK;
|
---|
475 |
|
---|
476 | /** @name RTCRPKCS7VCC_F_XXX - Flags for FNRTCRPKCS7VERIFYCERTCALLBACK.
|
---|
477 | * @{ */
|
---|
478 | /** Normal callback for a direct signatory of the signed data. */
|
---|
479 | #define RTCRPKCS7VCC_F_SIGNED_DATA RT_BIT_32(0)
|
---|
480 | /** Check that the signatory can be trusted for timestamps. */
|
---|
481 | #define RTCRPKCS7VCC_F_TIMESTAMP RT_BIT_32(1)
|
---|
482 | /** @} */
|
---|
483 |
|
---|
484 | /**
|
---|
485 | * @callback_method_impl{FNRTCRPKCS7VERIFYCERTCALLBACK,
|
---|
486 | * Default implementation that checks for the DigitalSignature KeyUsage bit.}
|
---|
487 | */
|
---|
488 | RTDECL(int) RTCrPkcs7VerifyCertCallbackDefault(PCRTCRX509CERTIFICATE pCert, RTCRX509CERTPATHS hCertPaths, uint32_t fFlags,
|
---|
489 | void *pvUser, PRTERRINFO pErrInfo);
|
---|
490 |
|
---|
491 | /**
|
---|
492 | * @callback_method_impl{FNRTCRPKCS7VERIFYCERTCALLBACK,
|
---|
493 | * Standard code signing. Use this for Microsoft SPC.}
|
---|
494 | */
|
---|
495 | RTDECL(int) RTCrPkcs7VerifyCertCallbackCodeSigning(PCRTCRX509CERTIFICATE pCert, RTCRX509CERTPATHS hCertPaths, uint32_t fFlags,
|
---|
496 | void *pvUser, PRTERRINFO pErrInfo);
|
---|
497 |
|
---|
498 | /**
|
---|
499 | * Verifies PKCS \#7 SignedData.
|
---|
500 | *
|
---|
501 | * For compatability with alternative crypto providers, the user must work on
|
---|
502 | * the top level PKCS \#7 structure instead directly on the SignedData.
|
---|
503 | *
|
---|
504 | * @returns IPRT status code.
|
---|
505 | * @param pContentInfo PKCS \#7 content info structure.
|
---|
506 | * @param fFlags RTCRPKCS7VERIFY_SD_F_XXX.
|
---|
507 | * @param hAdditionalCerts Store containing additional certificates to
|
---|
508 | * supplement those mentioned in the signed data.
|
---|
509 | * @param hTrustedCerts Store containing trusted certificates.
|
---|
510 | * @param pValidationTime The time we're supposed to validate the
|
---|
511 | * certificates chains at. Ignored for signatures
|
---|
512 | * with valid signing time attributes.
|
---|
513 | * @param pfnVerifyCert Callback for checking that a certificate used
|
---|
514 | * for signing the data is suitable.
|
---|
515 | * @param pvUser User argument for the callback.
|
---|
516 | * @param pErrInfo Optional error info buffer.
|
---|
517 | * @sa RTCrPkcs7VerifySignedDataWithExternalData
|
---|
518 | */
|
---|
519 | RTDECL(int) RTCrPkcs7VerifySignedData(PCRTCRPKCS7CONTENTINFO pContentInfo, uint32_t fFlags,
|
---|
520 | RTCRSTORE hAdditionalCerts, RTCRSTORE hTrustedCerts,
|
---|
521 | PCRTTIMESPEC pValidationTime, PFNRTCRPKCS7VERIFYCERTCALLBACK pfnVerifyCert, void *pvUser,
|
---|
522 | PRTERRINFO pErrInfo);
|
---|
523 |
|
---|
524 |
|
---|
525 | /**
|
---|
526 | * Verifies PKCS \#7 SignedData with external data.
|
---|
527 | *
|
---|
528 | * For compatability with alternative crypto providers, the user must work on
|
---|
529 | * the top level PKCS \#7 structure instead directly on the SignedData.
|
---|
530 | *
|
---|
531 | * @returns IPRT status code.
|
---|
532 | * @param pContentInfo PKCS \#7 content info structure.
|
---|
533 | * @param fFlags RTCRPKCS7VERIFY_SD_F_XXX.
|
---|
534 | * @param hAdditionalCerts Store containing additional certificates to
|
---|
535 | * supplement those mentioned in the signed data.
|
---|
536 | * @param hTrustedCerts Store containing trusted certificates.
|
---|
537 | * @param pValidationTime The time we're supposed to validate the
|
---|
538 | * certificates chains at. Ignored for signatures
|
---|
539 | * with valid signing time attributes.
|
---|
540 | * @param pfnVerifyCert Callback for checking that a certificate used
|
---|
541 | * for signing the data is suitable.
|
---|
542 | * @param pvUser User argument for the callback.
|
---|
543 | * @param pvData The signed external data.
|
---|
544 | * @param cbData The size of the signed external data.
|
---|
545 | * @param pErrInfo Optional error info buffer.
|
---|
546 | * @sa RTCrPkcs7VerifySignedData
|
---|
547 | */
|
---|
548 | RTDECL(int) RTCrPkcs7VerifySignedDataWithExternalData(PCRTCRPKCS7CONTENTINFO pContentInfo, uint32_t fFlags,
|
---|
549 | RTCRSTORE hAdditionalCerts, RTCRSTORE hTrustedCerts,
|
---|
550 | PCRTTIMESPEC pValidationTime,
|
---|
551 | PFNRTCRPKCS7VERIFYCERTCALLBACK pfnVerifyCert, void *pvUser,
|
---|
552 | void const *pvData, size_t cbData, PRTERRINFO pErrInfo);
|
---|
553 |
|
---|
554 | /** @name RTCRPKCS7VERIFY_SD_F_XXX - Flags for RTCrPkcs7VerifySignedData
|
---|
555 | * @{ */
|
---|
556 | /** Always use the signing time attribute if present, requiring it to be
|
---|
557 | * verified as valid. The default behavior is to ignore unverifiable
|
---|
558 | * signing time attributes and use the @a pValidationTime instead. */
|
---|
559 | #define RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT RT_BIT_32(0)
|
---|
560 | /** Same as RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT for the MS
|
---|
561 | * timestamp counter sigantures. */
|
---|
562 | #define RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_MS_TIMESTAMP_IF_PRESENT RT_BIT_32(1)
|
---|
563 | /** Only use signging time attributes from counter signatures. */
|
---|
564 | #define RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE_SIGNING_TIME_ONLY RT_BIT_32(2)
|
---|
565 | /** Don't validate the counter signature containing the signing time, just use
|
---|
566 | * it unverified. This is useful if we don't necessarily have the root
|
---|
567 | * certificates for the timestamp server handy, but use with great care.
|
---|
568 | * @sa RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED */
|
---|
569 | #define RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED RT_BIT_32(3)
|
---|
570 | /** Don't validate the MS counter signature containing the signing timestamp.
|
---|
571 | * @sa RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED */
|
---|
572 | #define RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED RT_BIT_32(4)
|
---|
573 | /** Do not consider timestamps in microsoft counter signatures. */
|
---|
574 | #define RTCRPKCS7VERIFY_SD_F_IGNORE_MS_TIMESTAMP RT_BIT_32(5)
|
---|
575 | /** The signed data requires certificates to have the timestamp extended
|
---|
576 | * usage bit present. This is used for recursivly verifying MS timestamp
|
---|
577 | * signatures. */
|
---|
578 | #define RTCRPKCS7VERIFY_SD_F_USAGE_TIMESTAMPING RT_BIT_32(6)
|
---|
579 |
|
---|
580 | /** Indicates internally that we're validating a counter signature and should
|
---|
581 | * use different rules when checking out the authenticated attributes.
|
---|
582 | * @internal */
|
---|
583 | #define RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE RT_BIT_32(31)
|
---|
584 | /** @} */
|
---|
585 |
|
---|
586 | /** @} */
|
---|
587 |
|
---|
588 | RT_C_DECLS_END
|
---|
589 |
|
---|
590 | #endif /* !IPRT_INCLUDED_crypto_pkcs7_h */
|
---|
591 |
|
---|