Skip to content

Commit

Permalink
refactor: Optimise ASN1 decoding in X509Certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Dec 19, 2024
1 parent 8ba45d2 commit 6632c9b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/DIRAC/Core/Security/m2crypto/X509Certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import random
import time

import M2Crypto.m2
import M2Crypto.ASN1
import M2Crypto.X509


Expand Down Expand Up @@ -211,8 +213,8 @@ def getNotAfterDate(self):
:returns: S_OK( datetime )/S_ERROR
"""

notAfter = self.__certObj.get_not_after().get_datetime()
rawNotAfter = M2Crypto.m2.x509_get_not_after(self.__certObj.x509)
notAfter = M2Crypto.ASN1.ASN1_TIME(rawNotAfter).get_datetime()

# M2Crypto does things correctly by setting a timezone info in the datetime
# However, we do not in DIRAC, and so we can't compare the dates.
Expand Down Expand Up @@ -242,7 +244,8 @@ def getNotBeforeDate(self):
:returns: S_OK( datetime )/S_ERROR
"""
return S_OK(self.__certObj.get_not_before().get_datetime())
rawNotBefore = M2Crypto.m2.x509_get_not_before(self.__certObj.x509)
return S_OK(M2Crypto.ASN1.ASN1_TIME(rawNotBefore).get_datetime())

# @executeOnlyIfCertLoaded
# def setNotBefore(self, notbefore):
Expand Down

0 comments on commit 6632c9b

Please sign in to comment.