|
@@ -1,5 +1,6 @@
|
|
|
import re
|
|
|
import subprocess
|
|
|
+import os
|
|
|
|
|
|
import backoff
|
|
|
import docker
|
|
@@ -80,12 +81,17 @@ def negotiate_cipher(sut_container, additional_params='', grep='Cipher is'):
|
|
|
raise Exception("Failed to process CLI request:\n" + e.stderr) from None
|
|
|
|
|
|
|
|
|
-def can_negotiate_dhe_ciphersuite(sut_container):
|
|
|
- r = negotiate_cipher(sut_container, "-cipher 'EDH'")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def can_negotiate_dhe_ciphersuite(sut_container, dh_bits=4096, additional_params=''):
|
|
|
+ openssl_params = f"-cipher 'EDH' {additional_params}"
|
|
|
+
|
|
|
+ r = negotiate_cipher(sut_container, openssl_params)
|
|
|
assert "New, TLSv1.2, Cipher is DHE-RSA-AES256-GCM-SHA384\n" == r
|
|
|
|
|
|
- r2 = negotiate_cipher(sut_container, "-cipher 'EDH'", "Server Temp Key")
|
|
|
- assert "DH" in r2
|
|
|
+ r2 = negotiate_cipher(sut_container, openssl_params, "Server Temp Key")
|
|
|
+ assert f"Server Temp Key: DH, {dh_bits} bits" in r2
|
|
|
|
|
|
|
|
|
def cannot_negotiate_dhe_ciphersuite(sut_container):
|
|
@@ -101,6 +107,29 @@ def cannot_negotiate_dhe_ciphersuite(sut_container):
|
|
|
assert "X25519" in r3
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def can_verify_chain_of_trust(sut_container, ca_cert, fqdn):
|
|
|
+ openssl_params = f"-CAfile '{ca_cert}' -servername '{fqdn}'"
|
|
|
+
|
|
|
+ r = negotiate_cipher(sut_container, openssl_params, "Verify return code")
|
|
|
+ assert "Verify return code: 0 (ok)" in r
|
|
|
+
|
|
|
+
|
|
|
+def should_be_equivalent_content(sut_container, expected, actual):
|
|
|
+ expected_checksum = sut_container.exec_run(f"md5sum {expected}").output.split()[0]
|
|
|
+ actual_checksum = sut_container.exec_run(f"md5sum {actual}").output.split()[0]
|
|
|
+
|
|
|
+ assert expected_checksum == actual_checksum
|
|
|
+
|
|
|
+
|
|
|
|
|
|
def get_env(sut_container, var):
|
|
|
env = sut_container.attrs['Config']['Env']
|
|
@@ -125,14 +154,17 @@ def test_default_dhparam_is_ffdhe4096(docker_compose):
|
|
|
|
|
|
assert_log_contains("Setting up DH Parameters..", container_name)
|
|
|
|
|
|
-
|
|
|
- default_checksum = sut_container.exec_run("md5sum /app/dhparam/ffdhe4096.pem").output.split()
|
|
|
- current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split()
|
|
|
- assert default_checksum[0] == current_checksum[0]
|
|
|
+
|
|
|
+ should_be_equivalent_content(
|
|
|
+ sut_container,
|
|
|
+ "/app/dhparam/ffdhe4096.pem",
|
|
|
+ "/etc/nginx/dhparam/dhparam.pem"
|
|
|
+ )
|
|
|
|
|
|
- can_negotiate_dhe_ciphersuite(sut_container)
|
|
|
+ can_negotiate_dhe_ciphersuite(sut_container, 4096)
|
|
|
|
|
|
|
|
|
+
|
|
|
def test_can_change_dhparam_group(docker_compose):
|
|
|
container_name="dh-env"
|
|
|
sut_container = docker_client.containers.get(container_name)
|
|
@@ -140,12 +172,14 @@ def test_can_change_dhparam_group(docker_compose):
|
|
|
|
|
|
assert_log_contains("Setting up DH Parameters..", container_name)
|
|
|
|
|
|
-
|
|
|
- default_checksum = sut_container.exec_run("md5sum /app/dhparam/ffdhe2048.pem").output.split()
|
|
|
- current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split()
|
|
|
- assert default_checksum[0] == current_checksum[0]
|
|
|
+
|
|
|
+ should_be_equivalent_content(
|
|
|
+ sut_container,
|
|
|
+ "/app/dhparam/ffdhe3072.pem",
|
|
|
+ "/etc/nginx/dhparam/dhparam.pem"
|
|
|
+ )
|
|
|
|
|
|
- can_negotiate_dhe_ciphersuite(sut_container)
|
|
|
+ can_negotiate_dhe_ciphersuite(sut_container, 3072)
|
|
|
|
|
|
|
|
|
def test_fail_if_dhparam_group_not_supported(docker_compose):
|
|
@@ -162,6 +196,7 @@ def test_fail_if_dhparam_group_not_supported(docker_compose):
|
|
|
)
|
|
|
|
|
|
|
|
|
+
|
|
|
def test_custom_dhparam_is_supported(docker_compose):
|
|
|
container_name="dh-file"
|
|
|
sut_container = docker_client.containers.get(container_name)
|
|
@@ -172,14 +207,49 @@ def test_custom_dhparam_is_supported(docker_compose):
|
|
|
container_name
|
|
|
)
|
|
|
|
|
|
-
|
|
|
- default_checksum = sut_container.exec_run("md5sum /app/dhparam/ffdhe4096.pem").output.split()
|
|
|
- current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split()
|
|
|
- assert default_checksum[0] != current_checksum[0]
|
|
|
+
|
|
|
+ should_be_equivalent_content(
|
|
|
+ sut_container,
|
|
|
+ "/app/dhparam/ffdhe3072.pem",
|
|
|
+ "/etc/nginx/dhparam/dhparam.pem"
|
|
|
+ )
|
|
|
+
|
|
|
+ can_negotiate_dhe_ciphersuite(sut_container, 3072)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def test_custom_dhparam_is_supported_per_site(docker_compose):
|
|
|
+ container_name="dh-file"
|
|
|
+ sut_container = docker_client.containers.get(container_name)
|
|
|
+ assert sut_container.status == "running"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ should_be_equivalent_content(
|
|
|
+ sut_container,
|
|
|
+ "/app/dhparam/ffdhe2048.pem",
|
|
|
+ "/etc/nginx/certs/web2.nginx-proxy.tld.dhparam.pem"
|
|
|
+ )
|
|
|
|
|
|
- can_negotiate_dhe_ciphersuite(sut_container)
|
|
|
+
|
|
|
+ can_negotiate_dhe_ciphersuite(sut_container, 2048, '-servername web2.nginx-proxy.tld')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ can_verify_chain_of_trust(
|
|
|
+ sut_container,
|
|
|
+ ca_cert = f"{os.getcwd()}/certs/ca-root.crt",
|
|
|
+ fqdn = 'web2.nginx-proxy.tld'
|
|
|
+ )
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def test_can_skip_dhparam(docker_compose):
|
|
|
container_name="dh-skip"
|
|
|
sut_container = docker_client.containers.get(container_name)
|
|
@@ -189,6 +259,7 @@ def test_can_skip_dhparam(docker_compose):
|
|
|
|
|
|
cannot_negotiate_dhe_ciphersuite(sut_container)
|
|
|
|
|
|
+
|
|
|
def test_can_skip_dhparam_backward_compatibility(docker_compose):
|
|
|
container_name="dh-skip-backward"
|
|
|
sut_container = docker_client.containers.get(container_name)
|