]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/AuthVariableLib/AuthService.c
SecurityPkg: enhance secure boot Config Dxe & Time Based AuthVariable.
[mirror_edk2.git] / SecurityPkg / Library / AuthVariableLib / AuthService.c
index b013d420f62e29097e418143e19b85d866b3af76..a37ec0bd0fc604f4333d29fdeb89fb4c2b119bcd 100644 (file)
@@ -18,7 +18,7 @@
   They will do basic validation for authentication data structure, then call crypto library\r
   to verify the signature.\r
 \r
-Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -36,6 +36,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 CONST UINT8 mRsaE[] = { 0x01, 0x00, 0x01 };\r
 \r
+CONST UINT8 mSha256OidValue[] = { 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 };\r
+\r
 //\r
 // Requirement for different signature type which have been defined in UEFI spec.\r
 // These data are used to perform SignatureList format check while setting PK/KEK variable.\r
@@ -2244,6 +2246,29 @@ VerifyTimeBasedPayload (
   SigData = CertData->AuthInfo.CertData;\r
   SigDataSize = CertData->AuthInfo.Hdr.dwLength - (UINT32) (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData));\r
 \r
+  //\r
+  // SignedData.digestAlgorithms shall contain the digest algorithm used when preparing the\r
+  // signature. Only a digest algorithm of SHA-256 is accepted.\r
+  //\r
+  //    According to PKCS#7 Definition:\r
+  //        SignedData ::= SEQUENCE {\r
+  //            version Version,\r
+  //            digestAlgorithms DigestAlgorithmIdentifiers,\r
+  //            contentInfo ContentInfo,\r
+  //            .... }\r
+  //    The DigestAlgorithmIdentifiers can be used to determine the hash algorithm \r
+  //    in VARIABLE_AUTHENTICATION_2 descriptor.\r
+  //    This field has the fixed offset (+13) and be calculated based on two bytes of length encoding.\r
+  //\r
+  if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
+    if (SigDataSize >= (13 + sizeof (mSha256OidValue))) {\r
+      if (((*(SigData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) || \r
+           (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidValue)) != 0)) {\r
+          return EFI_SECURITY_VIOLATION;\r
+        }\r
+    }\r
+  }\r
+\r
   //\r
   // Find out the new data payload which follows Pkcs7 SignedData directly.\r
   //\r