File shim-bsc1177315-verify-eku-codesign.patch of Package shim
697
1
From 6ff890bf0af9d37acc6ea8ad64f597060e8bb143 Mon Sep 17 00:00:00 2001
2
From: Gary Lin <glin@suse.com>
3
Date: Wed, 14 Oct 2020 14:31:12 +0800
4
Subject: [PATCH] Enforce EKU CodeSign extension check
5
6
Per NIAP OS_PP, the signer certificate of the UEFI image has to contain
7
"CodeSign" extension in its Extended Key Usage(EKU).
8
9
This commit borrows VerifyEKUsInPkcs7Signature() from edk2 and enforces
10
the CodeSign check in Pkcs7Verify().
11
+ Also merged the buffer use-after-free fix (*)
12
13
(*) https://bugzilla.tianocore.org/show_bug.cgi?id=2459
14
15
Signed-off-by: Gary Lin <glin@suse.com>
16
---
17
Cryptlib/InternalCryptLib.h | 32 ++
18
Cryptlib/Library/BaseCryptLib.h | 40 +++
19
Cryptlib/Makefile | 1 +
20
Cryptlib/Pk/CryptPkcs7Verify.c | 10 +
21
Cryptlib/Pk/CryptPkcs7VerifyEku.c | 516 ++++++++++++++++++++++++++++++
22
5 files changed, 599 insertions(+)
23
create mode 100644 Cryptlib/Pk/CryptPkcs7VerifyEku.c
24
25
diff --git a/Cryptlib/InternalCryptLib.h b/Cryptlib/InternalCryptLib.h
26
index e9a4c20..8c9a2a4 100644
27
--- a/Cryptlib/InternalCryptLib.h
28
+++ b/Cryptlib/InternalCryptLib.h
29
30
#define OBJ_length(o) ((o)->length)
31
#endif
32
33
+/**
34
+ Check input P7Data is a wrapped ContentInfo structure or not. If not construct
35
+ a new structure to wrap P7Data.
36
+
37
+ Caution: This function may receive untrusted input.
38
+ UEFI Authenticated Variable is external input, so this function will do basic
39
+ check for PKCS#7 data structure.
40
+
41
+ @param[in] P7Data Pointer to the PKCS#7 message to verify.
42
+ @param[in] P7Length Length of the PKCS#7 message in bytes.
43
+ @param[out] WrapFlag If TRUE P7Data is a ContentInfo structure, otherwise
44
+ return FALSE.
45
+ @param[out] WrapData If return status of this function is TRUE:
46
+ 1) when WrapFlag is TRUE, pointer to P7Data.
47
+ 2) when WrapFlag is FALSE, pointer to a new ContentInfo
48
+ structure. It's caller's responsibility to free this
49
+ buffer.
50
+ @param[out] WrapDataSize Length of ContentInfo structure in bytes.
51
+
52
+ @retval TRUE The operation is finished successfully.
53
+ @retval FALSE The operation is failed due to lack of resources.
54
+
55
+**/
56
+BOOLEAN
57
+WrapPkcs7Data (
58
+ IN CONST UINT8 *P7Data,
59
+ IN UINTN P7Length,
60
+ OUT BOOLEAN *WrapFlag,
61
+ OUT UINT8 **WrapData,
62
+ OUT UINTN *WrapDataSize
63
+ );
64
+
65
#endif
66
67
diff --git a/Cryptlib/Library/BaseCryptLib.h b/Cryptlib/Library/BaseCryptLib.h
68
index 2df8bd2..ed482d3 100644
69
--- a/Cryptlib/Library/BaseCryptLib.h
70
+++ b/Cryptlib/Library/BaseCryptLib.h
71
72
IN UINTN DataLength
73
);
74
75
+/**
76
+ This function receives a PKCS#7 formatted signature blob,
77
+ looks for the EKU SEQUENCE blob, and if found then looks
78
+ for all the required EKUs. This function was created so that
79
+ the Surface team can cut down on the number of Certificate
80
+ Authorities (CA's) by checking EKU's on leaf signers for
81
+ a specific product. This prevents one product's certificate
82
+ from signing another product's firmware or unlock blobs.
83
+
84
+ Note that this function does not validate the certificate chain.
85
+ That needs to be done before using this function.
86
+
87
+ @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
88
+ containing the content block with both the signature,
89
+ the signer's certificate, and any necessary intermediate
90
+ certificates.
91
+ @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
92
+ @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
93
+ required EKUs that must be present in the signature.
94
+ @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
95
+ @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
96
+ must be present in the leaf signer. If it is
97
+ FALSE, then we will succeed if we find any
98
+ of the specified EKU's.
99
+
100
+ @retval EFI_SUCCESS The required EKUs were found in the signature.
101
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
102
+ @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
103
+
104
+**/
105
+EFI_STATUS
106
+EFIAPI
107
+VerifyEKUsInPkcs7Signature (
108
+ IN CONST UINT8 *Pkcs7Signature,
109
+ IN CONST UINT32 SignatureSize,
110
+ IN CONST CHAR8 *RequiredEKUs[],
111
+ IN CONST UINT32 RequiredEKUsSize,
112
+ IN BOOLEAN RequireAllPresent
113
+ );
114
+
115
/**
116
Extracts the attached content from a PKCS#7 signed data if existed. The input signed
117
data could be wrapped in a ContentInfo structure.
118
diff --git a/Cryptlib/Makefile b/Cryptlib/Makefile
119
index 18a33b1..a1d8b02 100644
120
--- a/Cryptlib/Makefile
121
+++ b/Cryptlib/Makefile
122
123
Pk/CryptRsaExtNull.o \
124
Pk/CryptPkcs7SignNull.o \
125
Pk/CryptPkcs7Verify.o \
126
+ Pk/CryptPkcs7VerifyEku.o \
127
Pk/CryptDhNull.o \
128
Pk/CryptTs.o \
129
Pk/CryptX509.o \
130
diff --git a/Cryptlib/Pk/CryptPkcs7Verify.c b/Cryptlib/Pk/CryptPkcs7Verify.c
131
index 09895d8..da15be2 100644
132
--- a/Cryptlib/Pk/CryptPkcs7Verify.c
133
+++ b/Cryptlib/Pk/CryptPkcs7Verify.c
134
135
#include <openssl/pkcs7.h>
136
137
UINT8 mOidValue[9] = { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02 };
138
+/* EKU CodeSign */
139
+CHAR8 mOidCodeSign[] = "1.3.6.1.5.5.7.3.3";
140
141
#if 1
142
#if OPENSSL_VERSION_NUMBER < 0x10100000L
143
144
CONST UINT8 *Temp;
145
UINTN SignedDataSize;
146
BOOLEAN Wrapped;
147
+ CONST CHAR8 *Ekus[1];
148
+ EFI_STATUS EFI_Status;
149
150
//
151
// Check input parameters.
152
153
DataBio = NULL;
154
Cert = NULL;
155
CertStore = NULL;
156
+ Ekus[0] = mOidCodeSign;
157
158
//
159
// Register & Initialize necessary digest algorithms for PKCS#7 Handling
160
161
//
162
X509_STORE_set_purpose (CertStore, X509_PURPOSE_ANY);
163
164
+ EFI_Status = VerifyEKUsInPkcs7Signature(P7Data, P7Length, Ekus, 1, TRUE);
165
+ if (EFI_Status != EFI_SUCCESS) {
166
+ goto _Exit;
167
+ }
168
+
169
//
170
// Verifies the PKCS#7 signedData structure
171
//
172
diff --git a/Cryptlib/Pk/CryptPkcs7VerifyEku.c b/Cryptlib/Pk/CryptPkcs7VerifyEku.c
173
new file mode 100644
174
index 0000000..2c172e2
175
--- /dev/null
176
+++ b/Cryptlib/Pk/CryptPkcs7VerifyEku.c
177
178
+/** @file
179
+ This module verifies that Enhanced Key Usages (EKU's) are present within
180
+ a PKCS7 signature blob using OpenSSL.
181
+
182
+ Copyright (C) Microsoft Corporation. All Rights Reserved.
183
+ Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
184
+
185
+ SPDX-License-Identifier: BSD-2-Clause-Patent
186
+
187
+**/
188
+
189
+#include <Base.h>
190
+#include "InternalCryptLib.h"
191
+#include <openssl/x509v3.h>
192
+#include <openssl/asn1.h>
193
+#include <openssl/x509.h>
194
+#include <openssl/bio.h>
195
+#include <openssl/x509.h>
196
+#include <openssl/pkcs7.h>
197
+#include <openssl/bn.h>
198
+#include <openssl/x509_vfy.h>
199
+#include <openssl/pem.h>
200
+#include <openssl/evp.h>
201
+#include <openssl/asn1.h>
202
+
203
+/**
204
+ This function will return the leaf signer certificate in a chain. This is
205
+ required because certificate chains are not guaranteed to have the
206
+ certificates in the order that they were issued.
207
+
208
+ A typical certificate chain looks like this:
209
+
210
+
211
+ ----------------------------
212
+ | Root |
213
+ ----------------------------
214
+ ^
215
+ |
216
+ ----------------------------
217
+ | Policy CA | <-- Typical Trust Anchor.
218
+ ----------------------------
219
+ ^
220
+ |
221
+ ----------------------------
222
+ | Issuing CA |
223
+ ----------------------------
224
+ ^
225
+ |
226
+ -----------------------------
227
+ / End-Entity (leaf) signer / <-- Bottom certificate.
228
+ ----------------------------- EKU: "1.3.6.1.4.1.311.76.9.21.1"
229
+ (Firmware Signing)
230
+
231
+
232
+ @param[in] CertChain Certificate chain.
233
+
234
+ @param[out] SignerCert Last certificate in the chain. For PKCS7 signatures,
235
+ this will be the end-entity (leaf) signer cert.
236
+
237
+ @retval EFI_SUCCESS The required EKUs were found in the signature.
238
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
239
+ @retval EFI_NOT_FOUND The number of signers found was not 1.
240
+
241
+**/
242
+EFI_STATUS
243
+GetSignerCertificate (
244
+ IN CONST PKCS7 *CertChain,
245
+ OUT X509 **SignerCert
246
+ )
247
+{
248
+ EFI_STATUS Status;
249
+ STACK_OF(X509) *Signers;
250
+ INT32 NumberSigners;
251
+
252
+ Status = EFI_SUCCESS;
253
+ Signers = NULL;
254
+ NumberSigners = 0;
255
+
256
+ if (CertChain == NULL || SignerCert == NULL) {
257
+ Status = EFI_INVALID_PARAMETER;
258
+ goto Exit;
259
+ }
260
+
261
+ //
262
+ // Get the signers from the chain.
263
+ //
264
+ Signers = PKCS7_get0_signers ((PKCS7*) CertChain, NULL, PKCS7_BINARY);
265
+ if (Signers == NULL) {
266
+ //
267
+ // Fail to get signers form PKCS7
268
+ //
269
+ Status = EFI_INVALID_PARAMETER;
270
+ goto Exit;
271
+ }
272
+
273
+ //
274
+ // There should only be one signer in the PKCS7 stack.
275
+ //
276
+ NumberSigners = sk_X509_num (Signers);
277
+ if (NumberSigners != 1) {
278
+ //
279
+ // The number of singers should have been 1
280
+ //
281
+ Status = EFI_NOT_FOUND;
282
+ goto Exit;
283
+ }
284
+
285
+ *SignerCert = sk_X509_value (Signers, 0);
286
+
287
+Exit:
288
+ //
289
+ // Release Resources
290
+ //
291
+ if (Signers != NULL) {
292
+ sk_X509_free (Signers);
293
+ }
294
+
295
+ return Status;
296
+}
297
+
298
+
299
+/**
300
+ Determines if the specified EKU represented in ASN1 form is present
301
+ in a given certificate.
302
+
303
+ @param[in] Cert The certificate to check.
304
+
305
+ @param[in] Asn1ToFind The EKU to look for.
306
+
307
+ @retval EFI_SUCCESS We successfully identified the signing type.
308
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
309
+ @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
310
+
311
+**/
312
+EFI_STATUS
313
+IsEkuInCertificate (
314
+ IN CONST X509 *Cert,
315
+ IN ASN1_OBJECT *Asn1ToFind
316
+ )
317
+{
318
+ EFI_STATUS Status;
319
+ X509 *ClonedCert;
320
+ X509_EXTENSION *Extension;
321
+ EXTENDED_KEY_USAGE *Eku;
322
+ INT32 ExtensionIndex;
323
+ INTN NumExtensions;
324
+ ASN1_OBJECT *Asn1InCert;
325
+ INTN Index;
326
+
327
+ Status = EFI_NOT_FOUND;
328
+ ClonedCert = NULL;
329
+ Extension = NULL;
330
+ Eku = NULL;
331
+ ExtensionIndex = -1;
332
+ NumExtensions = 0;
333
+ Asn1InCert = NULL;
334
+
335
+ if (Cert == NULL || Asn1ToFind == NULL) {
336
+ Status = EFI_INVALID_PARAMETER;
337
+ goto Exit;
338
+ }
339
+
340
+ //
341
+ // Clone the certificate. This is required because the Extension API's
342
+ // only work once per instance of an X509 object.
343
+ //
344
+ ClonedCert = X509_dup ((X509*)Cert);
345
+ if (ClonedCert == NULL) {
346
+ //
347
+ // Fail to duplicate cert.
348
+ //
349
+ Status = EFI_INVALID_PARAMETER;
350
+ goto Exit;
351
+ }
352
+
353
+ //
354
+ // Look for the extended key usage.
355
+ //
356
+ ExtensionIndex = X509_get_ext_by_NID (ClonedCert, NID_ext_key_usage, -1);
357
+
358
+ if (ExtensionIndex < 0) {
359
+ //
360
+ // Fail to find 'NID_ext_key_usage' in Cert.
361
+ //
362
+ goto Exit;
363
+ }
364
+
365
+ Extension = X509_get_ext (ClonedCert, ExtensionIndex);
366
+ if (Extension == NULL) {
367
+ //
368
+ // Fail to get Extension form cert.
369
+ //
370
+ goto Exit;
371
+ }
372
+
373
+ Eku = (EXTENDED_KEY_USAGE*)X509V3_EXT_d2i (Extension);
374
+ if (Eku == NULL) {
375
+ //
376
+ // Fail to get Eku from extension.
377
+ //
378
+ goto Exit;
379
+ }
380
+
381
+ NumExtensions = sk_ASN1_OBJECT_num (Eku);
382
+
383
+ //
384
+ // Now loop through the extensions, looking for the specified Eku.
385
+ //
386
+ for (Index = 0; Index < NumExtensions; Index++) {
387
+ Asn1InCert = sk_ASN1_OBJECT_value (Eku, (INT32)Index);
388
+ if (Asn1InCert == NULL) {
389
+ //
390
+ // Fail to get ASN object from Eku.
391
+ //
392
+ goto Exit;
393
+ }
394
+
395
+ if (OBJ_cmp(Asn1InCert, Asn1ToFind) == 0) {
396
+ //
397
+ // Found Eku in certificate.
398
+ //
399
+ Status = EFI_SUCCESS;
400
+ goto Exit;
401
+ }
402
+ }
403
+
404
+Exit:
405
+
406
+ //
407
+ // Release Resources
408
+ //
409
+ if (ClonedCert != NULL) {
410
+ X509_free (ClonedCert);
411
+ }
412
+
413
+ if (Eku != NULL) {
414
+ sk_ASN1_OBJECT_pop_free (Eku, ASN1_OBJECT_free);
415
+ }
416
+
417
+ return Status;
418
+}
419
+
420
+
421
+/**
422
+ Determines if the specified EKUs are present in a signing certificate.
423
+
424
+ @param[in] SignerCert The certificate to check.
425
+ @param[in] RequiredEKUs The EKUs to look for.
426
+ @param[in] RequiredEKUsSize The number of EKUs
427
+ @param[in] RequireAllPresent If TRUE, then all the specified EKUs
428
+ must be present in the certificate.
429
+
430
+ @retval EFI_SUCCESS We successfully identified the signing type.
431
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
432
+ @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
433
+**/
434
+EFI_STATUS
435
+CheckEKUs(
436
+ IN CONST X509 *SignerCert,
437
+ IN CONST CHAR8 *RequiredEKUs[],
438
+ IN CONST UINT32 RequiredEKUsSize,
439
+ IN BOOLEAN RequireAllPresent
440
+ )
441
+{
442
+ EFI_STATUS Status;
443
+ ASN1_OBJECT *Asn1ToFind;
444
+ UINT32 NumEkusFound;
445
+ UINT32 Index;
446
+
447
+ Status = EFI_NOT_FOUND;
448
+ Asn1ToFind = NULL;
449
+ NumEkusFound = 0;
450
+
451
+ if (SignerCert == NULL || RequiredEKUs == NULL || RequiredEKUsSize == 0) {
452
+ Status = EFI_INVALID_PARAMETER;
453
+ goto Exit;
454
+ }
455
+
456
+ for (Index = 0; Index < RequiredEKUsSize; Index++) {
457
+ //
458
+ // Finding required EKU in cert.
459
+ //
460
+ if (Asn1ToFind != NULL) {
461
+ ASN1_OBJECT_free(Asn1ToFind);
462
+ Asn1ToFind = NULL;
463
+ }
464
+
465
+ Asn1ToFind = OBJ_txt2obj (RequiredEKUs[Index], 0);
466
+ if (Asn1ToFind == NULL) {
467
+ //
468
+ // Fail to convert required EKU to ASN1.
469
+ //
470
+ Status = EFI_INVALID_PARAMETER;
471
+ goto Exit;
472
+ }
473
+
474
+ Status = IsEkuInCertificate (SignerCert, Asn1ToFind);
475
+ if (Status == EFI_SUCCESS) {
476
+ NumEkusFound++;
477
+ if (!RequireAllPresent) {
478
+ //
479
+ // Found at least one, so we are done.
480
+ //
481
+ goto Exit;
482
+ }
483
+ } else {
484
+ //
485
+ // Fail to find Eku in cert
486
+ break;
487
+ }
488
+ }
489
+
490
+Exit:
491
+
492
+ if (Asn1ToFind != NULL) {
493
+ ASN1_OBJECT_free(Asn1ToFind);
494
+ }
495
+
496
+ if (RequireAllPresent &&
497
+ NumEkusFound == RequiredEKUsSize) {
498
+ //
499
+ // Found all required EKUs in certificate.
500
+ //
501
+ Status = EFI_SUCCESS;
502
+ }
503
+
504
+ return Status;
505
+}
506
+
507
+/**
508
+ This function receives a PKCS#7 formatted signature blob,
509
+ looks for the EKU SEQUENCE blob, and if found then looks
510
+ for all the required EKUs. This function was created so that
511
+ the Surface team can cut down on the number of Certificate
512
+ Authorities (CA's) by checking EKU's on leaf signers for
513
+ a specific product. This prevents one product's certificate
514
+ from signing another product's firmware or unlock blobs.
515
+
516
+ Note that this function does not validate the certificate chain.
517
+ That needs to be done before using this function.
518
+
519
+ @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
520
+ containing the content block with both the signature,
521
+ the signer's certificate, and any necessary intermediate
522
+ certificates.
523
+ @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
524
+ @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
525
+ required EKUs that must be present in the signature.
526
+ @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
527
+ @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
528
+ must be present in the leaf signer. If it is
529
+ FALSE, then we will succeed if we find any
530
+ of the specified EKU's.
531
+
532
+ @retval EFI_SUCCESS The required EKUs were found in the signature.
533
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
534
+ @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
535
+
536
+**/
537
+EFI_STATUS
538
+EFIAPI
539
+VerifyEKUsInPkcs7Signature (
540
+ IN CONST UINT8 *Pkcs7Signature,
541
+ IN CONST UINT32 SignatureSize,
542
+ IN CONST CHAR8 *RequiredEKUs[],
543
+ IN CONST UINT32 RequiredEKUsSize,
544
+ IN BOOLEAN RequireAllPresent
545
+ )
546
+{
547
+ EFI_STATUS Status;
548
+ PKCS7 *Pkcs7;
549
+ STACK_OF(X509) *CertChain;
550
+ INT32 SignatureType;
551
+ INT32 NumberCertsInSignature;
552
+ X509 *SignerCert;
553
+ UINT8 *SignedData;
554
+ UINT8 *Temp;
555
+ UINTN SignedDataSize;
556
+ BOOLEAN IsWrapped;
557
+ BOOLEAN Ok;
558
+
559
+ Status = EFI_SUCCESS;
560
+ Pkcs7 = NULL;
561
+ CertChain = NULL;
562
+ SignatureType = 0;
563
+ NumberCertsInSignature = 0;
564
+ SignerCert = NULL;
565
+ SignedData = NULL;
566
+ SignedDataSize = 0;
567
+ IsWrapped = FALSE;
568
+ Ok = FALSE;
569
+
570
+ //
571
+ //Validate the input parameters.
572
+ //
573
+ if (Pkcs7Signature == NULL ||
574
+ SignatureSize == 0 ||
575
+ RequiredEKUs == NULL ||
576
+ RequiredEKUsSize == 0) {
577
+ Status = EFI_INVALID_PARAMETER;
578
+ goto Exit;
579
+ }
580
+
581
+ if (RequiredEKUsSize == 1) {
582
+ RequireAllPresent = TRUE;
583
+ }
584
+
585
+ //
586
+ // Wrap the PKCS7 data if needed.
587
+ //
588
+ Ok = WrapPkcs7Data (Pkcs7Signature,
589
+ SignatureSize,
590
+ &IsWrapped,
591
+ &SignedData,
592
+ &SignedDataSize);
593
+ if (!Ok) {
594
+ //
595
+ // Fail to Wrap the PKCS7 data.
596
+ //
597
+ Status = EFI_INVALID_PARAMETER;
598
+ goto Exit;
599
+ }
600
+
601
+ Temp = SignedData;
602
+
603
+ //
604
+ // Create the PKCS7 object.
605
+ //
606
+ Pkcs7 = d2i_PKCS7 (NULL, (const unsigned char **)&Temp, (INT32)SignedDataSize);
607
+ if (Pkcs7 == NULL) {
608
+ //
609
+ // Fail to read PKCS7 data.
610
+ //
611
+ Status = EFI_INVALID_PARAMETER;
612
+ goto Exit;
613
+ }
614
+
615
+ //
616
+ // Get the certificate chain.
617
+ //
618
+ SignatureType = OBJ_obj2nid (Pkcs7->type);
619
+ switch (SignatureType) {
620
+ case NID_pkcs7_signed:
621
+ if (Pkcs7->d.sign != NULL) {
622
+ CertChain = Pkcs7->d.sign->cert;
623
+ }
624
+ break;
625
+ case NID_pkcs7_signedAndEnveloped:
626
+ if (Pkcs7->d.signed_and_enveloped != NULL) {
627
+ CertChain = Pkcs7->d.signed_and_enveloped->cert;
628
+ }
629
+ break;
630
+ default:
631
+ break;
632
+ }
633
+
634
+ //
635
+ // Ensure we have a certificate stack
636
+ //
637
+ if (CertChain == NULL) {
638
+ //
639
+ // Fail to get the certificate stack from signature.
640
+ //
641
+ Status = EFI_INVALID_PARAMETER;
642
+ goto Exit;
643
+ }
644
+
645
+ //
646
+ // Find out how many certificates were in the PKCS7 signature.
647
+ //
648
+ NumberCertsInSignature = sk_X509_num (CertChain);
649
+
650
+ if (NumberCertsInSignature == 0) {
651
+ //
652
+ // Fail to find any certificates in signature.
653
+ //
654
+ Status = EFI_INVALID_PARAMETER;
655
+ goto Exit;
656
+ }
657
+
658
+ //
659
+ // Get the leaf signer.
660
+ //
661
+ Status = GetSignerCertificate (Pkcs7, &SignerCert);
662
+ if (Status != EFI_SUCCESS || SignerCert == NULL) {
663
+ //
664
+ // Fail to get the end-entity leaf signer certificate.
665
+ //
666
+ Status = EFI_INVALID_PARAMETER;
667
+ goto Exit;
668
+ }
669
+
670
+ Status = CheckEKUs (SignerCert, RequiredEKUs, RequiredEKUsSize, RequireAllPresent);
671
+ if (Status != EFI_SUCCESS) {
672
+ goto Exit;
673
+ }
674
+
675
+Exit:
676
+
677
+ //
678
+ // Release Resources
679
+ //
680
+ // If the signature was not wrapped, then the call to WrapData() will allocate
681
+ // the data and add a header to it
682
+ //
683
+ if (!IsWrapped && SignedData) {
684
+ free (SignedData);
685
+ }
686
+
687
+ if (Pkcs7 != NULL) {
688
+ PKCS7_free (Pkcs7);
689
+ }
690
+
691
+ return Status;
692
+}
693
+
694
--
695
2.29.2
696
697