From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=yunhuax.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B713F210DF758 for ; Tue, 7 Aug 2018 23:57:09 -0700 (PDT) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2018 23:57:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,456,1526367600"; d="dat'59?scan'59,208,59";a="252271527" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga005.fm.intel.com with ESMTP; 07 Aug 2018 23:56:58 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 7 Aug 2018 23:56:57 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.143]) with mapi id 14.03.0319.002; Wed, 8 Aug 2018 14:56:55 +0800 From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" CC: "Zhu, Yonghong" , "Gao, Liming" Thread-Topic: [PATCH 3/3] BaseTools: Use hashlib instead of md5 Thread-Index: AdQu5P3ry6kwjoDJQfu2J37fVDYZrA== Date: Wed, 8 Aug 2018 06:56:55 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC48B6A34@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC48B6A34@shsmsx102.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.27 Subject: [PATCH 3/3] BaseTools: Use hashlib instead of md5 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Aug 2018 06:57:09 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Use from hashlib import md5 instead of import md5 due to md5 deprecated in python3 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py | 4 ++-- BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py | 4 ++-- BaseTools/Source/Python/UPT/InstallPkg.py | 12 ++++++------ BaseTools/Source/Python/UPT/MkPkg.py | 4 ++-- BaseTools/Source/Python/UPT/RmPkg.py | 4 ++-- BaseTools/Source/Python/Workspace/MetaFileParser.py | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py b/BaseTo= ols/Source/Python/UPT/GenMetaFile/GenDecFile.py index 0ba07ccebc..e2dd6a02dc 100644 --- a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py +++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py @@ -17,11 +17,11 @@ GenDEC ''' import os import stat import codecs -import md5 +from hashlib import md5 from Core.FileHook import __FileHookOpen__ from Library.Parsing import GenSection from Library.CommentGenerating import GenHeaderCommentSection from Library.CommentGenerating import GenGenericCommentF from Library.CommentGenerating import GenDecTailComment @@ -644,11 +644,11 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHea= der =3D '', Encoding=3DTAB_ENCO Content +=3D PcdErrString =20 File =3D codecs.open(ContainerFile, 'w', Encoding) File.write(u'\uFEFF' + Content) File.stream.close() - Md5Sigature =3D md5.new(__FileHookOpen__(str(ContainerFile), 'rb').rea= d()) + Md5Sigature =3D md5(__FileHookOpen__(str(ContainerFile), 'rb').read()) Md5Sum =3D Md5Sigature.hexdigest() if (ContainerFile, Md5Sum) not in PackageObject.FileList: PackageObject.FileList.append((ContainerFile, Md5Sum)) =20 return ContainerFile diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py b/BaseTo= ols/Source/Python/UPT/GenMetaFile/GenInfFile.py index b62c705137..c2a240a884 100644 --- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py +++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py @@ -16,11 +16,11 @@ GenInf ''' import os import stat import codecs -import md5 +from hashlib import md5 from Core.FileHook import __FileHookOpen__ from Library.StringUtils import GetSplitValueList from Library.Parsing import GenSection from Library.Parsing import GetWorkspacePackage from Library.Parsing import ConvertArchForInstall @@ -253,11 +253,11 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeade= r=3D'', Encoding=3DDT.TAB_ENCOD =20 if not os.path.exists(ContainerFile): File =3D codecs.open(ContainerFile, 'wb', Encoding) File.write(u'\uFEFF' + Content) File.stream.close() - Md5Sigature =3D md5.new(__FileHookOpen__(str(ContainerFile), 'rb').rea= d()) + Md5Sigature =3D md5(__FileHookOpen__(str(ContainerFile), 'rb').read()) Md5Sum =3D Md5Sigature.hexdigest() if (ContainerFile, Md5Sum) not in ModuleObject.FileList: ModuleObject.FileList.append((ContainerFile, Md5Sum)) =20 return ContainerFile diff --git a/BaseTools/Source/Python/UPT/InstallPkg.py b/BaseTools/Source/P= ython/UPT/InstallPkg.py index 3573886d5a..c553d707fd 100644 --- a/BaseTools/Source/Python/UPT/InstallPkg.py +++ b/BaseTools/Source/Python/UPT/InstallPkg.py @@ -21,11 +21,11 @@ from Core.FileHook import __FileHookOpen__ import os.path from os import chmod from os import SEEK_SET from os import SEEK_END import stat -import md5 +from hashlib import md5 import copy from sys import stdin from sys import platform from shutil import rmtree from shutil import copyfile @@ -174,11 +174,11 @@ def UnZipDp(WorkspaceDir, DpPkgFileName, Index=3D1): =20 # # verify MD5 signature when existed # if DistPkg.Header.Signature !=3D '': - Md5Sigature =3D md5.new(__FileHookOpen__(ContentFile, 'rb').read()= ) + Md5Sigature =3D md5(__FileHookOpen__(ContentFile, 'rb').read()) if DistPkg.Header.Signature !=3D Md5Sigature.hexdigest(): ContentZipFile.Close() Logger.Error("InstallPkg", FILE_CHECKSUM_FAILURE, ExtraData=3DContentFile) =20 @@ -213,11 +213,11 @@ def GetPackageList(DistPkg, Dep, WorkspaceDir, Option= s, ContentZipFile, ModuleLi # all packages installed, else hard to resolve modules' package # dependency (Hard to get the location of the newly installed package) # for Package in PackageList: FilePath =3D PackageToDec(Package, DistPkg.Header) - Md5Sigature =3D md5.new(__FileHookOpen__(str(FilePath), 'rb').read= ()) + Md5Sigature =3D md5(__FileHookOpen__(str(FilePath), 'rb').read()) Md5Sum =3D Md5Sigature.hexdigest() if (FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) =20 return NewDict @@ -273,11 +273,11 @@ def GetModuleList(DistPkg, Dep, WorkspaceDir, Content= ZipFile, ModuleList): # generate all inf for modules # for (Module, Package) in ModuleList: CheckCNameInModuleRedefined(Module, DistPkg) FilePath =3D ModuleToInf(Module, Package, DistPkg.Header) - Md5Sigature =3D md5.new(__FileHookOpen__(str(FilePath), 'rb').read= ()) + Md5Sigature =3D md5(__FileHookOpen__(str(FilePath), 'rb').read()) Md5Sum =3D Md5Sigature.hexdigest() if Package: if (FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) else: @@ -801,11 +801,11 @@ def InstallFile(ContentZipFile, FromFile, ToFile, Rea= dOnly, Executable=3DFalse): chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | sta= t.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOT= H) else: chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | sta= t.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) =20 - Md5Sigature =3D md5.new(__FileHookOpen__(str(ToFile), 'rb').read()) + Md5Sigature =3D md5(__FileHookOpen__(str(ToFile), 'rb').read()) Md5Sum =3D Md5Sigature.hexdigest() =20 return Md5Sum =20 ## InstallPackageContent method @@ -874,11 +874,11 @@ def InstallPackageContent(FromPath, ToPath, Package, = ContentZipFile, Dep, continue if ReadOnly: chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH) else: chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IW= USR|stat.S_IWGRP|stat.S_IWOTH) - Md5Sigature =3D md5.new(__FileHookOpen__(str(ToFile), 'rb').read()= ) + Md5Sigature =3D md5(__FileHookOpen__(str(ToFile), 'rb').read()) Md5Sum =3D Md5Sigature.hexdigest() if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) Package.SetIncludeArchList(PackageIncludeArchList) =20 diff --git a/BaseTools/Source/Python/UPT/MkPkg.py b/BaseTools/Source/Python= /UPT/MkPkg.py index 37942b8ed9..053d115547 100644 --- a/BaseTools/Source/Python/UPT/MkPkg.py +++ b/BaseTools/Source/Python/UPT/MkPkg.py @@ -25,11 +25,11 @@ from os import chdir import os.path from sys import stdin from sys import platform from traceback import format_exc from platform import python_version -import md5 +from hashlib import md5 from time import strftime from time import localtime from uuid import uuid4 =20 from Logger import StringTable as ST @@ -194,11 +194,11 @@ def Main(Options =3D None): ContentFileClosed =3D True =20 # # Add Md5Sigature # - DistPkg.Header.Signature =3D md5.new(open(str(ContentFile), 'rb').= read()).hexdigest() + DistPkg.Header.Signature =3D md5(open(str(ContentFile), 'rb').read= ()).hexdigest() # # Add current Date # DistPkg.Header.Date =3D str(strftime("%Y-%m-%dT%H:%M:%S", localtim= e())) =20 diff --git a/BaseTools/Source/Python/UPT/RmPkg.py b/BaseTools/Source/Python= /UPT/RmPkg.py index 78469dc758..f1d141c736 100644 --- a/BaseTools/Source/Python/UPT/RmPkg.py +++ b/BaseTools/Source/Python/UPT/RmPkg.py @@ -21,11 +21,11 @@ RmPkg # import os.path from stat import S_IWUSR from traceback import format_exc from platform import python_version -import md5 +from hashlib import md5 from sys import stdin from sys import platform =20 from Core.DependencyRules import DependencyRules from Library import GlobalData @@ -240,11 +240,11 @@ def RemoveDist(Guid, Version, StoredDistFile, DataBas= e, WorkspaceDir, ForceRemov NewFileList.remove(Path) if not ForceRemove: # # check whether modified by users # - Md5Sigature =3D md5.new(open(str(Path), 'rb').read()) + Md5Sigature =3D md5(open(str(Path), 'rb').read()) if Md5Sum !=3D Md5Sigature.hexdigest(): Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path) Input =3D stdin.readline() Input =3D Input.replace('\r', '').replace('\n', '') if Input.upper() !=3D 'Y': diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/Source/Python/Workspace/MetaFileParser.py index 2b1ab40439..7bfe0933a1 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -19,11 +19,11 @@ from __future__ import print_function from __future__ import absolute_import import Common.LongFilePathOs as os import re import time import copy -import md5 +from hashlib import md5 =20 import Common.EdkLogger as EdkLogger import Common.GlobalData as GlobalData =20 from CommonDataClass.DataClass import * @@ -1927,14 +1927,14 @@ class DecParser(MetaFileParser): self._ValueList =3D None self._include_flag =3D False return =20 if self._include_flag: - self._ValueList[1] =3D "_" + md5.new(self= ._CurrentLine).hexdigest() + self._ValueList[1] =3D "_" + md5(self._Cu= rrentLine).hexdigest() self._ValueList[2] =3D self._CurrentLine if self._package_flag and "}" !=3D self._CurrentLine: - self._ValueList[1] =3D "_" + md5.new(self._C= urrentLine).hexdigest() + self._ValueList[1] =3D "_" + md5(self._Curre= ntLine).hexdigest() self._ValueList[2] =3D self._CurrentLine if self._CurrentLine =3D=3D "}": self._package_flag =3D False self._include_flag =3D False self._ValueList =3D None --=20 2.12.2.windows.2