mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 19:42:02 +02:00
Migrate certbot-compatibility-test to cryptography (as much as possible (#10117)
Also fixed a typing error.
This commit is contained in:
@@ -18,7 +18,7 @@ from typing import Optional
|
|||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
|
||||||
from OpenSSL import crypto
|
from cryptography.hazmat.primitives import serialization
|
||||||
from urllib3.util import connection
|
from urllib3.util import connection
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
@@ -147,10 +147,10 @@ def test_installer(args: argparse.Namespace, plugin: common.Proxy, config: str,
|
|||||||
|
|
||||||
def test_deploy_cert(plugin: common.Proxy, temp_dir: str, domains: List[str]) -> bool:
|
def test_deploy_cert(plugin: common.Proxy, temp_dir: str, domains: List[str]) -> bool:
|
||||||
"""Tests deploy_cert returning True if the tests are successful"""
|
"""Tests deploy_cert returning True if the tests are successful"""
|
||||||
cert = crypto_util.gen_ss_cert(util.KEY, domains)
|
cert = crypto_util.gen_ss_cert(util.KEY, domains).to_cryptography()
|
||||||
cert_path = os.path.join(temp_dir, "cert.pem")
|
cert_path = os.path.join(temp_dir, "cert.pem")
|
||||||
with open(cert_path, "wb") as f:
|
with open(cert_path, "wb") as f:
|
||||||
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
|
f.write(cert.public_bytes(serialization.Encoding.PEM))
|
||||||
|
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
try:
|
try:
|
||||||
@@ -390,7 +390,7 @@ def _fake_dns_resolution(resolved_ip: str) -> Generator[None, None, None]:
|
|||||||
"""Monkey patch urllib3 to make any hostname be resolved to the provided IP"""
|
"""Monkey patch urllib3 to make any hostname be resolved to the provided IP"""
|
||||||
_original_create_connection = connection.create_connection
|
_original_create_connection = connection.create_connection
|
||||||
|
|
||||||
def _patched_create_connection(address: Tuple[str, str],
|
def _patched_create_connection(address: Tuple[str, int],
|
||||||
*args: Any, **kwargs: Any) -> socket.socket:
|
*args: Any, **kwargs: Any) -> socket.socket:
|
||||||
_, port = address
|
_, port = address
|
||||||
return _original_create_connection((resolved_ip, port), *args, **kwargs)
|
return _original_create_connection((resolved_ip, port), *args, **kwargs)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from typing import Mapping
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from OpenSSL import crypto
|
from cryptography import x509
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from acme import crypto_util
|
from acme import crypto_util
|
||||||
@@ -21,7 +21,7 @@ _VALIDATION_TIMEOUT = 10
|
|||||||
class Validator:
|
class Validator:
|
||||||
"""Collection of functions to test a live webserver's configuration"""
|
"""Collection of functions to test a live webserver's configuration"""
|
||||||
|
|
||||||
def certificate(self, cert: crypto.X509, name: Union[str, bytes],
|
def certificate(self, cert: x509.Certificate, name: Union[str, bytes],
|
||||||
alt_host: Optional[str] = None, port: int = 443) -> bool:
|
alt_host: Optional[str] = None, port: int = 443) -> bool:
|
||||||
"""Verifies the certificate presented at name is cert"""
|
"""Verifies the certificate presented at name is cert"""
|
||||||
if alt_host is None:
|
if alt_host is None:
|
||||||
@@ -39,7 +39,7 @@ class Validator:
|
|||||||
logger.exception(str(error))
|
logger.exception(str(error))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return presented_cert.digest("sha256") == cert.digest("sha256")
|
return presented_cert.to_cryptography() == cert
|
||||||
|
|
||||||
def redirect(self, name: str, port: int = 80,
|
def redirect(self, name: str, port: int = 80,
|
||||||
headers: Optional[Mapping[str, str]] = None) -> bool:
|
headers: Optional[Mapping[str, str]] = None) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user