Re: [edk2] [Patch v5 03/21] FmpDevicePkg: Add FmpDxe module
Reviewed-by: Star Zeng -Original Message- From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Kinney, Michael D Sent: Wednesday, August 1, 2018 2:55 PM To: edk2-devel@lists.01.org Cc: Kinney, Michael D ; Yao, Jiewen Subject: [edk2] [Patch v5 03/21] FmpDevicePkg: Add FmpDxe module https://bugzilla.tianocore.org/show_bug.cgi?id=922 Based on content from the following branch: https://github.com/Microsoft/MS_UEFI/tree/share/MsCapsuleSupport/MsCapsuleUpdatePkg The FmpDxe directory contains 2 INF files. FmpDxe.inf is a DXE driver that is used in a platform to add a Firmware Management Protocol for firmware device that supports firmware updates. FmpDxeLib.inf is a NULL library instance with the exact same functionality as FmpDxe.inf, but allows the the Firmware Management Protocol feature to be added to an existing device driver. The FmpDxe component is intended to be used "as is" with no need for any device specific or platform specific changes. Cc: Sean Brogan Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney --- FmpDevicePkg/FmpDxe/DetectTestKey.c | 166 FmpDevicePkg/FmpDxe/FmpDxe.c | 1452 + FmpDevicePkg/FmpDxe/FmpDxe.inf| 93 +++ FmpDevicePkg/FmpDxe/FmpDxe.uni| 20 + FmpDevicePkg/FmpDxe/FmpDxeExtra.uni | 18 + FmpDevicePkg/FmpDxe/FmpDxeLib.inf | 90 ++ FmpDevicePkg/FmpDxe/VariableSupport.c | 461 +++ FmpDevicePkg/FmpDxe/VariableSupport.h | 180 8 files changed, 2480 insertions(+) create mode 100644 FmpDevicePkg/FmpDxe/DetectTestKey.c create mode 100644 FmpDevicePkg/FmpDxe/FmpDxe.c create mode 100644 FmpDevicePkg/FmpDxe/FmpDxe.inf create mode 100644 FmpDevicePkg/FmpDxe/FmpDxe.uni create mode 100644 FmpDevicePkg/FmpDxe/FmpDxeExtra.uni create mode 100644 FmpDevicePkg/FmpDxe/FmpDxeLib.inf create mode 100644 FmpDevicePkg/FmpDxe/VariableSupport.c create mode 100644 FmpDevicePkg/FmpDxe/VariableSupport.h diff --git a/FmpDevicePkg/FmpDxe/DetectTestKey.c b/FmpDevicePkg/FmpDxe/DetectTestKey.c new file mode 100644 index 00..0a6e37eded --- /dev/null +++ b/FmpDevicePkg/FmpDxe/DetectTestKey.c @@ -0,0 +1,166 @@ +/** @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. + +**/ + +#include +#include +#include +#include +#include +#include +#include + +/** + Check to see if any of the keys in PcdFmpDevicePkcs7CertBufferXdr matches + the test key. PcdFmpDeviceTestKeySha256Digest contains the SHA256 hash of + the test key. For each key in PcdFmpDevicePkcs7CertBufferXdr, compute the + SHA256 hash and compare it to PcdFmpDeviceTestKeySha256Digest. If the + SHA256 hash matches or there is then error computing the SHA256 hash, then + set PcdTestKeyUsed to TRUE. Skip this check if PcdTestKeyUsed is already + TRUE or PcdFmpDeviceTestKeySha256Digest is not exactly SHA256_DIGEST_SIZE + bytes. +**/ +VOID +DetectTestKey ( + VOID + ) +{ + BOOLEAN TestKeyUsed; + UINTNPublicKeyDataLength; + UINT8*PublicKeyDataXdr; + UINT8*PublicKeyDataXdrEnd; + VOID *HashContext; + UINT8Digest[SHA256_DIGEST_SIZE]; + + // + // If PcdFmpDeviceTestKeySha256Digest is not exacty SHA256_DIGEST_SIZE bytes, + // then skip the test key detection. + // + if (PcdGetSize (PcdFmpDeviceTestKeySha256Digest) != SHA256_DIGEST_SIZE) { +return; + } + + // + // If PcdTestKeyUsed is already TRUE, then skip test key detection + // + TestKeyUsed = PcdGetBool (PcdTestKeyUsed); + if (TestKeyUsed) { +return; + } + + // + // If PcdFmpDevi
[edk2] [Patch v5 03/21] FmpDevicePkg: Add FmpDxe module
https://bugzilla.tianocore.org/show_bug.cgi?id=922 Based on content from the following branch: https://github.com/Microsoft/MS_UEFI/tree/share/MsCapsuleSupport/MsCapsuleUpdatePkg The FmpDxe directory contains 2 INF files. FmpDxe.inf is a DXE driver that is used in a platform to add a Firmware Management Protocol for firmware device that supports firmware updates. FmpDxeLib.inf is a NULL library instance with the exact same functionality as FmpDxe.inf, but allows the the Firmware Management Protocol feature to be added to an existing device driver. The FmpDxe component is intended to be used "as is" with no need for any device specific or platform specific changes. Cc: Sean Brogan Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney --- FmpDevicePkg/FmpDxe/DetectTestKey.c | 166 FmpDevicePkg/FmpDxe/FmpDxe.c | 1452 + FmpDevicePkg/FmpDxe/FmpDxe.inf| 93 +++ FmpDevicePkg/FmpDxe/FmpDxe.uni| 20 + FmpDevicePkg/FmpDxe/FmpDxeExtra.uni | 18 + FmpDevicePkg/FmpDxe/FmpDxeLib.inf | 90 ++ FmpDevicePkg/FmpDxe/VariableSupport.c | 461 +++ FmpDevicePkg/FmpDxe/VariableSupport.h | 180 8 files changed, 2480 insertions(+) create mode 100644 FmpDevicePkg/FmpDxe/DetectTestKey.c create mode 100644 FmpDevicePkg/FmpDxe/FmpDxe.c create mode 100644 FmpDevicePkg/FmpDxe/FmpDxe.inf create mode 100644 FmpDevicePkg/FmpDxe/FmpDxe.uni create mode 100644 FmpDevicePkg/FmpDxe/FmpDxeExtra.uni create mode 100644 FmpDevicePkg/FmpDxe/FmpDxeLib.inf create mode 100644 FmpDevicePkg/FmpDxe/VariableSupport.c create mode 100644 FmpDevicePkg/FmpDxe/VariableSupport.h diff --git a/FmpDevicePkg/FmpDxe/DetectTestKey.c b/FmpDevicePkg/FmpDxe/DetectTestKey.c new file mode 100644 index 00..0a6e37eded --- /dev/null +++ b/FmpDevicePkg/FmpDxe/DetectTestKey.c @@ -0,0 +1,166 @@ +/** @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. + +**/ + +#include +#include +#include +#include +#include +#include +#include + +/** + Check to see if any of the keys in PcdFmpDevicePkcs7CertBufferXdr matches + the test key. PcdFmpDeviceTestKeySha256Digest contains the SHA256 hash of + the test key. For each key in PcdFmpDevicePkcs7CertBufferXdr, compute the + SHA256 hash and compare it to PcdFmpDeviceTestKeySha256Digest. If the + SHA256 hash matches or there is then error computing the SHA256 hash, then + set PcdTestKeyUsed to TRUE. Skip this check if PcdTestKeyUsed is already + TRUE or PcdFmpDeviceTestKeySha256Digest is not exactly SHA256_DIGEST_SIZE + bytes. +**/ +VOID +DetectTestKey ( + VOID + ) +{ + BOOLEAN TestKeyUsed; + UINTNPublicKeyDataLength; + UINT8*PublicKeyDataXdr; + UINT8*PublicKeyDataXdrEnd; + VOID *HashContext; + UINT8Digest[SHA256_DIGEST_SIZE]; + + // + // If PcdFmpDeviceTestKeySha256Digest is not exacty SHA256_DIGEST_SIZE bytes, + // then skip the test key detection. + // + if (PcdGetSize (PcdFmpDeviceTestKeySha256Digest) != SHA256_DIGEST_SIZE) { +return; + } + + // + // If PcdTestKeyUsed is already TRUE, then skip test key detection + // + TestKeyUsed = PcdGetBool (PcdTestKeyUsed); + if (TestKeyUsed) { +return; + } + + // + // If PcdFmpDevicePkcs7CertBufferXdr is invalid, then skip test key detection + // + PublicKeyDataXdr= PcdGetPtr (PcdFmpDevicePkcs7CertBufferXdr); + PublicKeyDataXdrEnd = PublicKeyDataXdr + PcdGetSize (PcdFmpDevicePkcs7CertBufferXdr); + if (PublicKeyDataXdr == NULL || PublicKeyDataXdr == PublicKeyDataXdrEnd) { +return; + } + + // +