Skip to content

Commit 2ec029f

Browse files
committed
fix: Check md5 & sha1 usage
1 parent 69c7e5a commit 2ec029f

20 files changed

Lines changed: 38 additions & 37 deletions

File tree

src/DIRAC/AccountingSystem/private/MainReporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __calculateReportHash(self, reportRequest):
3939
for key in ("startTime", "endTime"):
4040
epoch = requestToHash[key]
4141
requestToHash[key] = epoch - epoch % granularity
42-
md5Hash = hashlib.md5()
42+
md5Hash = hashlib.md5(usedforsecurity=False)
4343
md5Hash.update(repr(requestToHash).encode())
4444
return md5Hash.hexdigest()
4545

src/DIRAC/Core/DISET/MessageClient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __generateUniqueClientName(self):
3131
hashStr = ":".join(
3232
(str(datetime.datetime.utcnow()), str(random.random()), Network.getFQDN(), gLogger.getName())
3333
)
34-
hexHash = md5(hashStr.encode()).hexdigest()
34+
hexHash = md5(hashStr.encode(), usedforsecurity=False).hexdigest()
3535
return hexHash
3636

3737
def setUniqueName(self, uniqueName):

src/DIRAC/Core/DISET/private/FileHelper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FileHelper:
2020
def __init__(self, oTransport=None, checkSum=True):
2121
self.oTransport = oTransport
2222
self.__checkMD5 = checkSum
23-
self.__oMD5 = hashlib.md5()
23+
self.__oMD5 = hashlib.md5(usedforsecurity=False)
2424
self.bFinishedTransmission = False
2525
self.bReceivedEOF = False
2626
self.direction = False
@@ -149,7 +149,7 @@ def networkToFD(self, iFD, maxFileSize=0):
149149
def networkToDataSink(self, dataSink, maxFileSize=0):
150150
if "write" not in dir(dataSink):
151151
return S_ERROR(f"{str(dataSink)} data sink object does not have a write method")
152-
self.__oMD5 = hashlib.md5()
152+
self.__oMD5 = hashlib.md5(usedforsecurity=False)
153153
self.bReceivedEOF = False
154154
self.bErrorInMD5 = False
155155
receivedBytes = 0
@@ -212,7 +212,7 @@ def stringToNetwork(self, stringVal):
212212
return S_OK()
213213

214214
def FDToNetwork(self, iFD):
215-
self.__oMD5 = hashlib.md5()
215+
self.__oMD5 = hashlib.md5(usedforsecurity=False)
216216
iPacketSize = self.packetSize
217217
self.__fileBytes = 0
218218
sentBytes = 0
@@ -244,7 +244,7 @@ def BufferToNetwork(self, stringToSend):
244244
def DataSourceToNetwork(self, dataSource):
245245
if "read" not in dir(dataSource):
246246
return S_ERROR(f"{str(dataSource)} data source object does not have a read method")
247-
self.__oMD5 = hashlib.md5()
247+
self.__oMD5 = hashlib.md5(usedforsecurity=False)
248248
iPacketSize = self.packetSize
249249
self.__fileBytes = 0
250250
sentBytes = 0

src/DIRAC/Core/DISET/private/Transports/BaseTransport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, stServerAddress, bServerMode=False, **kwargs):
5353
self.remoteAddress = False
5454
self.appData = ""
5555
self.startedKeepAlives = set()
56-
self.keepAliveId = md5((str(stServerAddress) + str(bServerMode)).encode()).hexdigest()
56+
self.keepAliveId = md5((str(stServerAddress) + str(bServerMode)).encode(), usedforsecurity=False).hexdigest()
5757
self.receivedMessages = []
5858
self.sentKeepAlives = 0
5959
self.waitingForKeepAlivePong = False

src/DIRAC/Core/Security/m2crypto/X509Chain.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __init__(self, certList=False, keyObj=False):
144144
# This is the position of the first proxy in the chain
145145
self.__firstProxyStep = 0
146146

147-
# Cache for sha1 hash of the object
147+
# Cache for sha256 hash of the object
148148
# This is just used as a unique identifier for
149149
# indexing in the ProxyCache
150150
self.__hash = False
@@ -1004,25 +1004,25 @@ def getCredentials(self, ignoreDefault=False, withRegistryInfo=True):
10041004

