From nobody Tue May 21 00:59:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+57175+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57175+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1586485880; cv=none; d=zohomail.com; s=zohoarc; b=UpQUub88D6FyJzdrLi4pVgvWQT1dMVTzxLJcMSO13OBa7E4HiEGoIh8/jm8YAdgv3qJLsfvwll5VY2ocM1kM0pMY/lnMnlUhYSxPC5X/qWHck/Q9SnuBRFq3S4DPg/7koAgTRZeu0VVUDHsgZrDXmJTQKHJQq6712ubXcpNhugE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586485880; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Kyb9OFeNp8aMNi7gj+x9yiINzlk7P5d831FM+yOR5xo=; b=JNWl5sLkJWDrgKhbCgwpoqKmSYlS7iVWHEFS2Wyndr6+7e7cd70oh7i15x31Z7yTdmJyYi91zLdls1q1P6Eub6VdcxujMS94rfMLe4GgPcbeApZjnNyT1RF45aQ/BbYi3sadZ1vsLxcHhqYcCNfzkdF08jka6tlbyTM4OLs/j5I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57175+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1586485880834682.1277518187887; Thu, 9 Apr 2020 19:31:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hS0UYY1788612xwm5oA4Pj9t; Thu, 09 Apr 2020 19:31:20 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.2281.1586485879345299175 for ; Thu, 09 Apr 2020 19:31:19 -0700 IronPort-SDR: Pivym21tqazepS1C6QFBd2TvW4veJHBeApF600N5b9hAqoI9Xf38bXlzA7bD6Fps60+eTb+qqt KPQQoy/f8k+w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 19:31:19 -0700 IronPort-SDR: 28C2hnUd77XkAxUGJg0BGaCdAG4eMcIIaQP3tIP9P7DUXbcv2ieDElvD4+dbfqbfIXOkSaEQkH 5IZWGQfRkXRA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,364,1580803200"; d="scan'208";a="452241709" X-Received: from unknown (HELO guominji-MOBL.ccr.corp.intel.com) ([10.239.158.147]) by fmsmga005.fm.intel.com with ESMTP; 09 Apr 2020 19:31:17 -0700 From: "Guomin Jiang" To: devel@edk2.groups.io Cc: Jian J Wang , Xiaoyu Lu Subject: [edk2-devel] [PATCH v3] CryptoPkg/Pkcs7: Extend support for other OID types Date: Fri, 10 Apr 2020 10:31:17 +0800 Message-Id: <20200410023117.1322-1-guomin.jiang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,guomin.jiang@intel.com X-Gm-Message-State: BfkwydtXLsim1Jh551cRRMDfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1586485880; bh=0W5g9OBP7AtSWz9GMrZNdXB7SMAEg785WxL0oyV3DTU=; h=Cc:Date:From:Reply-To:Subject:To; b=OIBH2BBfseVmJenmoyOMf8spDkwmqLh19BOqtXlDPvQBUAKpuAYse8pzB3LRhDY0kBw YPWUyhX2my3bRjLtoKIl61kpgEgVqLdUoFuG5VxNAmI1sVUHgOjS//AgcCOT5rFTz2S9R Vc69byh5pIuSdMxrbehLe13wYN4ll8xHYbo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2539 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 --- .../BaseCryptLib/Pk/CryptPkcs7VerifyBase.c | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c b/Cry= ptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c index 313f459b11..00840e7f83 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c @@ -13,6 +13,63 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include =20 +/** + 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 int The content type. +**/ +static +int +Pkcs7TypeIsOther ( + PKCS7 *p7 + ) +{ + int isOthers =3D 1; + int nid =3D 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: + isOthers =3D 0; + break; + default: + isOthers =3D 1; + } + + return isOthers; +} + +/** + 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) && p7->d.other && + (p7->d.other->type =3D=3D 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 +155,11 @@ Pkcs7GetAttachedContent ( // // Retrieve the attached content in PKCS7 signedData // - OctStr =3D Pkcs7->d.sign->contents->d.data; + OctStr =3D Pkcs7GetOctetString (Pkcs7->d.sign->contents); + if (OctStr =3D=3D NULL) { + goto _Exit; + } + if ((OctStr->length > 0) && (OctStr->data !=3D NULL)) { *ContentSize =3D OctStr->length; *Content =3D AllocatePool (*ContentSize); --=20 2.25.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#57175): https://edk2.groups.io/g/devel/message/57175 Mute This Topic: https://groups.io/mt/72912787/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-