Skip to main content

An implementation of the IETF HTTP Message Signatures draft standard

Project description

http-message-signatures is an implementation of the IETF HTTP Message Signatures draft standard in Python.

Installation

pip3 install http-message-signatures

Synopsis

from http_message_signatures import HTTPMessageSigner, HTTPMessageVerifier, HTTPSignatureKeyResolver, algorithms
import requests, base64, hashlib, http_sfv

class MyHTTPSignatureKeyResolver(HTTPSignatureKeyResolver):
    keys = {"my-key": b"top-secret-key"}

    def resolve_public_key(self, key_id: str):
        return self.keys[key_id]

    def resolve_private_key(self, key_id: str):
        return self.keys[key_id]

request = requests.Request('POST', 'https://example.com/foo?param=Value&Pet=dog', json={"hello": "world"})
request = request.prepare()
request.headers["Content-Digest"] = str(http_sfv.Dictionary({"sha-256": hashlib.sha256(request.body).digest()}))

signer = HTTPMessageSigner(signature_algorithm=algorithms.HMAC_SHA256, key_resolver=MyHTTPSignatureKeyResolver())
signer.sign(request, key_id="my-key", covered_component_ids=("@method", "@authority", "@target-uri", "content-digest"))

verifier = HTTPMessageVerifier(signature_algorithm=algorithms.HMAC_SHA256, key_resolver=MyHTTPSignatureKeyResolver())
verifier.verify(request)

Note that verifying the body content-digest is not yet implemented, so it remains the caller’s responsibility.

Authors

  • Andrey Kislyuk

License

Licensed under the terms of the Apache License, Version 2.0.

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

http-message-signatures-0.1.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

http_message_signatures-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file http-message-signatures-0.1.0.tar.gz.

File metadata

  • Download URL: http-message-signatures-0.1.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.10

File hashes

Hashes for http-message-signatures-0.1.0.tar.gz
Algorithm Hash digest
SHA256 21886a9d90a8f365724e5ed8a19af7a91c9ed2a67549b8e4262edf60d48e0db9
MD5 f680cf77b021daf3f0deb442c5d78410
BLAKE2b-256 fffb9d7fe6f0c2e93ff29306c7fe06e7f5a391e6788c91f31315ed308ad128f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: http_message_signatures-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.10

File hashes

Hashes for http_message_signatures-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33c56afc1f52906475eee0a378582d4c80335aab60136112abd0332e27e873ca
MD5 f4d6e286d1f8c5c584324da4da63feba
BLAKE2b-256 26f2d13ba63c0216f03bea9c52c160be9874d1f3cac3e182d2729951b882a065

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