public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types
@ 2020-04-26  5:40 Guomin Jiang
  2020-04-27  8:16 ` Wang, Jian J
       [not found] ` <16099F3AD41E60C6.16806@groups.io>
  0 siblings, 2 replies; 3+ messages in thread
From: Guomin Jiang @ 2020-04-26  5:40 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Xiaoyu Lu

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2539

Microsoft signtool supports creation of attached P7's with any OID payload
via the "/p7co" parameter. It is necessary to check the data before get
the string.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Signed-off-by: Guomin Jiang <guomin.jiang@intel.com>
---
 .../BaseCryptLib/Pk/CryptPkcs7VerifyBase.c    | 65 ++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
index 313f459b11..70d9880897 100644
--- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
+++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
@@ -13,6 +13,65 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <openssl/x509v3.h>
 #include <openssl/pkcs7.h>
 
+/**
+  Check the contents of PKCS7 is not data.
+
+  It is copied from PKCS7_type_is_other() in pk7_doit.c.
+
+  @param P7 Pointer to the location which the PKCS7 is located at.
+
+  @return UINT8 The content type.
+**/
+static
+UINT8
+Pkcs7TypeIsOther (
+  PKCS7 *P7
+  )
+{
+  UINT8 Others = 1;
+  UINT8 Nid = (UINT8) OBJ_obj2nid (P7->type);
+
+  switch (Nid) {
+    case NID_pkcs7_data:
+    case NID_pkcs7_signed:
+    case NID_pkcs7_enveloped:
+    case NID_pkcs7_signedAndEnveloped:
+    case NID_pkcs7_encrypted:
+      Others = 0;
+      break;
+    default:
+      Others = 1;
+  }
+
+  return Others;
+}
+
+/**
+  Get the ASN.1 string for the PKCS7.
+
+  It is copied from PKCS7_get_octet_string() in pk7_doit.c.
+  @param P7 Pointer to the location which the PKCS7 is located at.
+
+  @return ASN1_OCTET_STRING ASN.1 string.
+**/
+static
+ASN1_OCTET_STRING*
+Pkcs7GetOctetString (
+  PKCS7 *P7
+  )
+{
+  if (PKCS7_type_is_data (P7)) {
+    return P7->d.data;
+  }
+
+  if ((Pkcs7TypeIsOther(P7) == 1) && P7->d.other &&
+      (P7->d.other->type == V_ASN1_OCTET_STRING)) {
+    return P7->d.other->value.octet_string;
+  }
+
+  return NULL;
+}
+
 /**
   Extracts the attached content from a PKCS#7 signed data if existed. The input signed
   data could be wrapped in a ContentInfo structure.
@@ -98,7 +157,11 @@ Pkcs7GetAttachedContent (
     //
     // Retrieve the attached content in PKCS7 signedData
     //
-    OctStr = Pkcs7->d.sign->contents->d.data;
+    OctStr = Pkcs7GetOctetString (Pkcs7->d.sign->contents);
+    if (OctStr == NULL) {
+      goto _Exit;
+    }
+
     if ((OctStr->length > 0) && (OctStr->data != NULL)) {
       *ContentSize = OctStr->length;
       *Content     = AllocatePool (*ContentSize);
-- 
2.25.1.windows.1


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

* Re: [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types
  2020-04-26  5:40 [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types Guomin Jiang
@ 2020-04-27  8:16 ` Wang, Jian J
       [not found] ` <16099F3AD41E60C6.16806@groups.io>
  1 sibling, 0 replies; 3+ messages in thread
From: Wang, Jian J @ 2020-04-27  8:16 UTC (permalink / raw)
  To: Jiang, Guomin, devel@edk2.groups.io; +Cc: Lu, XiaoyuX

Guomin,

A few comments below.

> -----Original Message-----
> From: Jiang, Guomin <guomin.jiang@intel.com>
> Sent: Sunday, April 26, 2020 1:40 PM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Lu, XiaoyuX <xiaoyux.lu@intel.com>
> Subject: [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2539
> 
> Microsoft signtool supports creation of attached P7's with any OID payload
> via the "/p7co" parameter. It is necessary to check the data before get
> the string.
> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
> Signed-off-by: Guomin Jiang <guomin.jiang@intel.com>
> ---
>  .../BaseCryptLib/Pk/CryptPkcs7VerifyBase.c    | 65 ++++++++++++++++++-
>  1 file changed, 64 insertions(+), 1 deletion(-)
> 
> diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> index 313f459b11..70d9880897 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> @@ -13,6 +13,65 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <openssl/x509v3.h>
> 
>  #include <openssl/pkcs7.h>
> 
> 
> 
> +/**
> 
> +  Check the contents of PKCS7 is not data.
> 
> +
> 
> +  It is copied from PKCS7_type_is_other() in pk7_doit.c.
> 
> +
> 
> +  @param P7 Pointer to the location which the PKCS7 is located at.
> 
> +
> 
> +  @return UINT8 The content type.
> 
> +**/
> 
> +static

