public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] SecurityPkg: fix sha256 signature check
@ 2018-05-09 22:09 James Bottomley
  2018-05-10 12:36 ` Laszlo Ersek
  0 siblings, 1 reply; 3+ messages in thread
From: James Bottomley @ 2018-05-09 22:09 UTC (permalink / raw)
  To: edk2-devel@lists.01.org; +Cc: Zhang Lubo

commit c035e37335ae43229d7e68de74a65f2c01ebc0af
Author: Zhang Lubo <lubo.zhang@intel.com>
Date:   Thu Jan 5 14:58:05 2017 +0800

    SecurityPkg: enhance secure boot Config Dxe & Time Based AuthVariable.

Added a check for sha256 being the ownly allowed signature hash.
Unfortuantely this commit assumed the form of the signature data was a
raw SignedData sequence.  Most tools actually generate a ContentInfo
sequence instead which contains a header identifying the content as
pkcs7-SignedData.  Fix this check to allow either format to work.

This fix is needed at least for efitools because we generate signed
variable updates with the ContentInfo header.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 CryptoPkg/Library/OpensslLib/openssl              |  2 +-
 SecurityPkg/Library/AuthVariableLib/AuthService.c | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/CryptoPkg/Library/OpensslLib/openssl b/CryptoPkg/Library/OpensslLib/openssl
index b2758a2292..d4e4bd2a81 160000
--- a/CryptoPkg/Library/OpensslLib/openssl
+++ b/CryptoPkg/Library/OpensslLib/openssl
@@ -1 +1 @@
-Subproject commit b2758a2292aceda93e9f44c219b94fe21bb9a650
+Subproject commit d4e4bd2a8163f355fa8a3884077eaec7adc75ff7
diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPkg/Library/AuthVariableLib/AuthService.c
index 213a524f27..855ea3350a 100644
--- a/SecurityPkg/Library/AuthVariableLib/AuthService.c
+++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c
@@ -1908,10 +1908,19 @@ VerifyTimeBasedPayload (
   //    in VARIABLE_AUTHENTICATION_2 descriptor.
   //    This field has the fixed offset (+13) and be calculated based on two bytes of length encoding.
   //
+  // However the data may also begin
+  //   ContentInfo ::= SEQUENCE {
+  //	   contentType ContentType,
+  //	   content
+  //	     [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
+  //
+  // In which case the fixed offset is +32
+  //
   if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {
     if (SigDataSize >= (13 + sizeof (mSha256OidValue))) {
       if (((*(SigData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) || 
-           (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidValue)) != 0)) {
+	  (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidValue)) != 0 &&
+	   CompareMem (SigData + 32, &mSha256OidValue, sizeof (mSha256OidValue)) != 0)) {
           return EFI_SECURITY_VIOLATION;
         }
     }
-- 
2.13.6



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] SecurityPkg: fix sha256 signature check
  2018-05-09 22:09 [PATCH] SecurityPkg: fix sha256 signature check James Bottomley
@ 2018-05-10 12:36 ` Laszlo Ersek
  2018-05-11  8:25   ` Long, Qin
  0 siblings, 1 reply; 3+ messages in thread
From: Laszlo Ersek @ 2018-05-10 12:36 UTC (permalink / raw)
  To: James Bottomley, edk2-devel@lists.01.org; +Cc: Zhang Lubo

On 05/10/18 00:09, James Bottomley wrote:
> commit c035e37335ae43229d7e68de74a65f2c01ebc0af
> Author: Zhang Lubo <lubo.zhang@intel.com>
> Date:   Thu Jan 5 14:58:05 2017 +0800
> 
>     SecurityPkg: enhance secure boot Config Dxe & Time Based AuthVariable.
> 
> Added a check for sha256 being the ownly allowed signature hash.
> Unfortuantely this commit assumed the form of the signature data was a
> raw SignedData sequence.  Most tools actually generate a ContentInfo
> sequence instead which contains a header identifying the content as
> pkcs7-SignedData.  Fix this check to allow either format to work.
> 
> This fix is needed at least for efitools because we generate signed
> variable updates with the ContentInfo header.
> 
> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
> ---
>  CryptoPkg/Library/OpensslLib/openssl              |  2 +-
>  SecurityPkg/Library/AuthVariableLib/AuthService.c | 11 ++++++++++-
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/CryptoPkg/Library/OpensslLib/openssl b/CryptoPkg/Library/OpensslLib/openssl
> index b2758a2292..d4e4bd2a81 160000
> --- a/CryptoPkg/Library/OpensslLib/openssl
> +++ b/CryptoPkg/Library/OpensslLib/openssl
> @@ -1 +1 @@
> -Subproject commit b2758a2292aceda93e9f44c219b94fe21bb9a650
> +Subproject commit d4e4bd2a8163f355fa8a3884077eaec7adc75ff7

This hunk should not be necessary; please see edk2 commit b85b20fba42e
("CryptoPkg/OpensslLib: Update OpenSSL version to 1.1.0h", 2018-04-15).

(I'll let the SecurityPkg maintainers review the rest.)

Thanks,
Laszlo

> diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPkg/Library/AuthVariableLib/AuthService.c
> index 213a524f27..855ea3350a 100644
> --- a/SecurityPkg/Library/AuthVariableLib/AuthService.c
> +++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c
> @@ -1908,10 +1908,19 @@ VerifyTimeBasedPayload (
>    //    in VARIABLE_AUTHENTICATION_2 descriptor.
>    //    This field has the fixed offset (+13) and be calculated based on two bytes of length encoding.
>    //
> +  // However the data may also begin
> +  //   ContentInfo ::= SEQUENCE {
> +  //	   contentType ContentType,
> +  //	   content
> +  //	     [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
> +  //
> +  // In which case the fixed offset is +32
> +  //
>    if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {
>      if (SigDataSize >= (13 + sizeof (mSha256OidValue))) {
>        if (((*(SigData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) || 
> -           (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidValue)) != 0)) {
> +	  (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidValue)) != 0 &&
> +	   CompareMem (SigData + 32, &mSha256OidValue, sizeof (mSha256OidValue)) != 0)) {
>            return EFI_SECURITY_VIOLATION;
>          }
>      }
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] SecurityPkg: fix sha256 signature check
  2018-05-10 12:36 ` Laszlo Ersek
