Get data cer in cert sign
This commit is contained in:
parent
2d8b9bb378
commit
489266e7b3
|
@ -132,7 +132,7 @@ class CertValidate(object):
|
|||
def issuer(self):
|
||||
return self._issuer
|
||||
|
||||
def _get_data_cer(self, cer):
|
||||
def get_data_cer(self, cer: bytes):
|
||||
obj = x509.load_der_x509_certificate(cer, default_backend())
|
||||
self._rfc = obj.subject.get_attributes_for_oid(
|
||||
NameOID.X500_UNIQUE_IDENTIFIER)[0].value.split(' ')[0]
|
||||
|
@ -193,7 +193,7 @@ class CertValidate(object):
|
|||
return key_pem
|
||||
|
||||
def validate(self, cer: bytes, key: bytes, password: str) -> bool:
|
||||
self._get_data_cer(cer)
|
||||
self.get_data_cer(cer)
|
||||
self._get_data_key(key, password)
|
||||
return self.is_valid
|
||||
|
||||
|
@ -210,6 +210,10 @@ class CertSign(object):
|
|||
pw = get_hash(words)
|
||||
self._key = serialization.load_pem_private_key(key_file, pw, default_backend())
|
||||
|
||||
def get_data_cer(self, cer: bytes):
|
||||
cer = CertValidate().get_data_cer(cer)
|
||||
return cer
|
||||
|
||||
def sign(self, data, type_hash: str='sha256'):
|
||||
if isinstance(data, str):
|
||||
data = data.encode()
|
||||
|
|
|
@ -100,7 +100,6 @@ class TestCertValidate(BaseTest):
|
|||
key = path_key.read_bytes()
|
||||
|
||||
result = cert.validate(cer, key, PASSWORD)
|
||||
# ~ print(cert)
|
||||
|
||||
self.assertTrue(result)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue