Skip to main content

A library to simplify working with the IB1 Trust Framework directory

Project description

IB1 Directory

A library to simplify working with the IB1 Trust Framework directory

Development

Setup

poetry install

Run tests

poetry run pytest

Package and publish

poetry build
poetry publish

Usage

Encoding and decoding

from ib1.directory.extensions import encode_roles, decode_roles
...

cert_builder = (
    x509.CertificateBuilder()
    .subject_name(subject)
    .issuer_name(issuer)
    .public_key(private_key.public_key())
    .serial_number(x509.random_serial_number())
    .not_valid_before(datetime.utcnow())
    .not_valid_after(datetime.utcnow() + timedelta(days=365))
)

cert_builder = encode_roles(cert_builder, roles)

cert = cert_builder.sign(private_key, hashes.SHA256(), default_backend())

roles = decode_roles(cert)

Require a role

from ib1 import directory
...
    cert = directory.parse_cert(quoted_certificate_from_header)
    try:
        directory.require_role(
            "https://registry.core.ib1.org/scheme/perseus/role/carbon-accounting",
            cert,
        )
    except directory.CertificateRoleError as e:
        raise HTTPException(
            status_code=401,
            detail=str(e),
        )
...

Commands for generating certificates

The included cli can generate CA and issuer key certificate pairs suitable for signing client and server CSR requests in the IB1 Trust Framework.

Generate a CA key and certificate

Usage: ib1-directory create-ca [OPTIONS]

  Generate a server signing CA key and certificate and an issuer key and
  certificate pair signed by the CA then saves all files to disk

Options:
  -u, --usage [client|server]  Choose server or client CA
  -c, --country TEXT           Country to use for certificate generation
  -s, --state TEXT             State to use for certificate generation
  -f, --framework TEXT         Framework this certificate is for
  --help                       Show this message and exit.

eg. to create a server CA key and certificate for the Core Trust Framework:

poetry run ib1-directory create-ca -u server -f Core

Create test client and server certficates

Client:

Usage: ib1-directory create-client-certificates [OPTIONS]

  Create a private key and use it generate a CSR, then sign the CSR with a CA
  key and certificate.

  Saves the private key, CSR, certificate and bundle to disk.

Options:
  --issuer-key-file FILENAME   Issuer key file
  --issuer-cert-file FILENAME  Issuer certificate file
  --member_uri TEXT            Member uri
  --organization_name TEXT     Organization name
  --country TEXT               Country
  --state TEXT                 State
  -r, --role TEXT              Client roles
  --application_uri TEXT       Application uri
  --help                       Show this message and exit.

Server:

Usage: ib1-directory create-server-certificates [OPTIONS]

  Create a private key and use it generate a CSR, then sign the CSR with a CA
  key and certificate.

  Saves the private key, CSR, certificate and bundle to disk.

Options:
  --issuer-key-file FILENAME   Issuer key file
  --issuer-cert-file FILENAME  Issuer certificate file
  --domain TEXT                Domain name
  --trust_framework TEXT       Trust framework
  --country TEXT               Country
  --state TEXT                 State
  --help                       Show this message and exit.

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

ib1_directory-0.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

ib1_directory-0.2-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file ib1_directory-0.2.tar.gz.

File metadata

  • Download URL: ib1_directory-0.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/24.0.0

File hashes

Hashes for ib1_directory-0.2.tar.gz
Algorithm Hash digest
SHA256 169057ef457424c29df9035c2b213bb59ba4fa6c3400e33766b392984e2eb869
MD5 9054ccaec39ed1d5209c1c6f886ccb18
BLAKE2b-256 cff9b2f50914a052eb76222de4b24a7f186a7d6b2a1dcf6cf59e3056e1689619

See more details on using hashes here.

File details

Details for the file ib1_directory-0.2-py3-none-any.whl.

File metadata

  • Download URL: ib1_directory-0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/24.0.0

File hashes

Hashes for ib1_directory-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2cfbdc61ca4d50e37ef8e855ce5b7f8f7aa2bbe8fa2b30f9385dae11b4b2a2cf
MD5 3e68e78dfb86f00af61a57906c297ffb
BLAKE2b-256 253cc4c0405310fbb69858fe202da21a6f69a75ff07113270a8c404393f0fb72

See more details on using hashes here.

Supported by

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