Skip to main content

No project description provided

Project description

aiohttp_signer

This is an aiohttp client middleware, see also Client Middleware Cookbook, to add the digest and http message signatures.

Warning: Not all parts of RFC 9421 HTTP Message Signatures are implemented yet.

History

This package was created as part of rewriting bovine. My goal with it being to separate the parts that are HTTP from the parts that are Fediverse and the parts that are cryptography.

Usage

The following illustrates the simplest usage of this package

import aiohttp
from aiohttp_signer import DigestMiddleware, Rfc9421Signer

async def make_post_request(
    target_url: str,
    data: dict,
    key_id: str,
    signer: Callable[[bytes], bytes]
):
    async with aiohttp.ClientSession() as session:
        await session.post(
            target_url,
            json=data,
            middlewares=[
                DigestMiddleware(),
                Rfc9421Signer(key_id=key_id, signer=signer),
            ],
        )

This will cause the message to contain the content-digest, signature-input, and signature headers. Where the used signature parameters are @method, @target-uri, and content-digest.

A sample implementation of signer would be

from cryptography.hazmat.primitives.serialization import load_pem_private_key
from cryptography.hazmat.primitives.asymmetric import ed25519

private_key_pem = b"""
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIJ+DYvh6SEqVTm50DFtMDoQikTmiCqirVv9mWG9qfSnF
-----END PRIVATE KEY-----
"""

def signer(x: bytes):
    private_key = load_pem_private_key(private_key_pem, password=None)
    assert isinstance(private_key, ed25519.Ed25519PrivateKey)
    return private_key.sign(x)

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

aiohttp_signer-0.1.0.tar.gz (117.9 kB view details)

Uploaded Source

Built Distribution

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

aiohttp_signer-0.1.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_signer-0.1.0.tar.gz.

File metadata

  • Download URL: aiohttp_signer-0.1.0.tar.gz
  • Upload date:
  • Size: 117.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.3","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiohttp_signer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f9668d54440bbcae26425185876e45c936d0ea1aba178d09d0e2ff59e43af48
MD5 a2ede79933cf77b99896910463a3a3ff
BLAKE2b-256 e6a256d000eff4677eab617996a00765ac0bc24813691fea4d52af346b04407e

See more details on using hashes here.

File details

Details for the file aiohttp_signer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_signer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.3","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiohttp_signer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca730eda24add86e202a761f6b1094c12a1bcddc8122b42820135ccf96429fc
MD5 73db08565a645ecda20ab2964af2fe92
BLAKE2b-256 b0a3ac7aa1fb9e311b24030890c33df22ad776a38b85038d86d470df7c220414

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