From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.2163.1588121539406216934 for ; Tue, 28 Apr 2020 17:52:19 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: guomin.jiang@intel.com) IronPort-SDR: LLQGS+NO+3mFtQ+t9C7HwejdN9wzPMkgjJ/IA/OemcXDH87SS0GL+8DbrBIoo+0ziEOzMCNOSg 5haeRzIHt02g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2020 17:52:17 -0700 IronPort-SDR: j/PchO61oBqhAfrFzr/QGFEAA8TBTblZfOPHQycIb9VbE00T4ki0KmNpROUt1LKDEb/Q9fPjvp QdQXU51m7+mQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,329,1583222400"; d="scan'208";a="293044921" Received: from guominji-mobl.ccr.corp.intel.com ([10.238.5.173]) by fmsmga002.fm.intel.com with ESMTP; 28 Apr 2020 17:52:16 -0700 From: "Guomin Jiang" To: devel@edk2.groups.io Cc: Jian J Wang , Xiaoyu Lu Subject: [PATCH v6] CryptoPkg/Pkcs7: Extend support for other OID types Date: Wed, 29 Apr 2020 08:52:15 +0800 Message-Id: <20200429005215.597-1-guomin.jiang@intel.com> X-Mailer: git-send-email 2.25.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Xiaoyu Lu Signed-off-by: Guomin Jiang Reviewed-by: Jian J Wang --- .../BaseCryptLib/Pk/CryptPkcs7VerifyBase.c | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c index 313f459b11..112c13c226 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c @@ -13,6 +13,67 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +/** + Check the contents of PKCS7 is not data. + + It is copied from PKCS7_type_is_other() in pk7_doit.c. + + @param[in] P7 Pointer to the location at which the PKCS7 is located. + + @retval TRUE If the type is others. + @retval FALSE If the type is expected. +**/ +STATIC +BOOLEAN +Pkcs7TypeIsOther ( + IN PKCS7 *P7 + ) +{ + BOOLEAN Others; + INTN Nid = 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 = FALSE; + break; + default: + Others = TRUE; + } + + return Others; +} + +/** + Get the ASN.1 string for the PKCS7. + + It is copied from PKCS7_get_octet_string() in pk7_doit.c. + + @param[in] P7 Pointer to the location at which the PKCS7 is located. + + @return ASN1_OCTET_STRING ASN.1 string. +**/ +STATIC +ASN1_OCTET_STRING* +Pkcs7GetOctetString ( + IN PKCS7 *P7 + ) +{ + if (PKCS7_type_is_data (P7)) { + return P7->d.data; + } + + if (Pkcs7TypeIsOther(P7) && (P7->d.other != NULL) && + (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 +159,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