From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.120]) by mx.groups.io with SMTP id smtpd.web12.1436.1579201639959809261 for ; Thu, 16 Jan 2020 11:07:20 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gmR3QIf6; spf=pass (domain: redhat.com, ip: 205.139.110.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579201639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GCytShX9QaE/2FClrVoDBKB0FchnUOVPqcTJQGpRSJM=; b=gmR3QIf6DiLwc/XwaxHA4NAeMN3FTC0HNXJCLepx7MhdJXitqwPl35TkeVh1TS7VH8DqqY 3ehOI29YzusplpQMhXKfJdDsq73Ml97fvM/Op+obIaOEi2zhTJ4Ad5vrIGVMcsNknUyLFp LhshR7A8+LMofBwhciXTG2mL8dPC+HI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-LKCc0JB0OECKx4SrCa4gfg-1; Thu, 16 Jan 2020 14:07:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C39141005502; Thu, 16 Jan 2020 19:07:14 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-120.ams2.redhat.com [10.36.116.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7E0184333; Thu, 16 Jan 2020 19:07:13 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Chao Zhang , Jian J Wang , Jiewen Yao Subject: [PATCH 04/11] SecurityPkg/DxeImageVerificationHandler: narrow down PE/COFF hash status Date: Thu, 16 Jan 2020 20:06:58 +0100 Message-Id: <20200116190705.18816-5-lersek@redhat.com> In-Reply-To: <20200116190705.18816-1-lersek@redhat.com> References: <20200116190705.18816-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: LKCc0JB0OECKx4SrCa4gfg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: base64 SW5zaWRlIHRoZSAiZm9yIiBsb29wIHRoYXQgc2NhbnMgdGhlIHNpZ25hdHVyZXMgb2YgdGhlIGlt YWdlLCB3ZSBjYWxsCkhhc2hQZUltYWdlQnlUeXBlKCksIGFuZCBhc3NpZ24gaXRzIHJldHVybiB2 YWx1ZSB0byAiU3RhdHVzIi4KCkJleW9uZCB0aGUgaW1tZWRpYXRlIHJldHZhbCBjaGVjaywgdGhp cyBhc3NpZ25tZW50IGlzIHVzZWxlc3MgKG5ldmVyCmNvbnN1bWVkKS4gVGhhdCdzIGJlY2F1c2Ug YSBzdWJzZXF1ZW50IGFjY2VzcyB0byAiU3RhdHVzIiBtYXkgb25seSBiZSBvbmUKb2YgdGhlIGZv bGxvd2luZzoKCi0gdGhlICJTdGF0dXMiIGFzc2lnbm1lbnQgd2hlbiB3ZSBjYWxsIEhhc2hQZUlt YWdlQnlUeXBlKCkgaW4gdGhlIG5leHQKICBpdGVyYXRpb24gb2YgdGhlIGxvb3AsCgotIHRoZSAi U3RhdHVzID0gRUZJX0FDQ0VTU19ERU5JRUQiIGFzc2lnbm1lbnQgcmlnaHQgYWZ0ZXIgdGhlIGZp bmFsCiAgIklzVmVyaWZpZWQiIGNoZWNrLgoKVG8gbWFrZSBpdCBjbGVhciB0aGF0IHRoZSBhc3Np Z25tZW50IGlzIG9ubHkgdXNlZnVsIGZvciB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XJpdHlQa2cvTGlicmFyeS9EeGVJbWFnZVZlcmlmaWNhdGlvbkxpYi9EeGVJ bWFnZVZlcmlmaWNhdGlvbkxpYi5jCkBAIC0xNTU2LDM0OSArMTU1NiwzNTAgQEAgRUZJQVBJCiBE eGVJbWFnZVZlcmlmaWNhdGlvbkhhbmRsZXIgKA0KICAgSU4gIFVJTlQzMiAgICAgICAgICAgICAg ICAgICAgICAgICAgIEF1dGhlbnRpY2F0aW9uU3RhdHVzLA0KICAgSU4gIENPTlNUIEVGSV9ERVZJ Q0VfUEFUSF9QUk9UT0NPTCAgICpGaWxlLA0KICAgSU4gIFZPSUQgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICpGaWxlQnVmZmVyLA0KICAgSU4gIFVJTlROICAgICAgICAgICAgICAgICAgICAg ICAgICAgIEZpbGVTaXplLA0KICAgSU4gIEJPT0xFQU4gICAgICAgICAgICAgICAgICAgICAgICAg IEJvb3RQb2xpY3kNCiAgICkNCiB7DQogICBFRklfU1RBVFVTICAgICAgICAgICAgICAgICAgICAg ICAgICAgU3RhdHVzOw0KICAgRUZJX0lNQUdFX0RPU19IRUFERVIgICAgICAgICAgICAgICAgICpE b3NIZHI7DQogICBCT09MRUFOICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSXNWZXJpZmll ZDsNCiAgIEVGSV9TSUdOQVRVUkVfTElTVCAgICAgICAgICAgICAgICAgICAqU2lnbmF0dXJlTGlz dDsNCiAgIFVJTlROICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBTaWduYXR1cmVMaXN0 U2l6ZTsNCiAgIEVGSV9TSUdOQVRVUkVfREFUQSAgICAgICAgICAgICAgICAgICAqU2lnbmF0dXJl Ow0KICAgRUZJX0lNQUdFX0VYRUNVVElPTl9BQ1RJT04gICAgICAgICAgIEFjdGlvbjsNCiAgIFdJ Tl9DRVJUSUZJQ0FURSAgICAgICAgICAgICAgICAgICAgICAqV2luQ2VydGlmaWNhdGU7DQogICBV SU5UMzIgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUG9saWN5Ow0KICAgVUlOVDggICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICpTZWN1cmVCb290Ow0KICAgUEVfQ09GRl9MT0FE RVJfSU1BR0VfQ09OVEVYVCAgICAgICAgIEltYWdlQ29udGV4dDsNCiAgIFVJTlQzMiAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICBOdW1iZXJPZlJ2YUFuZFNpemVzOw0KICAgV0lOX0NFUlRJ RklDQVRFX0VGSV9QS0NTICAgICAgICAgICAgICpQa2NzQ2VydERhdGE7DQogICBXSU5fQ0VSVElG SUNBVEVfVUVGSV9HVUlEICAgICAgICAgICAgKldpbkNlcnRVZWZpR3VpZDsNCiAgIFVJTlQ4ICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqQXV0aERhdGE7DQogICBVSU5UTiAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgQXV0aERhdGFTaXplOw0KICAgRUZJX0lNQUdFX0RBVEFf RElSRUNUT1JZICAgICAgICAgICAgICpTZWNEYXRhRGlyOw0KICAgVUlOVDMyICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgIE9mZlNldDsNCiAgIENIQVIxNiAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAqTmFtZVN0cjsNCiAgIFJFVFVSTl9TVEFUVVMgICAgICAgICAgICAgICAgICAg ICAgICBQZUNvZmZTdGF0dXM7DQorICBFRklfU1RBVFVTICAgICAgICAgICAgICAgICAgICAgICAg ICAgSGFzaFN0YXR1czsNCiANCiAgIFNpZ25hdHVyZUxpc3QgICAgID0gTlVMTDsNCiAgIFNpZ25h dHVyZUxpc3RTaXplID0gMDsNCiAgIFdpbkNlcnRpZmljYXRlICAgID0gTlVMTDsNCiAgIFNlY0Rh dGFEaXIgICAgICAgID0gTlVMTDsNCiAgIFBrY3NDZXJ0RGF0YSAgICAgID0gTlVMTDsNCiAgIEFj dGlvbiAgICAgICAgICAgID0gRUZJX0l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