VirtualBox

source: vbox/trunk/include/iprt/crypto/pkcs7.h@ 95627

最後變更 在這個檔案從95627是 95627,由 vboxsync 提交於 3 年 前

IPRT/RTCrPkcs7: Prototyped some of the setters we generate. bugref:8691

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 31.4 KB
 
1/** @file
2 * IPRT - PKCS \#7, Cryptographic Message Syntax Standard (aka CMS).
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.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
36RT_C_DECLS_BEGIN
37
38struct 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 */
63typedef 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. */
73typedef RTCRPKCS7ISSUERANDSERIALNUMBER *PRTCRPKCS7ISSUERANDSERIALNUMBER;
74/** Pointer to the const IPRT representation of a PKCS \#7
75 * IssuerAndSerialNumber. */
76typedef RTCRPKCS7ISSUERANDSERIALNUMBER const *PCRTCRPKCS7ISSUERANDSERIALNUMBER;
77RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7ISSUERANDSERIALNUMBER, RTDECL, RTCrPkcs7IssuerAndSerialNumber, SeqCore.Asn1Core);
78
79
80/** Pointer to the IPRT representation of a PKCS \#7 SignerInfo. */
81typedef struct RTCRPKCS7SIGNERINFO *PRTCRPKCS7SIGNERINFO;
82/** Pointer to the const IPRT representation of a PKCS \#7 SignerInfo. */
83typedef struct RTCRPKCS7SIGNERINFO const *PCRTCRPKCS7SIGNERINFO;
84RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SIGNERINFOS, RTCRPKCS7SIGNERINFO, RTDECL, RTCrPkcs7SignerInfos);
85
86
87/**
88 * Attribute value type (for the union).
89 */
90typedef 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 */
121typedef 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. */
152typedef RTCRPKCS7ATTRIBUTE *PRTCRPKCS7ATTRIBUTE;
153/** Pointer to the const IPRT representation of a PKCS \#7 Attribute. */
154typedef RTCRPKCS7ATTRIBUTE const *PCRTCRPKCS7ATTRIBUTE;
155RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7ATTRIBUTE, RTDECL, RTCrPkcs7Attribute, SeqCore.Asn1Core);
156
157RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7ATTRIBUTES, RTCRPKCS7ATTRIBUTE, RTDECL, RTCrPkcs7Attributes);
158
159
160/**
161 * One PKCS \#7 SignerInfo (IPRT representation).
162 */
163typedef 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;
188RTASN1TYPE_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 */
242RTDECL(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 */
254RTDECL(PCRTASN1TIME) RTCrPkcs7SignerInfo_GetMsTimestamp(PCRTCRPKCS7SIGNERINFO pThis,
255 struct RTCRPKCS7CONTENTINFO const **ppContentInfoRet);
256
257
258
259/**
260 * PKCS \#7 ContentInfo (IPRT representation).
261 */
262typedef 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. */
310typedef RTCRPKCS7CONTENTINFO *PRTCRPKCS7CONTENTINFO;
311/** Pointer to the const IPRT representation of a PKCS \#7 ContentInfo. */
312typedef RTCRPKCS7CONTENTINFO const *PCRTCRPKCS7CONTENTINFO;
313RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7CONTENTINFO, RTDECL, RTCrPkcs7ContentInfo, SeqCore.Asn1Core);
314RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFCONTENTINFOS, RTCRPKCS7CONTENTINFO, RTDECL, RTCrPkcs7SetOfContentInfos);
315
316RTDECL(bool) RTCrPkcs7ContentInfo_IsSignedData(PCRTCRPKCS7CONTENTINFO pThis);
317
318
319/**
320 * PKCS \#7 Certificate choice.
321 */
322typedef 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 */
339typedef 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. */
363typedef RTCRPKCS7CERT *PRTCRPKCS7CERT;
364/** Pointer to the const IPRT representation of PKCS \#7 or CMS certificate. */
365typedef RTCRPKCS7CERT const *PCRTCRPKCS7CERT;
366RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7CERT, RTDECL, RTCrPkcs7Cert, Dummy.Asn1Core);
367RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFCERTS, RTCRPKCS7CERT, RTDECL, RTCrPkcs7SetOfCerts);
368
369RTDECL(int) RTCrPkcs7Cert_SetX509Cert(PRTCRPKCS7CERT pThis, PCRTCRX509CERTIFICATE pToClone, PCRTASN1ALLOCATORVTABLE pAllocator);
370RTDECL(int) RTCrPkcs7Cert_SetExtendedCert(PRTCRPKCS7CERT pThis, PCRTASN1CORE pToClone, PCRTASN1ALLOCATORVTABLE pAllocator);
371RTDECL(int) RTCrPkcs7Cert_SetAcV1(PRTCRPKCS7CERT pThis, PCRTASN1CORE pToClone, PCRTASN1ALLOCATORVTABLE pAllocator);
372RTDECL(int) RTCrPkcs7Cert_SetAcV2(PRTCRPKCS7CERT pThis, PCRTASN1CORE pToClone, PCRTASN1ALLOCATORVTABLE pAllocator);
373RTDECL(int) RTCrPkcs7Cert_SetOtherCert(PRTCRPKCS7CERT pThis, PCRTASN1CORE pToClone, PCRTASN1ALLOCATORVTABLE pAllocator);
374
375RTDECL(PCRTCRX509CERTIFICATE) RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(PCRTCRPKCS7SETOFCERTS pCertificates,
376 PCRTCRX509NAME pIssuer,
377 PCRTASN1INTEGER pSerialNumber);
378
379
380/**
381 * PKCS \#7 SignedData (IPRT representation).
382 */
383typedef struct RTCRPKCS7SIGNEDDATA
384{
385 /** Sequence core. */
386 RTASN1SEQUENCECORE SeqCore;
387 /** The structure version value (1). */
388 RTASN1INTEGER Version;
389 /** The digest algorithms that are used to signed the content (ContentInfo). */
390 RTCRX509ALGORITHMIDENTIFIERS DigestAlgorithms;
391 /** The content that's being signed. */
392 RTCRPKCS7CONTENTINFO ContentInfo;
393 /** Certificates, optional, implicit tag 0. (Required by Authenticode.) */
394 RTCRPKCS7SETOFCERTS Certificates;
395 /** Certificate revocation lists, optional, implicit tag 1.
396 * Not used by Authenticode, so currently stubbed. */
397 RTASN1CORE Crls;
398 /** Signer infos. */
399 RTCRPKCS7SIGNERINFOS SignerInfos;
400} RTCRPKCS7SIGNEDDATA;
401/** Pointer to the IPRT representation of a PKCS \#7 SignedData. */
402typedef RTCRPKCS7SIGNEDDATA *PRTCRPKCS7SIGNEDDATA;
403/** Pointer to the const IPRT representation of a PKCS \#7 SignedData. */
404typedef RTCRPKCS7SIGNEDDATA const *PCRTCRPKCS7SIGNEDDATA;
405RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7SIGNEDDATA, RTDECL, RTCrPkcs7SignedData, SeqCore.Asn1Core);
406RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFSIGNEDDATA, RTCRPKCS7SIGNEDDATA, RTDECL, RTCrPkcs7SetOfSignedData);
407
408/** PKCS \#7 SignedData object ID. */
409#define RTCRPKCS7SIGNEDDATA_OID RTCR_PKCS7_SIGNED_DATA_OID
410
411/** PKCS \#7 SignedData version number 1. */
412#define RTCRPKCS7SIGNEDDATA_V1 1
413/* No version 2 seems to exist. */
414/** CMS SignedData version number 3.
415 * This should only be used if there are version 1 attribute certificates
416 * present, or if there are version 3 SignerInfo items present, or if
417 * enmcCountInfo is not id-data (RFC-5652, section 5.1). */
418#define RTCRPKCS7SIGNEDDATA_V3 3
419/** CMS SignedData version number 4.
420 * This should only be used if there are version 2 attribute certificates
421 * present (RFC-5652, section 5.1). */
422#define RTCRPKCS7SIGNEDDATA_V4 4
423/** CMS SignedData version number 5.
424 * This should only be used if there are certificates or/and CRLs of the
425 * OTHER type present (RFC-5652, section 5.1). */
426#define RTCRPKCS7SIGNEDDATA_V5 5
427
428RTDECL(int) RTCrPkcs7SignedData_SetCertificates(PRTCRPKCS7SIGNEDDATA pThis, PCRTCRPKCS7SETOFCERTS pCerts, PCRTASN1ALLOCATORVTABLE pAllocator);
429RTDECL(int) RTCrPkcs7SignedData_SetCrls(PRTCRPKCS7SIGNEDDATA pThis, PCRTASN1CORE pCerts, PCRTASN1ALLOCATORVTABLE pAllocator);
430
431/** @name RTCRPKCS7SIGNEDDATA_SANITY_F_XXX - Flags for RTPkcs7SignedDataCheckSantiy.
432 * @{ */
433/** Check for authenticode restrictions. */
434#define RTCRPKCS7SIGNEDDATA_SANITY_F_AUTHENTICODE RT_BIT_32(0)
435/** Check that all the hash algorithms are known to IPRT. */
436#define RTCRPKCS7SIGNEDDATA_SANITY_F_ONLY_KNOWN_HASH RT_BIT_32(1)
437/** Require signing certificate to be present. */
438#define RTCRPKCS7SIGNEDDATA_SANITY_F_SIGNING_CERT_PRESENT RT_BIT_32(2)
439/** @} */
440
441/** PKCS\#7/CMS (content info) markers. */
442extern RTDATADECL(RTCRPEMMARKER const) g_aRTCrPkcs7Markers[];
443/** Number of entries in g_aRTCrPkcs7Markers. */
444extern RTDATADECL(uint32_t const) g_cRTCrPkcs7Markers;
445
446/** @name Flags for RTCrPkcs7ContentInfo_ReadFromBuffer
447 * @{ */
448/** Only allow PEM certificates, not binary ones.
449 * @sa RTCRPEMREADFILE_F_ONLY_PEM */
450#define RTCRPKCS7_READ_F_PEM_ONLY RT_BIT(1)
451/** @} */
452
453RTDECL(int) RTCrPkcs7_ReadFromBuffer(PRTCRPKCS7CONTENTINFO pContentInfo, const void *pvBuf, size_t cbBuf,
454 uint32_t fFlags, PCRTASN1ALLOCATORVTABLE pAllocator,
455 bool *pfCmsLabeled, PRTERRINFO pErrInfo, const char *pszErrorTag);
456
457
458/**
459 * PKCS \#7 DigestInfo (IPRT representation).
460 */
461typedef struct RTCRPKCS7DIGESTINFO
462{
463 /** Sequence core. */
464 RTASN1SEQUENCECORE SeqCore;
465 /** The digest algorithm use to digest the signed content. */
466 RTCRX509ALGORITHMIDENTIFIER DigestAlgorithm;
467 /** The digest. */
468 RTASN1OCTETSTRING Digest;
469} RTCRPKCS7DIGESTINFO;
470/** Pointer to the IPRT representation of a PKCS \#7 DigestInfo object. */
471typedef RTCRPKCS7DIGESTINFO *PRTCRPKCS7DIGESTINFO;
472/** Pointer to the const IPRT representation of a PKCS \#7 DigestInfo object. */
473typedef RTCRPKCS7DIGESTINFO const *PCRTCRPKCS7DIGESTINFO;
474RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7DIGESTINFO, RTDECL, RTCrPkcs7DigestInfo, SeqCore.Asn1Core);
475
476
477/**
478 * Callback function for use with RTCrPkcs7VerifySignedData.
479 *
480 * @returns IPRT status code.
481 * @param pCert The certificate to verify.
482 * @param hCertPaths Unless the certificate is trusted directly, this
483 * is a reference to the certificate path builder
484 * and verifier instance that we used to establish
485 * at least valid trusted path to @a pCert. The
486 * callback can use this to enforce additional
487 * certificate lineage requirements, effective
488 * policy checks and whatnot.
489 * This is NIL_RTCRX509CERTPATHS if the certificate
490 * is directly trusted.
491 * @param fFlags Mix of the RTCRPKCS7VCC_F_XXX flags.
492 * @param pvUser The user argument.
493 * @param pErrInfo Optional error info buffer.
494 */
495typedef DECLCALLBACKTYPE(int, FNRTCRPKCS7VERIFYCERTCALLBACK,(PCRTCRX509CERTIFICATE pCert, RTCRX509CERTPATHS hCertPaths,
496 uint32_t fFlags, void *pvUser, PRTERRINFO pErrInfo));
497/** Pointer to a FNRTCRPKCS7VERIFYCERTCALLBACK callback. */
498typedef FNRTCRPKCS7VERIFYCERTCALLBACK *PFNRTCRPKCS7VERIFYCERTCALLBACK;
499
500/** @name RTCRPKCS7VCC_F_XXX - Flags for FNRTCRPKCS7VERIFYCERTCALLBACK.
501 * @{ */
502/** Normal callback for a direct signatory of the signed data. */
503#define RTCRPKCS7VCC_F_SIGNED_DATA RT_BIT_32(0)
504/** Check that the signatory can be trusted for timestamps. */
505#define RTCRPKCS7VCC_F_TIMESTAMP RT_BIT_32(1)
506/** @} */
507
508/**
509 * @callback_method_impl{FNRTCRPKCS7VERIFYCERTCALLBACK,
510 * Default implementation that checks for the DigitalSignature KeyUsage bit.}
511 */
512RTDECL(int) RTCrPkcs7VerifyCertCallbackDefault(PCRTCRX509CERTIFICATE pCert, RTCRX509CERTPATHS hCertPaths, uint32_t fFlags,
513 void *pvUser, PRTERRINFO pErrInfo);
514
515/**
516 * @callback_method_impl{FNRTCRPKCS7VERIFYCERTCALLBACK,
517 * Standard code signing. Use this for Microsoft SPC.}
518 */
519RTDECL(int) RTCrPkcs7VerifyCertCallbackCodeSigning(PCRTCRX509CERTIFICATE pCert, RTCRX509CERTPATHS hCertPaths, uint32_t fFlags,
520 void *pvUser, PRTERRINFO pErrInfo);
521
522/**
523 * Verifies PKCS \#7 SignedData.
524 *
525 * For compatability with alternative crypto providers, the user must work on
526 * the top level PKCS \#7 structure instead directly on the SignedData.
527 *
528 * @returns IPRT status code.
529 * @param pContentInfo PKCS \#7 content info structure.
530 * @param fFlags RTCRPKCS7VERIFY_SD_F_XXX.
531 * @param hAdditionalCerts Store containing additional certificates to
532 * supplement those mentioned in the signed data.
533 * @param hTrustedCerts Store containing trusted certificates.
534 * @param pValidationTime The time we're supposed to validate the
535 * certificates chains at. Ignored for signatures
536 * with valid signing time attributes.
537 * When RTCRPKCS7VERIFY_SD_F_UPDATE_VALIDATION_TIME
538 * is set, this is updated to the actual validation
539 * time used.
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 pErrInfo Optional error info buffer.
544 * @sa RTCrPkcs7VerifySignedDataWithExternalData
545 */
546RTDECL(int) RTCrPkcs7VerifySignedData(PCRTCRPKCS7CONTENTINFO pContentInfo, uint32_t fFlags,
547 RTCRSTORE hAdditionalCerts, RTCRSTORE hTrustedCerts,
548 PCRTTIMESPEC pValidationTime, PFNRTCRPKCS7VERIFYCERTCALLBACK pfnVerifyCert, void *pvUser,
549 PRTERRINFO pErrInfo);
550
551
552/**
553 * Verifies PKCS \#7 SignedData with external data.
554 *
555 * For compatability with alternative crypto providers, the user must work on
556 * the top level PKCS \#7 structure instead directly on the SignedData.
557 *
558 * @returns IPRT status code.
559 * @param pContentInfo PKCS \#7 content info structure.
560 * @param fFlags RTCRPKCS7VERIFY_SD_F_XXX.
561 * @param hAdditionalCerts Store containing additional certificates to
562 * supplement those mentioned in the signed data.
563 * @param hTrustedCerts Store containing trusted certificates.
564 * @param pValidationTime The time we're supposed to validate the
565 * certificates chains at. Ignored for signatures
566 * with valid signing time attributes.
567 * When RTCRPKCS7VERIFY_SD_F_UPDATE_VALIDATION_TIME
568 * is set, this is updated to the actual validation
569 * time used.
570 * @param pfnVerifyCert Callback for checking that a certificate used
571 * for signing the data is suitable.
572 * @param pvUser User argument for the callback.
573 * @param pvData The signed external data.
574 * @param cbData The size of the signed external data.
575 * @param pErrInfo Optional error info buffer.
576 * @sa RTCrPkcs7VerifySignedData
577 */
578RTDECL(int) RTCrPkcs7VerifySignedDataWithExternalData(PCRTCRPKCS7CONTENTINFO pContentInfo, uint32_t fFlags,
579 RTCRSTORE hAdditionalCerts, RTCRSTORE hTrustedCerts,
580 PCRTTIMESPEC pValidationTime,
581 PFNRTCRPKCS7VERIFYCERTCALLBACK pfnVerifyCert, void *pvUser,
582 void const *pvData, size_t cbData, PRTERRINFO pErrInfo);
583
584/** @name RTCRPKCS7VERIFY_SD_F_XXX - Flags for RTCrPkcs7VerifySignedData and
585 * RTCrPkcs7VerifySignedDataWithExternalData
586 * @{ */
587/** Always use the signing time attribute if present, requiring it to be
588 * verified as valid. The default behavior is to ignore unverifiable
589 * signing time attributes and use the @a pValidationTime instead. */
590#define RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT RT_BIT_32(0)
591/** Same as RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT for the MS
592 * timestamp counter signatures. */
593#define RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_MS_TIMESTAMP_IF_PRESENT RT_BIT_32(1)
594/** Only use signing time attributes from counter signatures. */
595#define RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE_SIGNING_TIME_ONLY RT_BIT_32(2)
596/** Don't validate the counter signature containing the signing time, just use
597 * it unverified. This is useful if we don't necessarily have the root
598 * certificates for the timestamp server handy, but use with great care.
599 * @sa RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED */
600#define RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED RT_BIT_32(3)
601/** Don't validate the MS counter signature containing the signing timestamp.
602 * @sa RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED */
603#define RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED RT_BIT_32(4)
604/** Do not consider timestamps in microsoft counter signatures. */
605#define RTCRPKCS7VERIFY_SD_F_IGNORE_MS_TIMESTAMP RT_BIT_32(5)
606/** The signed data requires certificates to have the timestamp extended
607 * usage bit present. This is used for recursivly verifying MS timestamp
608 * signatures. */
609#define RTCRPKCS7VERIFY_SD_F_USAGE_TIMESTAMPING RT_BIT_32(6)
610/** Skip the verification of the certificate trust paths, taking all
611 * certificates to be trustworthy. */
612#define RTCRPKCS7VERIFY_SD_F_TRUST_ALL_CERTS RT_BIT_32(7)
613/** Update @a pValidationTime with the actual validation time used.
614 * This requires RTCRPKCS7VERIFY_SD_F_HAS_SIGNER_INDEX to get a consistent
615 * result. And yeah, it unconst the parameter, which is patently ugly. */
616#define RTCRPKCS7VERIFY_SD_F_UPDATE_VALIDATION_TIME RT_BIT_32(8)
617/** Check trust anchors (@sa RTCrX509CertPathsSetTrustAnchorChecks). */
618#define RTCRPKCS7VERIFY_SD_F_CHECK_TRUST_ANCHORS RT_BIT_32(9)
619
620/** This can be used to only verify one given signer info.
621 * Max index value is 15. */
622#define RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX(a_idxSignerInfo) \
623 ( RTCRPKCS7VERIFY_SD_F_HAS_SIGNER_INDEX \
624 | (((a_idxSignerInfo) & RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_MAX) << RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_SHIFT) )
625/** Has a valid value in RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_MASK. */
626#define RTCRPKCS7VERIFY_SD_F_HAS_SIGNER_INDEX RT_BIT_32(23)
627/** Signer index shift value. */
628#define RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_SHIFT 24
629/** Signer index mask. */
630#define RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_MASK UINT32_C(0x0f000000)
631/** Max signer index value (inclusive). */
632#define RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_MAX \
633 (RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_MASK >> RTCRPKCS7VERIFY_SD_F_SIGNER_INDEX_SHIFT)
634
635/** Indicates internally that we're validating a counter signature and should
636 * use different rules when checking out the authenticated attributes.
637 * @internal */
638#define RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE RT_BIT_32(31)
639/** @} */
640
641
642RTDECL(int) RTCrPkcs7SimpleSignSignedData(uint32_t fFlags, PCRTCRX509CERTIFICATE pSigner, RTCRKEY hPrivateKey,
643 void const *pvData, size_t cbData, RTDIGESTTYPE enmDigestType,
644 RTCRSTORE hAdditionalCerts, PCRTCRPKCS7ATTRIBUTES pAdditionalAuthenticatedAttribs,
645 void *pvResult, size_t *pcbResult, PRTERRINFO pErrInfo);
646
647/** @name RTCRPKCS7SIGN_SD_F_XXX - Flags for RTCrPkcs7SimpleSign.
648 * @{ */
649/** Detached data. */
650#define RTCRPKCS7SIGN_SD_F_DEATCHED RT_BIT_32(0)
651/** No SMIME capabilities attribute. */
652#define RTCRPKCS7SIGN_SD_F_NO_SMIME_CAP RT_BIT_32(1)
653/** Valid flag mask. */
654#define RTCRPKCS7SIGN_SD_F_VALID_MASK UINT32_C(0x00000003)
655/** @} */
656
657/** @} */
658
659RT_C_DECLS_END
660
661#endif /* !IPRT_INCLUDED_crypto_pkcs7_h */
662
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette