| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2022, William Brown <[email protected]> |
| 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 |
|
| 10 |
import pytest |
| 11 |
import ldap |
| 12 |
import os |
| 13 |
|
| 14 |
from lib389.nss_ssl import NssSsl |
| 15 |
from test389.topologies import topology_st |
| 16 |
|
| 17 |
pytestmark = pytest.mark.tier1 |
| 18 |
|
| 19 |
CA_CHAIN_FILE = os.path.join(os.path.dirname(__file__), '../../data/tls/tls_import_ca_chain.pem') |
| 20 |
CRT_CHAIN_FILE = os.path.join(os.path.dirname(__file__), '../../data/tls/tls_import_crt_chain.pem') |
| 21 |
KEY_CHAIN_FILE = os.path.join(os.path.dirname(__file__), '../../data/tls/tls_import_key_chain.pem') |
| 22 |
KEY_FILE = os.path.join(os.path.dirname(__file__), '../../data/tls/tls_import_key.pem') |
| 23 |
|
| 24 |
def test_tls_import_chain(topology_st): |
| 25 |
"""Test that TLS import will correct report errors when there are multiple |
| 26 |
files in a chain. |
| 27 |
|
| 28 |
:id: b7ba71bd-112a-44a1-8a7e-8968249da419 |
| 29 |
|
| 30 |
:steps: |
| 31 |
1. Attempt to import a ca chain |
| 32 |
|
| 33 |
:expectedresults: |
| 34 |
1. The chain is rejected |
| 35 |
""" |
| 36 |
topology_st.standalone.stop() |
| 37 |
tls = NssSsl(dirsrv=topology_st.standalone) |
| 38 |
tls.reinit() |
| 39 |
|
| 40 |
with pytest.raises(ValueError): |
| 41 |
tls.add_cert(nickname='CA_CHAIN_1', cert_file=CA_CHAIN_FILE) |
| 42 |
|
| 43 |
with pytest.raises(ValueError): |
| 44 |
tls.import_rsa_crt(crt=CRT_CHAIN_FILE) |
| 45 |
with pytest.raises(ValueError): |
| 46 |
tls.import_rsa_crt(ca=CA_CHAIN_FILE) |
| 47 |
|
| 48 |
def test_tls_import_chain_pk12util(topology_st): |
| 49 |
"""Test that importing certificate chain files via pk12util does not report |
| 50 |
any errors |
| 51 |
|
| 52 |
:id: c38b2cf9-93f0-4168-ab23-c74ac21ad59f |
| 53 |
|
| 54 |
:steps: |
| 55 |
1. Attempt to import a ca chain |
| 56 |
|
| 57 |
:expectedresults: |
| 58 |
1. Chain is successfully imported, no errors raised |
| 59 |
""" |
| 60 |
|
| 61 |
topology_st.standalone.stop() |
| 62 |
tls = NssSsl(dirsrv=topology_st.standalone) |
| 63 |
tls.reinit() |
| 64 |
|
| 65 |
tls.add_server_key_and_cert(KEY_FILE, CRT_CHAIN_FILE) |
| 66 |
tls.add_server_key_and_cert(KEY_CHAIN_FILE, CRT_CHAIN_FILE) |
| 67 |
tls.add_server_key_and_cert(KEY_FILE, KEY_CHAIN_FILE) |