Skip to main content

CFSSL-backed certificate service for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_certs_cfssl


Swarmauri Cert Cfssl

CFSSL-backed certificate service for Swarmauri.

Features

  • CfsslCertService adapter that wraps the CFSSL REST API for signing, parsing, and verifying certificates.
  • Supports RSA, ECDSA (P-256/P-384), and Ed25519 key material with profile/label routing.
  • Optional certificate bundling during verification to ensure complete chains before deployment.
  • Detailed parsing utilities that expose SANs, key usage, EKU, Subject/Authority Key Identifiers, and more.

Prerequisites

  • Python 3.10 or newer.
  • A reachable CFSSL instance (standalone binary, Kubernetes deployment, or the Cloudflare Docker image).
  • Valid CFSSL signing profile(s) configured for your use case (e.g., www, client, code_signing).
  • If your CFSSL endpoint is protected, API credentials or access tokens for the headers you plan to use.

Installation

# pip
pip install swarmauri_certs_cfssl

# poetry
poetry add swarmauri_certs_cfssl

# uv (pyproject-based projects)
uv add swarmauri_certs_cfssl

Quickstart: Issue a Certificate

CfsslCertService consumes CSRs generated by other Swarmauri certificate services (for example, the Azure or ACME packages). The example below submits a CSR to CFSSL and saves the issued certificate:

import asyncio
from datetime import datetime, timedelta, timezone
from pathlib import Path

from swarmauri_certs_cfssl import CfsslCertService
from swarmauri_core.crypto.types import KeyRef


async def main() -> None:
    service = CfsslCertService(
        base_url="https://cfssl.internal",
        default_profile="www",
        timeout_s=15.0,
        auth_header=("X-Auth-Key", "super-secret-token"),
    )

    csr_bytes = Path("site.csr").read_bytes()

    # KeyRef tags allow you to override CFSSL profile/label per request
    ca_key = KeyRef(material=b"", tags={"profile": "www", "label": "primary"})

    certificate_pem = await service.sign_cert(
        csr=csr_bytes,
        ca_key=ca_key,
        extensions={
            "subject_alt_name": {"dns": ["site.example.com", "www.site.example.com"]}
        },
        not_after=int((datetime.now(timezone.utc) + timedelta(days=90)).timestamp()),
    )

    Path("site.pem").write_bytes(certificate_pem)
    await service.aclose()


if __name__ == "__main__":
    asyncio.run(main())

Verify and Parse Certificates

Leverage CFSSL's bundling API to confirm a certificate's trust chain, then inspect the returned metadata:

import asyncio
from pathlib import Path

from swarmauri_certs_cfssl import CfsslCertService


async def verify_and_parse() -> None:
    service = CfsslCertService(
        base_url="https://cfssl.internal",
        use_bundle_for_verify=True,
    )

    cert_bytes = Path("site.pem").read_bytes()

    verification = await service.verify_cert(
        cert=cert_bytes,
        trust_roots=[Path("root.pem").read_bytes()],
    )
    print("Valid:", verification["valid"], "Chain length:", verification["chain_len"])

    parsed = await service.parse_cert(cert_bytes)
    print("Subject CN:", parsed["subject"].get("CN"))
    print("SAN entries:", parsed.get("san", {}))

    await service.aclose()


if __name__ == "__main__":
    asyncio.run(verify_and_parse())

Notes

  • CfsslCertService focuses on signing and validation. Generate CSRs with other Swarmauri services (e.g., swarmauri_certs_acme, swarmauri_certs_azure) or your existing PKI tooling.
  • The client uses httpx.AsyncClient; reuse a service instance for multiple operations and call aclose() when finished to release connections.
  • Profile and label defaults can be set globally in the constructor or dynamically by attaching tags to the KeyRef passed into sign_cert.

Best Practices

  • Store CFSSL credentials outside source control (environment variables, secret stores, or Swarmauri state providers).
  • Enable TLS on the CFSSL API and pin the certificate when connecting over untrusted networks.
  • Use dedicated CFSSL profiles for each application tier and rotate them regularly.
  • Capture verification results (e.g., bundle size, expiry) in metrics to stay ahead of certificate renewals.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_certs_cfssl-0.2.2.dev6.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarmauri_certs_cfssl-0.2.2.dev6-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_certs_cfssl-0.2.2.dev6.tar.gz.

File metadata

  • Download URL: swarmauri_certs_cfssl-0.2.2.dev6.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_certs_cfssl-0.2.2.dev6.tar.gz
Algorithm Hash digest
SHA256 ff94a32c5e9a9595a3b09ffb919d9b9c95bea3159810617cd2a21da33616048e
MD5 f0a80a59997a3ec2ea3f88c21efc518d
BLAKE2b-256 7b5511404b20165aa46111b76c7714b61dc54829953e9ce82b5a23234b8553c9

See more details on using hashes here.

File details

Details for the file swarmauri_certs_cfssl-0.2.2.dev6-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_certs_cfssl-0.2.2.dev6-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_certs_cfssl-0.2.2.dev6-py3-none-any.whl
Algorithm Hash digest
SHA256 257ca666b8d2f5a2ec8d3fb5fef09766fb77ebd52ce15851673286097f9f12f8
MD5 b6ba6cf74b72ee6b34bec7cf19d6eb1f
BLAKE2b-256 6c0c61324ec1e03269b6f6e4915a245f8c70954deca2c4c75006273e660402a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page