certipie


Namecertipie JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/lewoudar/certipie
SummaryA tool to create certificate signing request and self-signed certificates
upload_time2023-11-27 09:56:25
maintainer
docs_urlNone
authorle_woudar
requires_python>=3.9,<4.0
licenseApache-2.0
keywords certificate cli cryptography fastapi csr
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # certipie

[![Pypi version](https://img.shields.io/pypi/v/certipie.svg)](https://pypi.org/project/certipie/)
[![](https://github.com/lewoudar/certipie/workflows/CI/badge.svg)](https://github.com/lewoudar/certipie/actions/)
[![Coverage Status](https://codecov.io/gh/lewoudar/certipie/branch/main/graphs/badge.svg?branch=main)](https://codecov.io/gh/lewoudar/certipie)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/lewoudar/certipie)
[![License Apache 2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://github.com/lewoudar/certipie)

A utility library to create certificate signing request and self-signed certificates.

## Why?

There are three main reasons why I decide to do this:

- I am a *nerd* who loves to code. Yeah, I need to be honest here, it was an opportunity for me to play with the
  excellent [cryptography](https://cryptography.io/en/latest/) library.
- I currently work in a company where we deal a lot with certificates, and I know it can be handy to have a simple tool
  to generate certificate signing request, so I decide to create one.
- When creating or working with network servers, we often need to test certificate handling, so it is convenient to have
  a tool to quickly generate a self-signed certificate.

Notes:

- If you want a tool to handle a whole certificate life cycle for your project, consider using a library like
  [certbot](https://eff-certbot.readthedocs.io/en/stable/).
- If you just want a tool to create certificates on the fly during unit tests, consider using
  [trustme](https://trustme.readthedocs.io/en/latest/).

## Installation

The minimal python version supported is **3.9**. You can install the library using **pip** with the following command:

```shell
$ pip install certipie
```

You can also use an alternative package manager like [poetry](https://python-poetry.org/docs/):

```shell
$ poetry add certipie
```

## Usage

There are three ways to use certipie.

### The command line interface

This is probably the main way to use it. The project includes a convenient `cert` command line interface.

```shell
$ cert
Usage: cert [OPTIONS] COMMAND [ARGS]...

  A cli to generate certificate signing request and self-signed certificate
  that can be used for testing purpose.

Options:
  --version   Show the version and exit.
  -h, --help  Show this message and exit.

Commands:
  auto-cert           Creates a self-signed certificate useful for tests.
  csr                 Creates a certificate signing request file given...
  install-completion  Install completion script for bash, zsh and fish...
  rsa                 Creates a pair of private/public keys using the RSA...
  server              Serves a swagger UI where you can perform the same...
```

#### install-completion

The first command you will want to use is `install-completion` like the name said will allow options and commands
completion. The shells currently supported are **bash**, **fish** and **zsh**.

```shell
$ cert install-completion
```

#### rsa

To create a certificate signing request or a self-signed certificate, you need a private key. The `cert` command allows
you to create an **RSA** private key which is one of the most common (if not the most common) private keys used for this
type of operation.

```shell
$ cert rsa
Enter the passphrase [passphrase]:
Repeat for confirmation:
The pair of keys was successfully in ...
```

Note: On all commands, you can use `-h` option to get their usage documentation.

#### csr

This commands helps you create a certificate signing request.

```shell
$ cert csr -f csr.pem
Organization: orga
State: Ile-de-France
Country: FR
City: Paris
Name: site.com
The certificate signing request has been successfully created in /home/kevin/...
```

Notes:

- In the previous example since no private key was passed as input, the `csr` command creates an **RSA** one with no
  password in the same directory where the certificate signing request is created. If you want to provide one, use the
  `-k` option and gives the path to the private key, e.g: `cert csr -k /path/to/private/key`. It is not mandatory that
  the private key is of type RSA. In fact other algorithms are supported like DSA or elliptic curve. For a full list of
  supported algorithms, look `PrivateKey` type in module `certipie.types`.
- If you pass a key file, you will be prompted to give the password. If you don't provide a password to your private
  key, just type `Enter` to continue.
- The `--country` option must be a two-letters value. To know the two-letters code of a country, you can check this
  [website](https://www.iban.com/country-codes).
- The `--name` option value is used as the domain name to submit for the certificate signing request. In the previous
  example, it will be `site.com`. Wildcards like `*.site.com` are supported.
- If you want to include many domain names in the certificate signing request, not only the `--name` value, you can use
  the `--alt-names` option like the following: `cert csr --alt-names=site.com,foo.site.com`. The values **must**
  be separated by commas.

#### auto-cert

This command helps you create a self-signed certificate useful when you want to test a network server like an HTTP
server.

```shell
$ cert auto-cert -f cert.pem --validity=360
Organization: orga
State: Ile-de-France
Country: FR
City: Paris
The self-signed certificate has been successfully created in /home/kevin/...
```

Notes:

- The notes from the `csr` command also applies here.
- Since we often work on our own computer in this case, `localhost` is the default `--name` option.
- `--alt-names` also accepts ip adresses and networks. You can have a value like the following:
  `cert auto-cert --alt-names=localhost,192.168.1.0/24`.
- `--validity` option represents the number of days the certificate will be valid. If not provided, it is **365**.

#### server

This commands runs a server which serves a Swagger UI where you can perform the previous commands explained above. This
is handy if you want non-technical staff to be able to use the command line features.

```shell
$ cert server
```

If you open a browser on http://localhost:8000 you will see the swagger documentation.
![](images/cert_api.png)

Under the hood the server used is [hypercorn](https://pgjones.gitlab.io/hypercorn). You can configure it passing a
*toml* configuration file. To know all the settings available, refer to the
[official documentation](https://pgjones.gitlab.io/hypercorn/how_to_guides/configuring.html).

```shell
$ cert server -c /path/to/toml/file
```

### The REST API

Following the previous section about serving a swagger UI, if you think that it does not well suits your organization,
you can adjust it. The api is created using the [FastAPI](https://fastapi.tiangolo.com/) web framework. For example if
you want to integrate it in your own fastapi application, you can use the router provided by certipie.

This way you can adjust the url used for the certificate routes, for example `/certificate` instead of `/certs`, change
documentation url, add some authentication to routes, etc...
The [router](https://fastapi.tiangolo.com/tutorial/bigger-applications/) concept is a powerful feature from FastAPI.

```python
from fastapi import FastAPI
from certipie import router

app = FastAPI(
    title='certificate api',
    description='Your description',
    redoc_url=None,
    docs_url='/documentation'
)
app.include_router(router, prefix='/certificate', tags=['certificate'])
```

Transform the api to suit your needs :)

### The certipie API

The last way to leverage certipie is to interact programmatically with its api. The following functions are exposed:

- `create_private_key`: Creates an RSA private key.
- `get_public_key_from_private_key`: Extracts a public key from a private key.
- `create_csr`: Creates a certificate signing request.
- `create_auto_cert`: Creates a self-signed certificate.

Normally the api usage should be straightforward. The behaviour is the same as the command line. You can also look at
tests if you are blocked.

Here is a snippet on how to create a certificate signing request using `create_csr`:

```python
from certipie import create_csr

create_csr(
    'csr.pem',
    'FR',
    'Ile-de-France',
    'Paris',
    'organization',
    'site.com',
    alternative_names=['site.com', 'foo.site.com'],
    private_key='key.pem',
    passphrase='passphrase'
)
```

There are two others objets exported:

- `app`: The fastapi application used when running `cert server` command. It is exposed so that you can
  [mount](https://fastapi.tiangolo.com/advanced/sub-applications/) it in another application if you want.
- `PrivateKey`: The type annotation for all the private keys supported by the `cryptography` library.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lewoudar/certipie",
    "name": "certipie",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "certificate,cli,cryptography,fastapi,csr",
    "author": "le_woudar",
    "author_email": "lewoudar@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9b/ec/ab359d7363bb01ff76d1781cf57dfc05553ed0421669d758af18ba3dbd08/certipie-0.3.0.tar.gz",
    "platform": null,
    "description": "# certipie\n\n[![Pypi version](https://img.shields.io/pypi/v/certipie.svg)](https://pypi.org/project/certipie/)\n[![](https://github.com/lewoudar/certipie/workflows/CI/badge.svg)](https://github.com/lewoudar/certipie/actions/)\n[![Coverage Status](https://codecov.io/gh/lewoudar/certipie/branch/main/graphs/badge.svg?branch=main)](https://codecov.io/gh/lewoudar/certipie)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/lewoudar/certipie)\n[![License Apache 2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)\n[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://github.com/lewoudar/certipie)\n\nA utility library to create certificate signing request and self-signed certificates.\n\n## Why?\n\nThere are three main reasons why I decide to do this:\n\n- I am a *nerd* who loves to code. Yeah, I need to be honest here, it was an opportunity for me to play with the\n  excellent [cryptography](https://cryptography.io/en/latest/) library.\n- I currently work in a company where we deal a lot with certificates, and I know it can be handy to have a simple tool\n  to generate certificate signing request, so I decide to create one.\n- When creating or working with network servers, we often need to test certificate handling, so it is convenient to have\n  a tool to quickly generate a self-signed certificate.\n\nNotes:\n\n- If you want a tool to handle a whole certificate life cycle for your project, consider using a library like\n  [certbot](https://eff-certbot.readthedocs.io/en/stable/).\n- If you just want a tool to create certificates on the fly during unit tests, consider using\n  [trustme](https://trustme.readthedocs.io/en/latest/).\n\n## Installation\n\nThe minimal python version supported is **3.9**. You can install the library using **pip** with the following command:\n\n```shell\n$ pip install certipie\n```\n\nYou can also use an alternative package manager like [poetry](https://python-poetry.org/docs/):\n\n```shell\n$ poetry add certipie\n```\n\n## Usage\n\nThere are three ways to use certipie.\n\n### The command line interface\n\nThis is probably the main way to use it. The project includes a convenient `cert` command line interface.\n\n```shell\n$ cert\nUsage: cert [OPTIONS] COMMAND [ARGS]...\n\n  A cli to generate certificate signing request and self-signed certificate\n  that can be used for testing purpose.\n\nOptions:\n  --version   Show the version and exit.\n  -h, --help  Show this message and exit.\n\nCommands:\n  auto-cert           Creates a self-signed certificate useful for tests.\n  csr                 Creates a certificate signing request file given...\n  install-completion  Install completion script for bash, zsh and fish...\n  rsa                 Creates a pair of private/public keys using the RSA...\n  server              Serves a swagger UI where you can perform the same...\n```\n\n#### install-completion\n\nThe first command you will want to use is `install-completion` like the name said will allow options and commands\ncompletion. The shells currently supported are **bash**, **fish** and **zsh**.\n\n```shell\n$ cert install-completion\n```\n\n#### rsa\n\nTo create a certificate signing request or a self-signed certificate, you need a private key. The `cert` command allows\nyou to create an **RSA** private key which is one of the most common (if not the most common) private keys used for this\ntype of operation.\n\n```shell\n$ cert rsa\nEnter the passphrase [passphrase]:\nRepeat for confirmation:\nThe pair of keys was successfully in ...\n```\n\nNote: On all commands, you can use `-h` option to get their usage documentation.\n\n#### csr\n\nThis commands helps you create a certificate signing request.\n\n```shell\n$ cert csr -f csr.pem\nOrganization: orga\nState: Ile-de-France\nCountry: FR\nCity: Paris\nName: site.com\nThe certificate signing request has been successfully created in /home/kevin/...\n```\n\nNotes:\n\n- In the previous example since no private key was passed as input, the `csr` command creates an **RSA** one with no\n  password in the same directory where the certificate signing request is created. If you want to provide one, use the\n  `-k` option and gives the path to the private key, e.g: `cert csr -k /path/to/private/key`. It is not mandatory that\n  the private key is of type RSA. In fact other algorithms are supported like DSA or elliptic curve. For a full list of\n  supported algorithms, look `PrivateKey` type in module `certipie.types`.\n- If you pass a key file, you will be prompted to give the password. If you don't provide a password to your private\n  key, just type `Enter` to continue.\n- The `--country` option must be a two-letters value. To know the two-letters code of a country, you can check this\n  [website](https://www.iban.com/country-codes).\n- The `--name` option value is used as the domain name to submit for the certificate signing request. In the previous\n  example, it will be `site.com`. Wildcards like `*.site.com` are supported.\n- If you want to include many domain names in the certificate signing request, not only the `--name` value, you can use\n  the `--alt-names` option like the following: `cert csr --alt-names=site.com,foo.site.com`. The values **must**\n  be separated by commas.\n\n#### auto-cert\n\nThis command helps you create a self-signed certificate useful when you want to test a network server like an HTTP\nserver.\n\n```shell\n$ cert auto-cert -f cert.pem --validity=360\nOrganization: orga\nState: Ile-de-France\nCountry: FR\nCity: Paris\nThe self-signed certificate has been successfully created in /home/kevin/...\n```\n\nNotes:\n\n- The notes from the `csr` command also applies here.\n- Since we often work on our own computer in this case, `localhost` is the default `--name` option.\n- `--alt-names` also accepts ip adresses and networks. You can have a value like the following:\n  `cert auto-cert --alt-names=localhost,192.168.1.0/24`.\n- `--validity` option represents the number of days the certificate will be valid. If not provided, it is **365**.\n\n#### server\n\nThis commands runs a server which serves a Swagger UI where you can perform the previous commands explained above. This\nis handy if you want non-technical staff to be able to use the command line features.\n\n```shell\n$ cert server\n```\n\nIf you open a browser on http://localhost:8000 you will see the swagger documentation.\n![](images/cert_api.png)\n\nUnder the hood the server used is [hypercorn](https://pgjones.gitlab.io/hypercorn). You can configure it passing a\n*toml* configuration file. To know all the settings available, refer to the\n[official documentation](https://pgjones.gitlab.io/hypercorn/how_to_guides/configuring.html).\n\n```shell\n$ cert server -c /path/to/toml/file\n```\n\n### The REST API\n\nFollowing the previous section about serving a swagger UI, if you think that it does not well suits your organization,\nyou can adjust it. The api is created using the [FastAPI](https://fastapi.tiangolo.com/) web framework. For example if\nyou want to integrate it in your own fastapi application, you can use the router provided by certipie.\n\nThis way you can adjust the url used for the certificate routes, for example `/certificate` instead of `/certs`, change\ndocumentation url, add some authentication to routes, etc...\nThe [router](https://fastapi.tiangolo.com/tutorial/bigger-applications/) concept is a powerful feature from FastAPI.\n\n```python\nfrom fastapi import FastAPI\nfrom certipie import router\n\napp = FastAPI(\n    title='certificate api',\n    description='Your description',\n    redoc_url=None,\n    docs_url='/documentation'\n)\napp.include_router(router, prefix='/certificate', tags=['certificate'])\n```\n\nTransform the api to suit your needs :)\n\n### The certipie API\n\nThe last way to leverage certipie is to interact programmatically with its api. The following functions are exposed:\n\n- `create_private_key`: Creates an RSA private key.\n- `get_public_key_from_private_key`: Extracts a public key from a private key.\n- `create_csr`: Creates a certificate signing request.\n- `create_auto_cert`: Creates a self-signed certificate.\n\nNormally the api usage should be straightforward. The behaviour is the same as the command line. You can also look at\ntests if you are blocked.\n\nHere is a snippet on how to create a certificate signing request using `create_csr`:\n\n```python\nfrom certipie import create_csr\n\ncreate_csr(\n    'csr.pem',\n    'FR',\n    'Ile-de-France',\n    'Paris',\n    'organization',\n    'site.com',\n    alternative_names=['site.com', 'foo.site.com'],\n    private_key='key.pem',\n    passphrase='passphrase'\n)\n```\n\nThere are two others objets exported:\n\n- `app`: The fastapi application used when running `cert server` command. It is exposed so that you can\n  [mount](https://fastapi.tiangolo.com/advanced/sub-applications/) it in another application if you want.\n- `PrivateKey`: The type annotation for all the private keys supported by the `cryptography` library.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A tool to create certificate signing request and self-signed certificates",
    "version": "0.3.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/lewoudar/certipie/issues",
        "Documentation": "https://github.com/lewoudar/certipie#readme",
        "Homepage": "https://github.com/lewoudar/certipie",
        "Repository": "https://github.com/lewoudar/certipie"
    },
    "split_keywords": [
        "certificate",
        "cli",
        "cryptography",
        "fastapi",
        "csr"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "948de9fbfe2b4b409cb591b0b588e279bf11dd8d7eb2895371a91b36090dd96c",
                "md5": "6cc79c440c92c4bc06cf133e7b2d830d",
                "sha256": "56f6cb2b948f978a7188fda913866060861d8cca38cbed08c98d19b93423d694"
            },
            "downloads": -1,
            "filename": "certipie-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6cc79c440c92c4bc06cf133e7b2d830d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 24743,
            "upload_time": "2023-11-27T09:56:23",
            "upload_time_iso_8601": "2023-11-27T09:56:23.025019Z",
            "url": "https://files.pythonhosted.org/packages/94/8d/e9fbfe2b4b409cb591b0b588e279bf11dd8d7eb2895371a91b36090dd96c/certipie-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9becab359d7363bb01ff76d1781cf57dfc05553ed0421669d758af18ba3dbd08",
                "md5": "bd6da9c63efc482388f44d714d6dc85d",
                "sha256": "6ef1cf7a4dfd42d67437d20b92a09fd0a74796956bf2f886af2c94c6542208aa"
            },
            "downloads": -1,
            "filename": "certipie-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bd6da9c63efc482388f44d714d6dc85d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 21577,
            "upload_time": "2023-11-27T09:56:25",
            "upload_time_iso_8601": "2023-11-27T09:56:25.467478Z",
            "url": "https://files.pythonhosted.org/packages/9b/ec/ab359d7363bb01ff76d1781cf57dfc05553ed0421669d758af18ba3dbd08/certipie-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-27 09:56:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lewoudar",
    "github_project": "certipie",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "certipie"
}
        
Elapsed time: 0.33192s