10051005
@needCertList
10061006
def hash(self):
1007-
"""Get a hash of the chain
1007+
"""Get a hash of the chain (32 byte hex-string is returned)
10081008
In practice, this is only used to index the chain in a DictCache
10091009
10101010
:returns: S_OK(string hash)
10111011
"""
10121012
if self.__hash:
10131013
return S_OK(self.__hash)
1014-
sha1 = hashlib.sha1()
1014+
sha = hashlib.sha256()
10151015
for cert in self._certList:
1016-
sha1.update(str(cert.getSubjectNameObject()["Value"]).encode())
1017-
sha1.update(str(self.getRemainingSecs()["Value"] / 3600).encode())
1018-
sha1.update(self.getDIRACGroup()["Value"].encode())
1016+
sha.update(str(cert.getSubjectNameObject()["Value"]).encode())
1017+
sha.update(str(self.getRemainingSecs()["Value"] / 3600).encode())
1018+
sha.update(self.getDIRACGroup()["Value"].encode())
10191019
if self.isVOMS():
1020-
sha1.update(b"VOMS")
1020+
sha.update(b"VOMS")
10211021
from DIRAC.Core.Security.VOMS import VOMS
10221022

10231023
result = VOMS().getVOMSAttributes(self)
10241024
if result["OK"]:
10251025
for attribute in result["Value"]:
1026-
sha1.update(attribute.encode())
1027-
self.__hash = sha1.hexdigest()
1028-
return S_OK(self.__hash)
1026+
sha.update(attribute.encode())
1027+
self.__hash = sha.hexdigest()
1028+
return S_OK(self.__hash[:32])

src/DIRAC/Core/Utilities/File.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def makeGuid(fileName=None):
6969
7070
:param string fileName: name of file
7171
"""
72-
myMd5 = hashlib.md5()
72+
myMd5 = hashlib.md5(usedforsecurity=False)
7373
if fileName:
7474
try:
7575
with open(fileName, "rb") as fd:
@@ -106,7 +106,7 @@ def generateGuid(checksum, checksumtype):
106106
return guid
107107

108108
# Failed to use the check sum, generate a new guid
109-
myMd5 = hashlib.md5()
109+
myMd5 = hashlib.md5(usedforsecurity=False)
110110
myMd5.update(str(random.getrandbits(128)).encode())
111111
md5HexString = myMd5.hexdigest()
112112
guid = "{}-{}-{}-{}-{}".format(
@@ -213,7 +213,7 @@ def getMD5ForFiles(fileList):
213213
:type fileList: python:list
214214
"""
215215
fileList.sort()
216-
hashMD5 = hashlib.md5()
216+
hashMD5 = hashlib.md5(usedforsecurity=False)
217217
for filePath in fileList:
218218
if os.path.isdir(filePath):
219219
continue

src/DIRAC/Core/Utilities/Graphs/Palette.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def getColor(self, label):
8383
return self.generateColor(label)
8484

8585
def generateColor(self, label):
86-
myMD5 = hashlib.md5()
86+
myMD5 = hashlib.md5(usedforsecurity=False)
8787
myMD5.update(label.encode())
8888
hexstring = myMD5.hexdigest()
8989
color = "#" + hexstring[:6]

src/DIRAC/Core/Utilities/LockRing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def __init__(self):
1515

1616
def __genName(self, container):
1717
# TODO: Shouldn't this be a UUID?
18-
name = md5(str(time.time() + random.random()).encode()).hexdigest()
18+
name = md5(str(time.time() + random.random()).encode(), usedforsecurity=False).hexdigest()
1919
retries = 10
2020
while name in container and retries:
21-
name = md5(str(time.time() + random.random()).encode()).hexdigest()
21+
name = md5(str(time.time() + random.random()).encode(), usedforsecurity=False).hexdigest()
2222
retries -= 1
2323
return name
2424

src/DIRAC/Core/Utilities/ThreadScheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def addPeriodicTask(self, period, taskFunc, taskArgs=(), executions=0, elapsedTi
3232
return S_ERROR(f"{str(taskFunc)} is not callable")
3333
period = max(period, self.__minPeriod)
3434
elapsedTime = min(elapsedTime, period - 1)
35-
md = hashlib.md5()
35+
md = hashlib.md5(usedforsecurity=False)
3636
task = {
3737
"period": period,
3838
"func": taskFunc,

src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/DatasetManager/DatasetManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def __getMetaQueryParameters(self, metaQuery, credDict):
321321
idLfnDict = result["Value"]
322322
lfnIDList = list(idLfnDict)
323323
lfnList = sorted(idLfnDict.values())
324-
myMd5 = hashlib.md5()
324+
myMd5 = hashlib.md5(usedforsecurity=False)
325325
myMd5.update(str(lfnList).encode())
326326
datasetHash = myMd5.hexdigest().upper()
327327
numberOfFiles = len(lfnList)

0 commit comments

Comments
 (0)