<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<div>
<div>
<div dir="ltr">reviewed-by: Jiewen Yao <Jiewen.yao@intel.com></div>
</div>
<div id="ms-outlook-mobile-signature">
<div></div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>发件人:</b> Jan Bobek <jbobek@nvidia.com><br>
<b>发送时间:</b> Monday, January 23, 2023 5:53:48 AM<br>
<b>收件人:</b> devel@edk2.groups.io <devel@edk2.groups.io><br>
<b>抄送:</b> Jan Bobek <jbobek@nvidia.com>; Yao, Jiewen <jiewen.yao@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Xu, Min M <min.m.xu@intel.com><br>
<b>主题:</b> [PATCH v2 1/1] SecurityPkg/AuthVariableLib: Check SHA-256 OID with ContentInfo present</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">REF: <a href="https://bugzilla.tianocore.org/show_bug.cgi?id=4305">
https://bugzilla.tianocore.org/show_bug.cgi?id=4305</a><br>
<br>
Based on whether the DER-encoded ContentInfo structure is present in<br>
authenticated SetVariable payload or not, the SHA-256 OID can be<br>
located at different places.<br>
<br>
UEFI specification explicitly states the driver shall support both<br>
cases, but the old code assumed ContentInfo was not present and<br>
incorrectly rejected authenticated variable updates when it were<br>
present.<br>
<br>
Cc: Jiewen Yao <jiewen.yao@intel.com><br>
Cc: Jian J Wang <jian.j.wang@intel.com><br>
Cc: Min Xu <min.m.xu@intel.com><br>
Signed-off-by: Jan Bobek <jbobek@nvidia.com><br>
---<br>
 .../Library/AuthVariableLib/AuthService.c     | 50 ++++++++++++++++---<br>
 1 file changed, 42 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPkg/Library/AuthVariableLib/AuthService.c<br>
index 054ee4d1d988..9beeca09aeba 100644<br>
--- a/SecurityPkg/Library/AuthVariableLib/AuthService.c<br>
+++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c<br>
@@ -1925,7 +1925,7 @@ VerifyTimeBasedPayload (<br>
   // SignedData.digestAlgorithms shall contain the digest algorithm used when preparing the<br>
   // signature. Only a digest algorithm of SHA-256 is accepted.<br>
   //<br>
-  //    According to PKCS#7 Definition:<br>
+  //    According to PKCS#7 Definition (<a href="https://www.rfc-editor.org/rfc/rfc2315">https://www.rfc-editor.org/rfc/rfc2315</a>):<br>
   //        SignedData ::= SEQUENCE {<br>
   //            version Version,<br>
   //            digestAlgorithms DigestAlgorithmIdentifiers,<br>
@@ -1933,15 +1933,49 @@ VerifyTimeBasedPayload (<br>
   //            .... }<br>
   //    The DigestAlgorithmIdentifiers can be used to determine the hash algorithm<br>
   //    in VARIABLE_AUTHENTICATION_2 descriptor.<br>
-  //    This field has the fixed offset (+13) and be calculated based on two bytes of length encoding.<br>
+  //    This field has the fixed offset (+13) or (+32) based on whether the DER-encoded<br>
+  //    ContentInfo structure is present or not, and can be calculated based on two<br>
+  //    bytes of length encoding.<br>
+  //<br>
+  //    Both condition can be handled in WrapPkcs7Data() in CryptPkcs7VerifyCommon.c.<br>
+  //<br>
+  //    See below examples:<br>
+  //<br>
+  // 1. Without ContentInfo<br>
+  //    30 82 0c da // SEQUENCE (5 element) (3294 BYTES) -- SignedData<br>
+  //       02 01 01 // INTEGER 1 -- Version<br>
+  //       31 0f // SET (1 element) (15 BYTES) -- DigestAlgorithmIdentifiers<br>
+  //          30 0d // SEQUENCE (2 element) (13 BYTES) -- AlgorithmIdentifier<br>
+  //             06 09 // OBJECT-IDENTIFIER (9 BYTES) -- algorithm<br>
+  //                60 86 48 01 65 03 04 02 01 // sha256 [2.16.840.1.101.3.4.2.1]<br>
+  //             05 00 // NULL (0 BYTES) -- parameters<br>
+  //<br>
+  // Example from: <a href="https://uefi.org/revocationlistfile">https://uefi.org/revocationlistfile</a><br>
+  //<br>
+  // 2. With ContentInfo<br>
+  //    30 82 05 90 // SEQUENCE (1424 BYTES) -- ContentInfo<br>
+  //       06 09 // OBJECT-IDENTIFIER (9 BYTES) -- ContentType<br>
+  //          2a 86 48 86 f7 0d 01 07 02 // signedData [1.2.840.113549.1.7.2]<br>
+  //       a0 82 05 81 // CONTEXT-SPECIFIC CONSTRUCTED TAG 0 (1409 BYTES) -- content<br>
+  //          30 82 05 7d // SEQUENCE (1405 BYTES) -- SignedData<br>
+  //             02 01 01 // INTEGER 1 -- Version<br>
+  //             31 0f // SET (1 element) (15 BYTES) -- DigestAlgorithmIdentifiers<br>
+  //                30 0d // SEQUENCE (13 BYTES) -- AlgorithmIdentifier<br>
+  //                   06 09 // OBJECT-IDENTIFIER (9 BYTES) -- algorithm<br>
+  //                      60 86 48 01 65 03 04 02 01 // sha256 [2.16.840.1.101.3.4.2.1]<br>
+  //                   05 00 // NULL (0 BYTES) -- parameters<br>
+  //<br>
+  // Example generated with: <a href="https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot#Manual_process">
https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot#Manual_process</a><br>
   //<br>
   if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {<br>
-    if (SigDataSize >= (13 + sizeof (mSha256OidValue))) {<br>
-      if (((*(SigData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) ||<br>
-          (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidValue)) != 0))<br>
-      {<br>
-        return EFI_SECURITY_VIOLATION;<br>
-      }<br>
+    if (  (  (SigDataSize >= (13 + sizeof (mSha256OidValue)))<br>
+          && (  ((*(SigData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE)<br>
+             || (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidValue)) != 0)))<br>
+       && (  (SigDataSize >= (32 + sizeof (mSha256OidValue)))<br>
+          && (  ((*(SigData + 20) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE)<br>
+             || (CompareMem (SigData + 32, &mSha256OidValue, sizeof (mSha256OidValue)) != 0))))<br>
+    {<br>
+      return EFI_SECURITY_VIOLATION;<br>
     }<br>
   }<br>
 <br>
-- <br>
2.30.2<br>
<br>
</div>
</span></font></div>
</body>
</html>


<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>


Groups.io Links:<p>


  
    You receive all messages sent to this group.
  
  


<p>
<a target="_blank" href="https://edk2.groups.io/g/devel/message/98953">View/Reply Online (#98953)</a> |


  

|

  <a target="_blank" href="https://groups.io/mt/96462302/1813853">Mute This Topic</a>

| <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>




<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>