Esempio n. 1
0
def test_create_certificates_ca_not_initialized(
        ca: certs.CertificateAuthority) -> None:
    with pytest.raises(RuntimeError,
                       match="Certificate authority is not initialized yet"):
        ca.create_site_certificate("xyz")
    with pytest.raises(RuntimeError,
                       match="Certificate authority is not initialized yet"):
        ca.create_agent_receiver_certificate()
Esempio n. 2
0
def test_create_site_certificate(ca: CertificateAuthority) -> None:
    site_id = "xyz"
    assert not ca.site_certificate_exists(site_id)

    ca.create_site_certificate(site_id, days_valid=100)
    assert ca.site_certificate_exists(site_id)
    assert _file_permissions_is_660(ca._site_certificate_path(site_id))

    cert, key = load_cert_and_private_key(ca._site_certificate_path(site_id))
    assert check_cn(
        cert,
        site_id,
    )
    check_certificate_against_private_key(
        cert,
        key,
    )
    check_certificate_against_public_key(
        cert,
        _rsa_public_key_from_cert_or_csr(ca.root_ca.cert),
    )
Esempio n. 3
0
def test_create_site_certificate(ca: certs.CertificateAuthority) -> None:
    ca.initialize()
    site_id = "xyz"
    assert not ca.site_certificate_exists(site_id)

    ca.create_site_certificate(site_id)
    assert ca.site_certificate_exists(site_id)
    assert _file_permissions_is_660(ca._site_certificate_path(site_id))

    cert, key = load_cert_and_private_key(ca._site_certificate_path(site_id))
    assert check_cn(
        cert,
        site_id,
    )
    check_certificate_against_private_key(
        cert,
        key,
    )
    check_certificate_against_public_key(
        cert,
        rsa_public_key_from_cert_or_csr(ca._get_root_certificate()[0]),
    )