@ 2018-05-11  8:25   ` Long, Qin
  0 siblings, 0 replies; 3+ messages in thread
From: Long, Qin @ 2018-05-11  8:25 UTC (permalink / raw)
  To: Laszlo Ersek, James Bottomley, edk2-devel@lists.01.org; +Cc: Zhang Lubo


> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Laszlo Ersek
> Sent: Thursday, May 10, 2018 8:36 PM
> To: James Bottomley <James.Bottomley@HansenPartnership.com>; edk2-
> devel@lists.01.org
> Cc: Zhang Lubo <lubo.zhang@intel.com>
> Subject: Re: [edk2] [PATCH] SecurityPkg: fix sha256 signature check
> 
> On 05/10/18 00:09, James Bottomley wrote:
> > commit c035e37335ae43229d7e68de74a65f2c01ebc0af
> > Author: Zhang Lubo <lubo.zhang@intel.com>
> > Date:   Thu Jan 5 14:58:05 2017 +0800
> >
> >     SecurityPkg: enhance secure boot Config Dxe & Time Based AuthVariable.
> >
> > Added a check for sha256 being the ownly allowed signature hash.
> > Unfortuantely this commit assumed the form of the signature data was a
> > raw SignedData sequence.  Most tools actually generate a ContentInfo
> > sequence instead which contains a header identifying the content as
> > pkcs7-SignedData.  Fix this check to allow either format to work.
> >
> > This fix is needed at least for efitools because we generate signed
> > variable updates with the ContentInfo header.
> >
> > Signed-off-by: James Bottomley
> <James.Bottomley@HansenPartnership.com>
> > ---
> >  CryptoPkg/Library/OpensslLib/openssl              |  2 +-
> >  SecurityPkg/Library/AuthVariableLib/AuthService.c | 11 ++++++++++-
> >  2 files changed, 11 insertions(+), 2 deletions(-)
> >
> > diff --git a/CryptoPkg/Library/OpensslLib/openssl
> > b/CryptoPkg/Library/OpensslLib/openssl
> > index b2758a2292..d4e4bd2a81 160000
> > --- a/CryptoPkg/Library/OpensslLib/openssl
> > +++ b/CryptoPkg/Library/OpensslLib/openssl
> > @@ -1 +1 @@
> > -Subproject commit b2758a2292aceda93e9f44c219b94fe21bb9a650
> > +Subproject commit d4e4bd2a8163f355fa8a3884077eaec7adc75ff7
> 
> This hunk should not be necessary; please see edk2 commit b85b20fba42e
> ("CryptoPkg/OpensslLib: Update OpenSSL version to 1.1.0h", 2018-04-15).
> 
> (I'll let the SecurityPkg maintainers review the rest.)
> 
> Thanks,
> Laszlo

[Long, Qin] I think so. 
OpenSSL submodule was already upgraded to 1.1.0h (d4e4bd2a8...)

> 
> > diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c
> > b/SecurityPkg/Library/AuthVariableLib/AuthService.c
> > index 213a524f27..855ea3350a 100644
> > --- a/SecurityPkg/Library/AuthVariableLib/AuthService.c
> > +++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c
> > @@ -1908,10 +1908,19 @@ VerifyTimeBasedPayload (
> >    //    in VARIABLE_AUTHENTICATION_2 descriptor.
> >    //    This field has the fixed offset (+13) and be calculated based on two
> bytes of length encoding.
> >    //
> > +  // However the data may also begin
> > +  //   ContentInfo ::= SEQUENCE {
> > +  //	   contentType ContentType,
> > +  //	   content
> > +  //	     [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
> > +  //
> > +  // In which case the fixed offset is +32  //
> >    if ((Attributes &
> EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {
> >      if (SigDataSize >= (13 + sizeof (mSha256OidValue))) {
> >        if (((*(SigData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) ||
> > -           (CompareMem (SigData + 13, &mSha256OidValue, sizeof
> (mSha256OidValue)) != 0)) {
> > +	  (CompareMem (SigData + 13, &mSha256OidValue, sizeof
> (mSha256OidValue)) != 0 &&
> > +	   CompareMem (SigData + 32, &mSha256OidValue, sizeof
> > +(mSha256OidValue)) != 0)) {
> >            return EFI_SECURITY_VIOLATION;
> >          }
> >      }
> >
[Long, Qin]  This part looks good to me. 
	I prefer to add this to make both formats (with or without contentType) to work.

> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-11  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-09 22:09 [PATCH] SecurityPkg: fix sha256 signature check James Bottomley
2018-05-10 12:36 ` Laszlo Ersek
2018-05-11  8:25   ` Long, Qin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox