Changeset - a8ad1fdf6f60
[Not reviewed]
0 4 0
Branko Majic (branko) - 4 years ago 2020-05-19 15:26:09
branko@majic.rs
MAR-153: Use custom Diffie-Helman parameters for HTTP(S) server in the web_server role.
4 files changed with 58 insertions and 0 deletions:
0 comments (0 inline, 0 general)
roles/web_server/molecule/default/prepare.yml
Show inline comments
 
@@ -18,6 +18,11 @@
 
        update_cache: true
 
      changed_when: false
 

	
 
    - name: Install tools for testing
 
      apt:
 
        name: gnutls-bin
 
        state: present
 

	
 
- hosts: stretch
 
  become: true
 
  tasks:
roles/web_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -234,3 +234,45 @@ def test_php_timezone_configuration(host, php_info):
 
    timezone = host.run("php --php-ini %s -r %s", "%s/fpm/php.ini" % php_info.base_config_dir, "echo ini_get('date.timezone');")
 
    assert timezone.rc == 0
 
    assert timezone.stdout == server_timezone
 

	
 

	
 
def test_https_server_dh_parameters_file(host):
 
    """
 
    Tests if the Diffie-Helman parameter file has been generated
 
    correctly.
 
    """
 

	
 
    hostname = host.run('hostname').stdout.strip()
 
    dhparam_file_path = '/etc/ssl/private/%s_https.dh.pem' % hostname
 

	
 
    with host.sudo():
 
        dhparam_file = host.file(dhparam_file_path)
 
        assert dhparam_file.is_file
 
        assert dhparam_file.user == 'root'
 
        assert dhparam_file.group == 'root'
 
        assert dhparam_file.mode == 0o640
 

	
 
        dhparam_info = host.run("openssl dhparam -noout -text -in %s", dhparam_file_path)
 

	
 
        assert "DH Parameters: (2048 bit)" in dhparam_info.stdout
 

	
 

	
 
def test_https_server_uses_correct_dh_parameters(host):
 
    """
 
    Tests if the HTTP server uses the generated Diffie-Helman parameter.
 
    """
 

	
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    with host.sudo():
 
        expected_dhparam = host.file('/etc/ssl/private/%s_https.dh.pem' % hostname).content_string.rstrip()
 

	
 
    connection = host.run("gnutls-cli --no-ca-verification --starttls-proto=https --port 443 "
 
                          "--priority 'NONE:+VERS-TLS1.2:+CTYPE-X509:+COMP-NULL:+SIGN-RSA-SHA384:+DHE-RSA:+SHA384:+AEAD:+AES-256-GCM' --verbose localhost")
 

	
 
    output = connection.stdout
 
    begin_marker = "-----BEGIN DH PARAMETERS-----"
 
    end_marker = "-----END DH PARAMETERS-----"
 
    used_dhparam = output[output.find(begin_marker):output.find(end_marker) + len(end_marker)]
 

	
 
    assert used_dhparam == expected_dhparam
roles/web_server/tasks/main.yml
Show inline comments
 
@@ -33,6 +33,16 @@
 
  notify:
 
    - Restart nginx
 

	
 
- name: Generate the HTTPS server Diffie-Helman parameter
 
  openssl_dhparam:
 
    owner: root
 
    group: root
 
    mode: 0640
 
    path: "/etc/ssl/private/{{ ansible_fqdn }}_https.dh.pem"
 
    size: 2048
 
  notify:
 
    - Restart nginx
 

	
 
- name: Deploy configuration file for checking certificate validity via cron
 
  copy:
 
    content: "/etc/ssl/certs/{{ ansible_fqdn }}_https.pem"
roles/web_server/templates/tls.conf.j2
Show inline comments
 
ssl_protocols {{ web_server_tls_protocols | join(" ") }};
 
ssl_ciphers {{ web_server_tls_ciphers }};
 
ssl_dhparam /etc/ssl/private/{{ ansible_fqdn }}_https.dh.pem;
0 comments (0 inline, 0 general)