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