| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2017 Red Hat, Inc. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# License: GPL (version 3 or any later version). |
| 6 |
# See LICENSE for details. |
| 7 |
# --- END COPYRIGHT BLOCK --- |
| 8 |
# |
| 9 |
import logging |
| 10 |
import os |
| 11 |
import pytest |
| 12 |
from lib389.utils import ds_is_older |
| 13 |
from lib389.idm.services import ServiceAccounts |
| 14 |
from lib389.config import CertmapLegacy |
| 15 |
from lib389._constants import DEFAULT_SUFFIX |
| 16 |
from lib389.replica import ReplicationManager, Replicas |
| 17 |
from test389.topologies import topology_m2 as topo_m2 |
| 18 |
|
| 19 |
pytestmark = pytest.mark.tier1 |
| 20 |
|
| 21 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 22 |
if DEBUGGING: |
| 23 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 24 |
else: |
| 25 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 26 |
log = logging.getLogger(__name__) |
| 27 |
|
| 28 |
|
| 29 |
@pytest.fixture(scope="module") |
| 30 |
def tls_client_auth(topo_m2): |
| 31 |
"""Enable TLS on both suppliers and reconfigure |
| 32 |
both agreements to use TLS Client auth |
| 33 |
""" |
| 34 |
|
| 35 |
m1 = topo_m2.ms['supplier1'] |
| 36 |
m2 = topo_m2.ms['supplier2'] |
| 37 |
|
| 38 |
if ds_is_older('1.4.0.6'): |
| 39 |
transport = 'SSL' |
| 40 |
else: |
| 41 |
transport = 'LDAPS' |
| 42 |
|
| 43 |
# Create the certmap before we restart for enable_tls |
| 44 |
cm_m1 = CertmapLegacy(m1) |
| 45 |
cm_m2 = CertmapLegacy(m2) |
| 46 |
|
| 47 |
# We need to configure the same maps for both .... |
| 48 |
certmaps = cm_m1.list() |
| 49 |
certmaps['default']['DNComps'] = None |
| 50 |
certmaps['default']['CmapLdapAttr'] = 'nsCertSubjectDN' |
| 51 |
|
| 52 |
cm_m1.set(certmaps) |
| 53 |
cm_m2.set(certmaps) |
| 54 |
|
| 55 |
[i.enable_tls() for i in topo_m2] |
| 56 |
|
| 57 |
# Create the replication dns |
| 58 |
services = ServiceAccounts(m1, DEFAULT_SUFFIX) |
| 59 |
repl_m1 = services.get(f'{DEFAULT_SUFFIX}:{m1.host}:{m1.sslport}') |
| 60 |
repl_m1.set('nsCertSubjectDN', m1.get_server_tls_subject()) |
| 61 |
|
| 62 |
repl_m2 = services.get(f'{DEFAULT_SUFFIX}:{m2.host}:{m2.sslport}') |
| 63 |
repl_m2.set('nsCertSubjectDN', m2.get_server_tls_subject()) |
| 64 |
|
| 65 |
# Check the replication is "done". |
| 66 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 67 |
repl.wait_for_replication(m1, m2) |
| 68 |
# Now change the auth type |
| 69 |
|
| 70 |
replica_m1 = Replicas(m1).get(DEFAULT_SUFFIX) |
| 71 |
agmt_m1 = replica_m1.get_agreements().list()[0] |
| 72 |
|
| 73 |
agmt_m1.replace_many( |
| 74 |
('nsDS5ReplicaBindMethod', 'SSLCLIENTAUTH'), |
| 75 |
('nsDS5ReplicaTransportInfo', transport), |
| 76 |
('nsDS5ReplicaPort', str(m2.sslport)), |
| 77 |
) |
| 78 |
agmt_m1.remove_all('nsDS5ReplicaBindDN') |
| 79 |
|
| 80 |
replica_m2 = Replicas(m2).get(DEFAULT_SUFFIX) |
| 81 |
agmt_m2 = replica_m2.get_agreements().list()[0] |
| 82 |
|
| 83 |
agmt_m2.replace_many( |
| 84 |
('nsDS5ReplicaBindMethod', 'SSLCLIENTAUTH'), |
| 85 |
('nsDS5ReplicaTransportInfo', transport), |
| 86 |
('nsDS5ReplicaPort', str(m1.sslport)), |
| 87 |
) |
| 88 |
agmt_m2.remove_all('nsDS5ReplicaBindDN') |
| 89 |
|
| 90 |
repl.test_replication_topology(topo_m2) |
| 91 |
|
| 92 |
return topo_m2 |
| 93 |
|
| 94 |
|
| 95 |
def test_ssl_transport(tls_client_auth): |
| 96 |
"""Test different combinations for nsDS5ReplicaTransportInfo values |
| 97 |
|
| 98 |
:id: a3157108-cb98-43e9-ba16-8fb21a4a03e9 |
| 99 |
:setup: Two supplier replication, enabled TLS client auth |
| 100 |
:steps: |
| 101 |
1. Set nsDS5ReplicaTransportInfoCheck: SSL or StartTLS or TLS |
| 102 |
2. Restart the instance |
| 103 |
3. Check that replication works |
| 104 |
4. Set nsDS5ReplicaTransportInfoCheck: LDAPS back |
| 105 |
:expectedresults: |
| 106 |
1. Success |
| 107 |
2. Success |
| 108 |
3. Replication works |
| 109 |
4. Success |
| 110 |
""" |
| 111 |
|
| 112 |
m1 = tls_client_auth.ms['supplier1'] |
| 113 |
m2 = tls_client_auth.ms['supplier2'] |
| 114 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 115 |
replica_m1 = Replicas(m1).get(DEFAULT_SUFFIX) |
| 116 |
replica_m2 = Replicas(m2).get(DEFAULT_SUFFIX) |
| 117 |
agmt_m1 = replica_m1.get_agreements().list()[0] |
| 118 |
agmt_m2 = replica_m2.get_agreements().list()[0] |
| 119 |
|
| 120 |
if ds_is_older('1.4.0.6'): |
| 121 |
check_list = (('TLS', False),) |
| 122 |
else: |
| 123 |
check_list = (('SSL', True), ('StartTLS', False), ('TLS', False)) |
| 124 |
|
| 125 |
for transport, secure_port in check_list: |
| 126 |
agmt_m1.replace_many(('nsDS5ReplicaTransportInfo', transport), |
| 127 |
('nsDS5ReplicaPort', '{}'.format(m2.port if not secure_port else m2.sslport))) |
| 128 |
agmt_m2.replace_many(('nsDS5ReplicaTransportInfo', transport), |
| 129 |
('nsDS5ReplicaPort', '{}'.format(m1.port if not secure_port else m1.sslport))) |
| 130 |
repl.test_replication_topology(tls_client_auth) |
| 131 |
|
| 132 |
if ds_is_older('1.4.0.6'): |
| 133 |
agmt_m1.replace_many(('nsDS5ReplicaTransportInfo', 'SSL'), |
| 134 |
('nsDS5ReplicaPort', str(m2.sslport))) |
| 135 |
agmt_m2.replace_many(('nsDS5ReplicaTransportInfo', 'SSL'), |
| 136 |
('nsDS5ReplicaPort', str(m1.sslport))) |
| 137 |
else: |
| 138 |
agmt_m1.replace_many(('nsDS5ReplicaTransportInfo', 'LDAPS'), |
| 139 |
('nsDS5ReplicaPort', str(m2.sslport))) |
| 140 |
agmt_m2.replace_many(('nsDS5ReplicaTransportInfo', 'LDAPS'), |
| 141 |
('nsDS5ReplicaPort', str(m1.sslport))) |
| 142 |
repl.test_replication_topology(tls_client_auth) |
| 143 |
|
| 144 |
|
| 145 |
def test_extract_pemfiles(tls_client_auth): |
| 146 |
"""Test TLS client authentication between two suppliers operates |
| 147 |
as expected with 'on' and 'off' options of nsslapd-extract-pemfiles |
| 148 |
|
| 149 |
:id: 922d16f8-662a-4915-a39e-0aecd7c8e6e1 |
| 150 |
:setup: Two supplier replication, enabled TLS client auth |
| 151 |
:steps: |
| 152 |
1. Check that nsslapd-extract-pemfiles default value is right |
| 153 |
2. Check that replication works with both 'on' and 'off' values |
| 154 |
:expectedresults: |
| 155 |
1. Success |
| 156 |
2. Replication works |
| 157 |
""" |
| 158 |
|
| 159 |
m1 = tls_client_auth.ms['supplier1'] |
| 160 |
m2 = tls_client_auth.ms['supplier2'] |
| 161 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 162 |
|
| 163 |
if ds_is_older('1.3.7'): |
| 164 |
default_val = 'off' |
| 165 |
else: |
| 166 |
default_val = 'on' |
| 167 |
attr_val = m1.config.get_attr_val_utf8('nsslapd-extract-pemfiles') |
| 168 |
log.info("Check that nsslapd-extract-pemfiles is {}".format(default_val)) |
| 169 |
assert attr_val == default_val |
| 170 |
|
| 171 |
for extract_pemfiles in ('on', 'off'): |
| 172 |
log.info("Set nsslapd-extract-pemfiles = '{}' and check replication works)") |
| 173 |
m1.config.set('nsslapd-extract-pemfiles', extract_pemfiles) |
| 174 |
m2.config.set('nsslapd-extract-pemfiles', extract_pemfiles) |
| 175 |
repl.test_replication_topology(tls_client_auth) |
| 176 |
|