]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/Pkcs7Verify.h
7b3454ec3a716c027179b9d7bfdab51810a7516b
[mirror_edk2.git] / MdePkg / Include / Protocol / Pkcs7Verify.h
1 /** @file
2 EFI_PKCS7_VERIFY_PROTOCOL as defined in UEFI 2.5.
3 The EFI_PKCS7_VERIFY_PROTOCOL is used to verify data signed using PKCS#7
4 formatted authentication. The PKCS#7 data to be verified must be binary
5 DER encoded.
6 PKCS#7 is a general-purpose cryptographic standard (defined by RFC2315,
7 available at http://tools.ietf.org/html/rfc2315).
8
9 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 #ifndef __EFI_PKCS7_VERIFY_PROTOCOL_H__
15 #define __EFI_PKCS7_VERIFY_PROTOCOL_H__
16
17 #include <Guid/ImageAuthentication.h>
18
19 ///
20 /// Global ID for the PKCS7 Verification Protocol
21 ///
22 #define EFI_PKCS7_VERIFY_PROTOCOL_GUID \
23 { \
24 0x47889fb2, 0xd671, 0x4fab, {0xa0, 0xca, 0xdf, 0x0e, 0x44, 0xdf, 0x70, 0xd6 } \
25 }
26
27 typedef struct _EFI_PKCS7_VERIFY_PROTOCOL EFI_PKCS7_VERIFY_PROTOCOL;
28
29
30 /**
31 Processes a buffer containing binary DER-encoded PKCS7 signature.
32 The signed data content may be embedded within the buffer or separated. Funtion
33 verifies the signature of the content is valid and signing certificate was not
34 revoked and is contained within a list of trusted signers.
35
36 @param[in] This Pointer to EFI_PKCS7_VERIFY_PROTOCOL instance.
37 @param[in] SignedData Points to buffer containing ASN.1 DER-encoded PKCS7
38 signature.
39 @param[in] SignedDataSize The size of SignedData buffer in bytes.
40 @param[in] InData In case of detached signature, InData points to
41 buffer containing the raw message data previously
42 signed and to be verified by function. In case of
43 SignedData containing embedded data, InData must be
44 NULL.
45 @param[in] InDataSize When InData is used, the size of InData buffer in
46 bytes. When InData is NULL. This parameter must be
47 0.
48 @param[in] AllowedDb Pointer to a list of pointers to EFI_SIGNATURE_LIST
49 structures. The list is terminated by a null
50 pointer. The EFI_SIGNATURE_LIST structures contain
51 lists of X.509 certificates of approved signers.
52 Function recognizes signer certificates of type
53 EFI_CERT_X509_GUID. Any hash certificate in AllowedDb
54 list is ignored by this function. Function returns
55 success if signer of the buffer is within this list
56 (and not within RevokedDb). This parameter is
57 required.
58 @param[in] RevokedDb Optional pointer to a list of pointers to
59 EFI_SIGNATURE_LIST structures. The list is terminated
60 by a null pointer. List of X.509 certificates of
61 revoked signers and revoked file hashes. Except as
62 noted in description of TimeStampDb signature
63 verification will always fail if the signer of the
64 file or the hash of the data component of the buffer
65 is in RevokedDb list. This list is optional and
66 caller may pass Null or pointer to NULL if not
67 required.
68 @param[in] TimeStampDb Optional pointer to a list of pointers to
69 EFI_SIGNATURE_LIST structures. The list is terminated
70 by a null pointer. This parameter can be used to pass
71 a list of X.509 certificates of trusted time stamp
72 signers. This list is optional and caller must pass
73 Null or pointer to NULL if not required.
74 @param[out] Content On input, points to an optional caller-allocated
75 buffer into which the function will copy the content
76 portion of the file after verification succeeds.
77 This parameter is optional and if NULL, no copy of
78 content from file is performed.
79 @param[in,out] ContentSize On input, points to the size in bytes of the optional
80 buffer Content previously allocated by caller. On
81 output, if the verification succeeds, the value
82 referenced by ContentSize will contain the actual
83 size of the content from signed file. If ContentSize
84 indicates the caller-allocated buffer is too small
85 to contain content, an error is returned, and
86 ContentSize will be updated with the required size.
87 This parameter must be 0 if Content is Null.
88
89 @retval EFI_SUCCESS Content signature was verified against hash of
90 content, the signer's certificate was not found in
91 RevokedDb, and was found in AllowedDb or if in signer
92 is found in both AllowedDb and RevokedDb, the
93 signing was allowed by reference to TimeStampDb as
94 described above, and no hash matching content hash
95 was found in RevokedDb.
96 @retval EFI_SECURITY_VIOLATION The SignedData buffer was correctly formatted but
97 signer was in RevokedDb or not in AllowedDb. Also
98 returned if matching content hash found in RevokedDb.
99 @retval EFI_COMPROMISED_DATA Calculated hash differs from signed hash.
100 @retval EFI_INVALID_PARAMETER SignedData is NULL or SignedDataSize is zero.
101 AllowedDb is NULL.
102 @retval EFI_INVALID_PARAMETER Content is not NULL and ContentSize is NULL.
103 @retval EFI_ABORTED Unsupported or invalid format in TimeStampDb,
104 RevokedDb or AllowedDb list contents was detected.
105 @retval EFI_NOT_FOUND Content not found because InData is NULL and no
106 content embedded in SignedData.
107 @retval EFI_UNSUPPORTED The SignedData buffer was not correctly formatted
108 for processing by the function.
109 @retval EFI_UNSUPPORTED Signed data embedded in SignedData but InData is not
110 NULL.
111 @retval EFI_BUFFER_TOO_SMALL The size of buffer indicated by ContentSize is too
112 small to hold the content. ContentSize updated to
113 required size.
114
115 **/
116 typedef
117 EFI_STATUS
118 (EFIAPI *EFI_PKCS7_VERIFY_BUFFER) (
119 IN EFI_PKCS7_VERIFY_PROTOCOL *This,
120 IN VOID *SignedData,
121 IN UINTN SignedDataSize,
122 IN VOID *InData OPTIONAL,
123 IN UINTN InDataSize,
124 IN EFI_SIGNATURE_LIST **AllowedDb,
125 IN EFI_SIGNATURE_LIST **RevokedDb OPTIONAL,
126 IN EFI_SIGNATURE_LIST **TimeStampDb OPTIONAL,
127 OUT VOID *Content OPTIONAL,
128 IN OUT UINTN *ContentSize
129 );
130
131 /**
132 Processes a buffer containing binary DER-encoded detached PKCS7 signature.
133 The hash of the signed data content is calculated and passed by the caller. Function
134 verifies the signature of the content is valid and signing certificate was not revoked
135 and is contained within a list of trusted signers.
136
137 Note: because this function uses hashes and the specification contains a variety of
138 hash choices, you should be aware that the check against the RevokedDb list
139 will improperly succeed if the signature is revoked using a different hash
140 algorithm. For this reason, you should either cycle through all UEFI supported
141 hashes to see if one is forbidden, or rely on a single hash choice only if the
142 UEFI signature authority only signs and revokes with a single hash (at time
143 of writing, this hash choice is SHA256).
144
145 @param[in] This Pointer to EFI_PKCS7_VERIFY_PROTOCOL instance.
146 @param[in] Signature Points to buffer containing ASN.1 DER-encoded PKCS
147 detached signature.
148 @param[in] SignatureSize The size of Signature buffer in bytes.
149 @param[in] InHash InHash points to buffer containing the caller
150 calculated hash of the data. The parameter may not
151 be NULL.
152 @param[in] InHashSize The size in bytes of InHash buffer.
153 @param[in] AllowedDb Pointer to a list of pointers to EFI_SIGNATURE_LIST
154 structures. The list is terminated by a null
155 pointer. The EFI_SIGNATURE_LIST structures contain
156 lists of X.509 certificates of approved signers.
157 Function recognizes signer certificates of type
158 EFI_CERT_X509_GUID. Any hash certificate in AllowedDb
159 list is ignored by this function. Function returns
160 success if signer of the buffer is within this list
161 (and not within RevokedDb). This parameter is
162 required.
163 @param[in] RevokedDb Optional pointer to a list of pointers to
164 EFI_SIGNATURE_LIST structures. The list is terminated
165 by a null pointer. List of X.509 certificates of
166 revoked signers and revoked file hashes. Signature
167 verification will always fail if the signer of the
168 file or the hash of the data component of the buffer
169 is in RevokedDb list. This parameter is optional
170 and caller may pass Null if not required.
171 @param[in] TimeStampDb Optional pointer to a list of pointers to
172 EFI_SIGNATURE_LIST structures. The list is terminated
173 by a null pointer. This parameter can be used to pass
174 a list of X.509 certificates of trusted time stamp
175 counter-signers.
176
177 @retval EFI_SUCCESS Signed hash was verified against caller-provided
178 hash of content, the signer's certificate was not
179 found in RevokedDb, and was found in AllowedDb or
180 if in signer is found in both AllowedDb and
181 RevokedDb, the signing was allowed by reference to
182 TimeStampDb as described above, and no hash matching
183 content hash was found in RevokedDb.
184 @retval EFI_SECURITY_VIOLATION The SignedData buffer was correctly formatted but
185 signer was in RevokedDb or not in AllowedDb. Also
186 returned if matching content hash found in RevokedDb.
187 @retval EFI_COMPROMISED_DATA Caller provided hash differs from signed hash. Or,
188 caller and encrypted hash are different sizes.
189 @retval EFI_INVALID_PARAMETER Signature is NULL or SignatureSize is zero. InHash
190 is NULL or InHashSize is zero. AllowedDb is NULL.
191 @retval EFI_ABORTED Unsupported or invalid format in TimeStampDb,
192 RevokedDb or AllowedDb list contents was detected.
193 @retval EFI_UNSUPPORTED The Signature buffer was not correctly formatted
194 for processing by the function.
195
196 **/
197 typedef
198 EFI_STATUS
199 (EFIAPI *EFI_PKCS7_VERIFY_SIGNATURE) (
200 IN EFI_PKCS7_VERIFY_PROTOCOL *This,
201 IN VOID *Signature,
202 IN UINTN SignatureSize,
203 IN VOID *InHash,
204 IN UINTN InHashSize,
205 IN EFI_SIGNATURE_LIST **AllowedDb,
206 IN EFI_SIGNATURE_LIST **RevokedDb OPTIONAL,
207 IN EFI_SIGNATURE_LIST **TimeStampDb OPTIONAL
208 );
209
210 ///
211 /// The EFI_PKCS7_VERIFY_PROTOCOL is used to verify data signed using PKCS7
212 /// structure. The PKCS7 data to be verified must be ASN.1 (DER) encoded.
213 /// SHA256 must be supported as digest algorithm with RSA digest encryption.
214 /// Support of other hash algorithms is optional.
215 ///
216 struct _EFI_PKCS7_VERIFY_PROTOCOL {
217 EFI_PKCS7_VERIFY_BUFFER VerifyBuffer;
218 EFI_PKCS7_VERIFY_SIGNATURE VerifySignature;
219 };
220
221 extern EFI_GUID gEfiPkcs7VerifyProtocolGuid;
222
223 #endif