Quickstart

Requirements

  • Python 3.10 or newer

  • Django 3.2 or newer

Installation

  1. Install from PyPI using pip:

    pip install django-simple-certmanager
    
  2. Add simple_certmanager to the INSTALLED_APPS setting.

  3. Run python src/manage.py migrate to create the necessary database tables

  4. Configure django-privates correctly - the TLS certificates and keys are stored outside of settings.MEDIA_ROOT for security reasons.

Usage

Django admin

In the Django admin, you can create Certificate instances to (re-)use (mutual) TLS configuration.

Whenever an instance is deleted (through the admin or code), the associated files are purged as well.

Programmatically

The Certificate model is the public API of the library.

class simple_certmanager.models.Certificate(id, label, type, public_certificate, private_key)
property expiry_date: datetime
get_type_display(*, field=<django.db.models.fields.CharField: type>)
is_valid_key_pair() None | bool
property issuer: str
label

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

private_key

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
public_certificate

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
property serial_number: str
property subject: str
type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.