Please use STATIC instead, according to ch5.6.1.2 of "EDK II Coding
Standards 2.1".

https://github.com/tianocore-docs/Docs/raw/master/Specifications/CCS_2_1_Draft.pdf

> 
> +UINT8
> 
> +Pkcs7TypeIsOther (
> 
> +  PKCS7 *P7

Missing IN/OUT modifier for parameter, according to ch5.7.1.11 of
"EDK II Coding Standards 2.1". Add in/out in function parameter
description comment as well.

https://github.com/tianocore-docs/Docs/raw/master/Specifications/CCS_2_1_Draft.pdf

> 
> +  )
> 
> +{
> 
> +  UINT8 Others = 1;
> 
> +  UINT8 Nid = (UINT8) OBJ_obj2nid (P7->type);
> 
> +
> 
> +  switch (Nid) {
> 
> +    case NID_pkcs7_data:
> 
> +    case NID_pkcs7_signed:
> 
> +    case NID_pkcs7_enveloped:
> 
> +    case NID_pkcs7_signedAndEnveloped:
> 
> +    case NID_pkcs7_encrypted:
> 
> +      Others = 0;
> 
> +      break;
> 
> +    default:
> 
> +      Others = 1;
> 
> +  }
> 
> +
> 
> +  return Others;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Get the ASN.1 string for the PKCS7.
> 
> +
> 
> +  It is copied from PKCS7_get_octet_string() in pk7_doit.c.
> 
> +  @param P7 Pointer to the location which the PKCS7 is located at.
> 
> +
> 
> +  @return ASN1_OCTET_STRING ASN.1 string.
> 
> +**/
> 
> +static

Same as above, use STATIC instead.

> 
> +ASN1_OCTET_STRING*
> 
> +Pkcs7GetOctetString (
> 
> +  PKCS7 *P7

Missing IN/OUT modifier for parameter, according to ch5.7.1.11 of
"EDK II Coding Standards 2.1". Add in/out in function parameter
description comment as well.

Regards,
Jian

> 
> +  )
> 
> +{
> 
> +  if (PKCS7_type_is_data (P7)) {
> 
> +    return P7->d.data;
> 
> +  }
> 
> +
> 
> +  if ((Pkcs7TypeIsOther(P7) == 1) && P7->d.other &&
> 
> +      (P7->d.other->type == V_ASN1_OCTET_STRING)) {
> 
> +    return P7->d.other->value.octet_string;
> 
> +  }
> 
> +
> 
> +  return NULL;
> 
> +}
> 
> +
> 
>  /**
> 
>    Extracts the attached content from a PKCS#7 signed data if existed. The input
> signed
> 
>    data could be wrapped in a ContentInfo structure.
> 
> @@ -98,7 +157,11 @@ Pkcs7GetAttachedContent (
>      //
> 
>      // Retrieve the attached content in PKCS7 signedData
> 
>      //
> 
> -    OctStr = Pkcs7->d.sign->contents->d.data;
> 
> +    OctStr = Pkcs7GetOctetString (Pkcs7->d.sign->contents);
> 
> +    if (OctStr == NULL) {
> 
> +      goto _Exit;
> 
> +    }
> 
> +
> 
>      if ((OctStr->length > 0) && (OctStr->data != NULL)) {
> 
>        *ContentSize = OctStr->length;
> 
>        *Content     = AllocatePool (*ContentSize);
> 
> --
> 2.25.1.windows.1


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

* Re: [edk2-devel] [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types
       [not found] ` <16099F3AD41E60C6.16806@groups.io>
@ 2020-04-27 15:53   ` Wang, Jian J
  0 siblings, 0 replies; 3+ messages in thread
From: Wang, Jian J @ 2020-04-27 15:53 UTC (permalink / raw)
  To: devel@edk2.groups.io, Wang, Jian J, Jiang, Guomin; +Cc: Lu, XiaoyuX

Guomin,

One more comment.

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wang, Jian
> J
> Sent: Monday, April 27, 2020 4:17 PM
> To: Jiang, Guomin <guomin.jiang@intel.com>; devel@edk2.groups.io
> Cc: Lu, XiaoyuX <xiaoyux.lu@intel.com>
> Subject: Re: [edk2-devel] [PATCH v4] CryptoPkg/Pkcs7: Extend support for other
> OID types
> 
> Guomin,
> 
> A few comments below.
> 
> > -----Original Message-----
> > From: Jiang, Guomin <guomin.jiang@intel.com>
> > Sent: Sunday, April 26, 2020 1:40 PM
> > To: devel@edk2.groups.io
> > Cc: Wang, Jian J <jian.j.wang@intel.com>; Lu, XiaoyuX <xiaoyux.lu@intel.com>
> > Subject: [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2539
> >
> > Microsoft signtool supports creation of attached P7's with any OID payload
> > via the "/p7co" parameter. It is necessary to check the data before get
> > the string.
> >
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
> > Signed-off-by: Guomin Jiang <guomin.jiang@intel.com>
> > ---
> >  .../BaseCryptLib/Pk/CryptPkcs7VerifyBase.c    | 65 ++++++++++++++++++-
> >  1 file changed, 64 insertions(+), 1 deletion(-)
> >
> > diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> > b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> > index 313f459b11..70d9880897 100644
> > --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> > +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
> > @@ -13,6 +13,65 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> >  #include <openssl/x509v3.h>
> >
> >  #include <openssl/pkcs7.h>
> >
> >
> >
> > +/**
> >
> > +  Check the contents of PKCS7 is not data.
> >
> > +
> >
> > +  It is copied from PKCS7_type_is_other() in pk7_doit.c.
> >
> > +
> >
> > +  @param P7 Pointer to the location which the PKCS7 is located at.
> >
> > +
> >
> > +  @return UINT8 The content type.
> >
> > +**/
> >
> > +static
> 
> Please use STATIC instead, according to ch5.6.1.2 of "EDK II Coding
> Standards 2.1".
> 
> https://github.com/tianocore-
> docs/Docs/raw/master/Specifications/CCS_2_1_Draft.pdf
> 
> >
> > +UINT8
> >
> > +Pkcs7TypeIsOther (
> >
> > +  PKCS7 *P7
> 
> Missing IN/OUT modifier for parameter, according to ch5.7.1.11 of
> "EDK II Coding Standards 2.1". Add in/out in function parameter
> description comment as well.
> 
> https://github.com/tianocore-
> docs/Docs/raw/master/Specifications/CCS_2_1_Draft.pdf
> 
> >
> > +  )
> >
> > +{
> >
> > +  UINT8 Others = 1;
> >
> > +  UINT8 Nid = (UINT8) OBJ_obj2nid (P7->type);
> >

The nid in source data structure is defined as 'int'. I think edk2 INTN is the best shot
for type of 'Others', 'Nid' and return value.

Regards,
Jian
> > +
> >
> > +  switch (Nid) {
> >
> > +    case NID_pkcs7_data:
> >
> > +    case NID_pkcs7_signed:
> >
> > +    case NID_pkcs7_enveloped:
> >
> > +    case NID_pkcs7_signedAndEnveloped:
> >
> > +    case NID_pkcs7_encrypted:
> >
> > +      Others = 0;
> >
> > +      break;
> >
> > +    default:
> >
> > +      Others = 1;
> >
> > +  }
> >
> > +
> >
> > +  return Others;
> >
> > +}
> >
> > +
> >
> > +/**
> >
> > +  Get the ASN.1 string for the PKCS7.
> >
> > +
> >
> > +  It is copied from PKCS7_get_octet_string() in pk7_doit.c.
> >
> > +  @param P7 Pointer to the location which the PKCS7 is located at.
> >
> > +
> >
> > +  @return ASN1_OCTET_STRING ASN.1 string.
> >
> > +**/
> >
> > +static
> 
> Same as above, use STATIC instead.
> 
> >
> > +ASN1_OCTET_STRING*
> >
> > +Pkcs7GetOctetString (
> >
> > +  PKCS7 *P7
> 
> Missing IN/OUT modifier for parameter, according to ch5.7.1.11 of
> "EDK II Coding Standards 2.1". Add in/out in function parameter
> description comment as well.
> 
> Regards,
> Jian
> 
> >
> > +  )
> >
> > +{
> >
> > +  if (PKCS7_type_is_data (P7)) {
> >
> > +    return P7->d.data;
> >
> > +  }
> >
> > +
> >
> > +  if ((Pkcs7TypeIsOther(P7) == 1) && P7->d.other &&
> >
> > +      (P7->d.other->type == V_ASN1_OCTET_STRING)) {
> >
> > +    return P7->d.other->value.octet_string;
> >
> > +  }
> >
> > +
> >
> > +  return NULL;
> >
> > +}
> >
> > +
> >
> >  /**
> >
> >    Extracts the attached content from a PKCS#7 signed data if existed. The input
> > signed
> >
> >    data could be wrapped in a ContentInfo structure.
> >
> > @@ -98,7 +157,11 @@ Pkcs7GetAttachedContent (
> >      //
> >
> >      // Retrieve the attached content in PKCS7 signedData
> >
> >      //
> >
> > -    OctStr = Pkcs7->d.sign->contents->d.data;
> >
> > +    OctStr = Pkcs7GetOctetString (Pkcs7->d.sign->contents);
> >
> > +    if (OctStr == NULL) {
> >
> > +      goto _Exit;
> >
> > +    }
> >
> > +
> >
> >      if ((OctStr->length > 0) && (OctStr->data != NULL)) {
> >
> >        *ContentSize = OctStr->length;
> >
> >        *Content     = AllocatePool (*ContentSize);
> >
> > --
> > 2.25.1.windows.1
> 
> 
> 


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

end of thread, other threads:[~2020-04-27 15:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-26  5:40 [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types Guomin Jiang
2020-04-27  8:16 ` Wang, Jian J
     [not found] ` <16099F3AD41E60C6.16806@groups.io>
2020-04-27 15:53   ` [edk2-devel] " Wang, Jian J

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