From nobody Sun May 19 15:20:03 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+58137+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+58137+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1587879614; cv=none; d=zohomail.com; s=zohoarc; b=MmQEk/YVqtJ5MPKG2umIbLuGKxohy23KIowEtQQ44SuHQKwVUrMPdGYt1oOm7lbpo91x5AF3moG0InbouRk6h5fYcm81RG3ziLMbkJEVoUf3tlSaiZ/lTdZ4gm/d8Ku2NhxotcGjuo3mxVddQgG5hKmoyQSzdMQfgwDASrQKwdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587879614; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=q7REnUGnsXBaMAznfqlPyJtlkJKYh3CxcItxoglXklA=; b=GlT87bTqdvK5lIOmGk8Z5WkyMorycHw6LJvHg8CwvCvHlzk0SRVlDY848Yi0DdPI5+GpFFxOprnyQ96yJqQoedolsIP+zhzqy6if8UDf0BhodxrtKf1sqzQDFbO3T79+V9N1Pdfkb5A8xObERJuQF8ZP6Jneqsz69RNyaGb8ZWU= 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+58137+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 1587879614483662.1039224600221; Sat, 25 Apr 2020 22:40:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id baSEYY1788612xX8NrmIrItT; Sat, 25 Apr 2020 22:40:14 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.6650.1587879612974656178 for ; Sat, 25 Apr 2020 22:40:13 -0700 IronPort-SDR: Dj5S/Gopk6cpfYr6yIqHdiZul7W0g5jWkRK3lfg7tSWP7POiRZ65/xyk+VG7A2hEzrES8ZD8Jy n2KpK4YRS/OA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:40:11 -0700 IronPort-SDR: fFuZYlh9xH3/SCJdhJ9G04wuJnZP5bnNEPqQKTXRuRmsG4r39jYaI0GS9HNt33MReWRKQYcSBq 6q7zrr8GfvKA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,318,1583222400"; d="scan'208";a="403859634" X-Received: from guominji-mobl.ccr.corp.intel.com ([10.238.5.173]) by orsmga004.jf.intel.com with ESMTP; 25 Apr 2020 22:40:10 -0700 From: "Guomin Jiang" To: devel@edk2.groups.io Cc: Jian J Wang , Xiaoyu Lu Subject: [edk2-devel] [PATCH v4] CryptoPkg/Pkcs7: Extend support for other OID types Date: Sun, 26 Apr 2020 13:40:09 +0800 Message-Id: <20200426054009.792-1-guomin.jiang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: <27952.devel.edk2.groups.io> 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: Q5u2BLa3r0TF0DMZr9G7Tpzdx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1587879614; bh=mwnG65UKWn9Pcw0YSS9iKfFxACKOTdPq2EEAZnyQBXs=; h=Cc:Date:From:Reply-To:Subject:To; b=n/r/fSjVr9BvTNYoIeKStySRuGkO9f412gVfnZk4Efap+C2pvx0JxtSMM4xEvwXqSjF z40QK4W2x+zMhshDUaKxEm08vWMyc5abOgUCPrtWuigNw4r7/aXg/ROlBSMGSg1ZVUaZE rKJ7Du1/2ojc0lTx2q3DmJjlSilaS4ru8FU= 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 | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c b/Cry= ptoPkg/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 #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 UINT8 The content type. +**/ +static +UINT8 +Pkcs7TypeIsOther ( + PKCS7 *P7 + ) +{ + UINT8 Others =3D 1; + UINT8 Nid =3D (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 =3D 0; + break; + default: + Others =3D 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) =3D=3D 1) && 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 +157,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 (#58137): https://edk2.groups.io/g/devel/message/58137 Mute This Topic: https://groups.io/mt/73277356/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-