|
|
import os
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
import testinfra.utils.ansible_runner
|
|
|
|
|
|
from tls_ciphers import ALL_CIPHERS
|
|
|
|
|
|
|
|
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
|
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional')
|
|
@@ -33,18 +37,47 @@ def test_tls_version(host):
|
|
|
assert tls1_2_enabled.rc == 0
|
|
|
|
|
|
|
|
|
def test_tls_ciphers(host):
|
|
|
ENABLED_CIPHERS = [
|
|
|
"DHE-RSA-AES128-GCM-SHA256",
|
|
|
"DHE-RSA-AES128-SHA256",
|
|
|
"DHE-RSA-AES256-GCM-SHA384",
|
|
|
"DHE-RSA-AES256-SHA256",
|
|
|
"ECDHE-RSA-AES128-GCM-SHA256",
|
|
|
"ECDHE-RSA-AES128-SHA",
|
|
|
"ECDHE-RSA-AES128-SHA256",
|
|
|
"ECDHE-RSA-AES256-GCM-SHA384",
|
|
|
"ECDHE-RSA-AES256-SHA384",
|
|
|
]
|
|
|
|
|
|
DISABLED_CIPHERS = sorted(list(set(ALL_CIPHERS)-set(ENABLED_CIPHERS)))
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("cipher", ENABLED_CIPHERS)
|
|
|
def test_enabled_tls_ciphers(host, cipher):
|
|
|
"""
|
|
|
Tests available TLS ciphers on the server.
|
|
|
"""
|
|
|
|
|
|
hostname = host.run('hostname').stdout.strip()
|
|
|
fqdn = hostname[:hostname.rfind('-')]
|
|
|
|
|
|
client = host.run("echo 'Q' | openssl s_client -cipher %s -connect %s:443", cipher, fqdn)
|
|
|
assert client.rc == 0
|
|
|
assert cipher in client.stdout
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("cipher", DISABLED_CIPHERS)
|
|
|
def test_disabled_tls_ciphers(host, cipher):
|
|
|
"""
|
|
|
Tests available TLS ciphers on the server.
|
|
|
"""
|
|
|
|
|
|
cipher = host.run("echo 'Q' | openssl s_client -cipher ECDHE-RSA-AES128-SHA256 -connect parameters-optional:443")
|
|
|
assert cipher.rc == 0
|
|
|
assert "ECDHE-RSA-AES128-SHA256" in cipher.stdout
|
|
|
hostname = host.run('hostname').stdout.strip()
|
|
|
fqdn = hostname[:hostname.rfind('-')]
|
|
|
|
|
|
cipher = host.run("echo 'Q' | openssl s_client -cipher ECDHE-RSA-AES128-SHA -connect parameters-optional:443")
|
|
|
assert cipher.rc == 0
|
|
|
assert "ECDHE-RSA-AES128-SHA" in cipher.stdout
|
|
|
client = host.run("echo 'Q' | openssl s_client -cipher %s -connect %s:443", cipher, fqdn)
|
|
|
assert client.rc != 0
|
|
|
assert cipher not in client.stdout
|
|
|
|
|
|
|
|
|
def test_https_enforcement(host):
|