mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 03:22:14 +02:00
Migrate get_serial_from_cert and valid_privkey to cryptography (#10116)
This commit is contained in:
@@ -268,11 +268,14 @@ def valid_privkey(privkey: Union[str, bytes]) -> bool:
|
|||||||
:rtype: bool
|
:rtype: bool
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if isinstance(privkey, str):
|
||||||
|
privkey = privkey.encode()
|
||||||
try:
|
try:
|
||||||
return crypto.load_privatekey(
|
serialization.load_pem_private_key(privkey, password=None)
|
||||||
crypto.FILETYPE_PEM, privkey).check()
|
except ValueError:
|
||||||
except (TypeError, crypto.Error):
|
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def verify_renewable_cert(renewable_cert: interfaces.RenewableCert) -> None:
|
def verify_renewable_cert(renewable_cert: interfaces.RenewableCert) -> None:
|
||||||
@@ -604,10 +607,9 @@ def get_serial_from_cert(cert_path: str) -> int:
|
|||||||
:returns: serial number of the certificate
|
:returns: serial number of the certificate
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
# pylint: disable=redefined-outer-name
|
|
||||||
with open(cert_path, "rb") as f:
|
with open(cert_path, "rb") as f:
|
||||||
x509 = crypto.load_certificate(crypto.FILETYPE_PEM, f.read())
|
cert = x509.load_pem_x509_certificate(f.read())
|
||||||
return x509.get_serial_number()
|
return cert.serial_number
|
||||||
|
|
||||||
|
|
||||||
def find_chain_with_issuer(fullchains: List[str], issuer_cn: str,
|
def find_chain_with_issuer(fullchains: List[str], issuer_cn: str,
|
||||||
|
|||||||
Reference in New Issue
Block a user