Get RFC with regular expresion

This commit is contained in:
Mauricio Baeza 2021-07-18 22:01:59 -05:00
parent 482a10aa5d
commit 315decd98a
1 changed files with 3 additions and 5 deletions

View File

@ -2,6 +2,7 @@
import base64
import datetime
import re
from subprocess import check_output
from dateutil.parser import parse
from conf import TOKEN
@ -58,13 +59,10 @@ class SATCertificate(object):
def _get_data_cer(self, cer):
# ~ RFC
sep = 'x500UniqueIdentifier = '
cmd = f'{self.OPENSSL} x509 -inform der -in "{cer}" -noout -subject'
result = check_output(cmd, shell=True).decode()
if not sep in result:
sep = 'x500UniqueIdentifier='
self._rfc = result.split(sep)[1].split(' /')[0]
pattern = r'[A-Z]{3,4}[0-9]{6}[A-Z0-9]{3}'
self._rfc = re.search(pattern, result)[0]
# ~ Serial number
sep = '='
cmd = f'{self.OPENSSL} x509 -inform der -in "{cer}" -noout -serial'