Skip to main content

An implementation of the IETF HTTP Message Signatures draft standard, forked from `http-message-signatures`, fixed ed25519 key loader.

Project description

http-message-signatures is an implementation of the IETF RFC 9421 HTTP Message Signatures 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 outside the scope of this package’s functionality, so it remains the caller’s responsibility. The requests-http-signature library builds upon this package to provide integrated signing and validation of the request body.

Given an HTTP request can potentially have multiple signatures the verify() method returns a list of VerifyResult s. However, the implementation currently supports just one signature, so the returned list currently contains just one element. If more signatures are found in the request then InvalidSignature is raised.

Additionally, the verify() method raises HTTPMessageSignaturesException or an exception derived from this class in case an error occurs (unable to load PEM key, unsupported algorithm specified in signature input, signature doesn’t match digest etc.)

Authors

  • Andrey Kislyuk <https://kislyuk.com>

License

Copyright 2017-2024, Andrey Kislyuk and http-message-signatures contributors. Licensed under the terms of the Apache License, Version 2.0. Distribution of attribution information, LICENSE and NOTICE files with source copies of this package and derivative works is REQUIRED as specified by the Apache License.

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_msg_sig-0.2.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

http_msg_sig-0.2.0-py2.py3-none-any.whl (13.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file http_msg_sig-0.2.0.tar.gz.

File metadata

  • Download URL: http_msg_sig-0.2.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for http_msg_sig-0.2.0.tar.gz
Algorithm Hash digest
SHA256 36e2c86baa049a675b59d405c81b7d2a35cdffe479bc3bb945331eb40e15ad6d
MD5 f44bf92f09dcf168c8228827e1d3975a
BLAKE2b-256 e540e20f451ca158b0784b063d3f077e8d0ad0a1124bb8596444a69ca5f5aab1

See more details on using hashes here.

File details

Details for the file http_msg_sig-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: http_msg_sig-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for http_msg_sig-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8bb9b5adcf9830dd694b6677e51b9a6678fb41cb23cf765e7d6980dc0ca79ddc
MD5 72857dee2fae7a88cde71aeb252abb0f
BLAKE2b-256 cd208eb2eb80d55602fb6056a07beaa17c89efe3dc7ee54cdfbdc41ad253fd8e

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