Skip to content

Commit 86ecf2a

Browse files
authored
Merge pull request #7971 from DIRACGridBot/cherry-pick-2-e775ffada-integration
[sweep:integration] Optimise ASN1 decoding in X509Certificate
2 parents 0159c90 + 3f9998a commit 86ecf2a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import random
1111
import time
1212

13+
import M2Crypto.m2
14+
import M2Crypto.ASN1
1315
import M2Crypto.X509
1416

1517

@@ -211,8 +213,10 @@ def getNotAfterDate(self):
211213
212214
:returns: S_OK( datetime )/S_ERROR
213215
"""
214-
215-
notAfter = self.__certObj.get_not_after().get_datetime()
216+
# Here we use the M2Crypto low level API, as the high level API is notably
217+
# slower due to the conversion to a string and then back to an ASN1_TIME.
218+
rawNotAfter = M2Crypto.m2.x509_get_not_after(self.__certObj.x509) # pylint: disable=no-member
219+
notAfter = M2Crypto.ASN1.ASN1_TIME(rawNotAfter).get_datetime()
216220

217221
# M2Crypto does things correctly by setting a timezone info in the datetime
218222
# However, we do not in DIRAC, and so we can't compare the dates.
@@ -242,7 +246,10 @@ def getNotBeforeDate(self):
242246
:returns: S_OK( datetime )/S_ERROR
243247
244248
"""
245-
return S_OK(self.__certObj.get_not_before().get_datetime())
249+
# Here we use the M2Crypto low level API, as the high level API is notably
250+
# slower due to the conversion to a string and then back to an ASN1_TIME.
251+
rawNotBefore = M2Crypto.m2.x509_get_not_before(self.__certObj.x509) # pylint: disable=no-member
252+
return S_OK(M2Crypto.ASN1.ASN1_TIME(rawNotBefore).get_datetime())
246253

247254
# @executeOnlyIfCertLoaded
248255
# def setNotBefore(self, notbefore):

0 commit comments

Comments
 (0)