Changeset - a7cd31c6886d
[Not reviewed]
0 3 0
Branko Majic (branko) - 4 years ago 2020-05-18 16:45:24
branko@majic.rs
MAR-153: Use custom Diffie-Helman parameters for SMTP server in the mail_server role.
3 files changed with 53 insertions and 0 deletions:
0 comments (0 inline, 0 general)
roles/mail_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -355,3 +355,44 @@ def test_firewall_configuration_file(host):
 
        assert config.user == 'root'
 
        assert config.group == 'root'
 
        assert config.mode == 0o640
 

	
 

	
 
def test_smtp_server_dh_parameter_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_smtp.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_smtp_server_uses_correct_dh_parameters(host):
 
    """
 
    Tests if the SMTP server uses the generated Diffie-Helman parameter.
 
    """
 

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

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

	
 
    connection = host.run("gnutls-cli --no-ca-verification --starttls-proto=smtp --port 25 --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/mail_server/tasks/main.yml
Show inline comments
 
@@ -59,6 +59,16 @@
 
  notify:
 
    - Restart Postfix
 

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

	
 
- name: Deploy IMAP TLS private key
 
  copy:
 
    dest: "/etc/ssl/private/{{ ansible_fqdn }}_imap.key"
roles/mail_server/templates/main.cf.j2
Show inline comments
 
@@ -54,6 +54,8 @@ smtpd_tls_security_level = may
 
smtpd_tls_auth_only = yes
 
smtpd_tls_cert_file = /etc/ssl/certs/{{ ansible_fqdn }}_smtp.pem
 
smtpd_tls_key_file = /etc/ssl/private/{{ ansible_fqdn }}_smtp.key
 
smtpd_tls_dh1024_param_file = /etc/ssl/private/{{ inventory_hostname }}_smtp.dh.pem
 
smtpd_tls_dh512_param_file = /etc/ssl/private/{{ inventory_hostname }}_smtp.dh.pem
 
smtpd_use_tls=yes
 
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
 
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
0 comments (0 inline, 0 general)