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