X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=FmpDevicePkg%2FFmpDxe%2FDetectTestKey.c;h=0e10d5ee17f0d0c147d7755f9ba7a9706d05bfdb;hp=0a6e37ededae7360268ffd60264987cb5667ad46;hb=HEAD;hpb=b0bacc003a6890d1881ea269d785d42928a7f340
diff --git a/FmpDevicePkg/FmpDxe/DetectTestKey.c b/FmpDevicePkg/FmpDxe/DetectTestKey.c
index 0a6e37eded..75dfce16bb 100644
--- a/FmpDevicePkg/FmpDxe/DetectTestKey.c
+++ b/FmpDevicePkg/FmpDxe/DetectTestKey.c
@@ -1,36 +1,13 @@
-/** @file
+/** @file
Detects if PcdFmpDevicePkcs7CertBufferXdr contains a test key.
- Copyright (c) 2018, Intel Corporation. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include "FmpDxe.h"
/**
Check to see if any of the keys in PcdFmpDevicePkcs7CertBufferXdr matches
@@ -53,12 +30,14 @@ DetectTestKey (
UINT8 *PublicKeyDataXdrEnd;
VOID *HashContext;
UINT8 Digest[SHA256_DIGEST_SIZE];
+ UINTN TestKeyDigestSize;
//
- // If PcdFmpDeviceTestKeySha256Digest is not exacty SHA256_DIGEST_SIZE bytes,
+ // If PcdFmpDeviceTestKeySha256Digest is not exactly SHA256_DIGEST_SIZE bytes,
// then skip the test key detection.
//
- if (PcdGetSize (PcdFmpDeviceTestKeySha256Digest) != SHA256_DIGEST_SIZE) {
+ TestKeyDigestSize = PcdGetSize (PcdFmpDeviceTestKeySha256Digest);
+ if (TestKeyDigestSize != SHA256_DIGEST_SIZE) {
return;
}
@@ -75,7 +54,7 @@ DetectTestKey (
//
PublicKeyDataXdr = PcdGetPtr (PcdFmpDevicePkcs7CertBufferXdr);
PublicKeyDataXdrEnd = PublicKeyDataXdr + PcdGetSize (PcdFmpDevicePkcs7CertBufferXdr);
- if (PublicKeyDataXdr == NULL || PublicKeyDataXdr == PublicKeyDataXdrEnd) {
+ if ((PublicKeyDataXdr == NULL) || (PublicKeyDataXdr == PublicKeyDataXdrEnd)) {
return;
}
@@ -97,6 +76,7 @@ DetectTestKey (
//
break;
}
+
//
// Read key length stored in big endian format
//
@@ -121,10 +101,12 @@ DetectTestKey (
TestKeyUsed = TRUE;
break;
}
+
if (!Sha256Update (HashContext, PublicKeyDataXdr, PublicKeyDataLength)) {
TestKeyUsed = TRUE;
break;
}
+
if (!Sha256Final (HashContext, Digest)) {
TestKeyUsed = TRUE;
break;
@@ -142,7 +124,7 @@ DetectTestKey (
// Point to start of next key
//
PublicKeyDataXdr += PublicKeyDataLength;
- PublicKeyDataXdr = (UINT8 *)ALIGN_POINTER (PublicKeyDataXdr, sizeof (UINT32));
+ PublicKeyDataXdr = (UINT8 *)ALIGN_POINTER (PublicKeyDataXdr, sizeof (UINT32));
}
//
@@ -154,13 +136,13 @@ DetectTestKey (
}
//
- // If test key detected or an error occured checking for the test key, then
+ // If test key detected or an error occurred checking for the test key, then
// set PcdTestKeyUsed to TRUE.
//
if (TestKeyUsed) {
- DEBUG ((DEBUG_INFO, "FmpDxe: Test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n"));
+ DEBUG ((DEBUG_INFO, "FmpDxe(%s): Test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n", mImageIdName));
PcdSetBoolS (PcdTestKeyUsed, TRUE);
} else {
- DEBUG ((DEBUG_INFO, "FmpDxe: No test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n"));
+ DEBUG ((DEBUG_INFO, "FmpDxe(%s): No test key detected in PcdFmpDevicePkcs7CertBufferXdr.\n", mImageIdName));
}
}