Fix - Obtener RFC del certificado
This commit is contained in:
parent
570f81f3eb
commit
a8930f17ed
|
@ -331,7 +331,8 @@ class Certificado(object):
|
||||||
result = _call(args.format(self._path_cer, 'serial'))
|
result = _call(args.format(self._path_cer, 'serial'))
|
||||||
serie = result.split('=')[1].split('\n')[0][1::2]
|
serie = result.split('=')[1].split('\n')[0][1::2]
|
||||||
result = _call(args.format(self._path_cer, 'subject'))
|
result = _call(args.format(self._path_cer, 'subject'))
|
||||||
rfc = result.split('=')[5].split('/')[0].strip()
|
#~ rfc = result.split('=')[5].split('/')[0].strip()
|
||||||
|
rfc = result.split('x500UniqueIdentifier = ')[1][:13].strip()
|
||||||
|
|
||||||
if not DEBUG:
|
if not DEBUG:
|
||||||
if not rfc == session_rfc:
|
if not rfc == session_rfc:
|
||||||
|
@ -359,14 +360,12 @@ class Certificado(object):
|
||||||
|
|
||||||
args = 'openssl x509 -inform DER -in "{}" -out "{}"'
|
args = 'openssl x509 -inform DER -in "{}" -out "{}"'
|
||||||
_call(args.format(self._path_cer, tmp_cer))
|
_call(args.format(self._path_cer, tmp_cer))
|
||||||
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:{} -out "{}"'
|
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:"{}" -out "{}"'
|
||||||
_call(args.format(self._path_key, password, tmp_key))
|
_call(args.format(self._path_key, password, tmp_key))
|
||||||
|
|
||||||
args = 'openssl pkcs12 -export -in "{}" -inkey "{}" -name "{}" -passout ' \
|
args = 'openssl pkcs12 -export -in "{}" -inkey "{}" -name "{}" ' \
|
||||||
'pass:"{}" -out "{}"'
|
'-passout pass:"{}" -out "{}"'
|
||||||
_call(args.format(tmp_cer, tmp_key, rfc,
|
_call(args.format(tmp_cer, tmp_key, rfc, _get_md5(rfc), tmp_p12))
|
||||||
hashlib.md5(rfc.encode()).hexdigest(), tmp_p12))
|
|
||||||
#~ data = open(tmp_p12, 'rb').read()
|
|
||||||
data = read_file(tmp_p12)
|
data = read_file(tmp_p12)
|
||||||
|
|
||||||
self._kill(tmp_cer)
|
self._kill(tmp_cer)
|
||||||
|
@ -378,14 +377,14 @@ class Certificado(object):
|
||||||
def _get_info_key(self, password, rfc):
|
def _get_info_key(self, password, rfc):
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:{}'
|
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:"{}"'
|
||||||
try:
|
try:
|
||||||
result = _call(args.format(self._path_key, password))
|
result = _call(args.format(self._path_key, password))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.error = 'Contraseña incorrecta'
|
self.error = 'Contraseña incorrecta'
|
||||||
return data
|
return data
|
||||||
|
|
||||||
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:{} | ' \
|
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:"{}" | ' \
|
||||||
'openssl rsa -noout -modulus'
|
'openssl rsa -noout -modulus'
|
||||||
mod_key = _call(args.format(self._path_key, password))
|
mod_key = _call(args.format(self._path_key, password))
|
||||||
|
|
||||||
|
@ -393,8 +392,8 @@ class Certificado(object):
|
||||||
self.error = 'Los archivos no son pareja'
|
self.error = 'Los archivos no son pareja'
|
||||||
return data
|
return data
|
||||||
|
|
||||||
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:{} | ' \
|
args = 'openssl pkcs8 -inform DER -in "{}" -passin pass:"{}" | ' \
|
||||||
'openssl rsa -des3 -passout pass:{}'.format(
|
'openssl rsa -des3 -passout pass:"{}"'.format(
|
||||||
self._path_key, password, _get_md5(rfc))
|
self._path_key, password, _get_md5(rfc))
|
||||||
key_enc = _call(args)
|
key_enc = _call(args)
|
||||||
|
|
||||||
|
@ -442,7 +441,7 @@ def make_xml(data, certificado):
|
||||||
'pass': _get_md5(certificado.rfc)
|
'pass': _get_md5(certificado.rfc)
|
||||||
}
|
}
|
||||||
args = '"{xsltproc}" "{xslt}" "{xml}" | ' \
|
args = '"{xsltproc}" "{xslt}" "{xml}" | ' \
|
||||||
'"{openssl}" dgst -sha256 -sign "{key}" -passin pass:{pass} | ' \
|
'"{openssl}" dgst -sha256 -sign "{key}" -passin pass:"{pass}" | ' \
|
||||||
'"{openssl}" enc -base64 -A'.format(**data)
|
'"{openssl}" enc -base64 -A'.format(**data)
|
||||||
sello = _call(args)
|
sello = _call(args)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue