Registry / http-networking / http-message-signatures

http-message-signatures

JSON →
library2.0.1pypypi✓ verified 22d ago

An implementation of the IETF HTTP Message Signatures draft standard, providing tools to sign and verify HTTP messages using various cryptographic algorithms. The current stable version is 2.0.1, with a moderate release cadence driven by specification updates and bug fixes.

pip install http-message-signatures
INSTALL
IMPORT
SIG · HTTP-MESSAGE-SIGNA
H
http-message-signatures
http-networkingpythonv2.0.1
Install
2.5s avg
Import
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 35.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.000s · 36MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HTTPSignatureKeySigner
from http_message_signatures import HTTPSignatureKeySigner
from http_message_signatures import HTTPSignatureKeySigner

This quickstart demonstrates how to sign and verify an HTTP request using `http-message-signatures`. It involves generating a temporary RSA key pair, creating a `requests.Request` object, signing it with `HTTPSignatureKeySigner`, and then verifying the resulting message with `HTTPSignatureKeyVerifier`. This example requires `requests` and `cryptography`.

import requests from http_message_signatures import HTTPSignatureKeySigner, HTTPSignatureKeyVerifier, algorithms from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization # 1. Generate a dummy RSA key pair (for demonstration) private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048) public_key = private_key.public_key() # Serialize keys for signer/verifier private_jwk = private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption() ).decode() public_jwk = public_key.public_bytes( encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo ).decode() key_id = "test-key" # 2. Prepare an HTTP request request = requests.Request( method="POST", url="https://example.com/data", headers={ "Host": "example.com", "Content-Type": "application/json", "Date": "Tue, 20 Apr 2021 02:07:55 GMT" }, data='{"message": "hello world"}' ) # 3. Sign the request signer = HTTPSignatureKeySigner( key_id=key_id, private_key=private_jwk, algorithm=algorithms.RSA_V1_5_SHA256 ) signed_request = signer.sign(request) print("--- Signed Request Headers ---") for k, v in signed_request.headers.items(): print(f"{k}: {v}") # 4. Verify the signed request (simulate receiving the request) verifier = HTTPSignatureKeyVerifier( key_id=key_id, public_key=public_jwk, algorithm=algorithms.RSA_V1_5_SHA256 ) # Create a dummy requests.Response object for verification # In a real scenario, this would be the actual received request dummy_received_request = requests.Request( method=signed_request.method, url=signed_request.url, headers=signed_request.headers, data=signed_request.data ) try: is_valid = verifier.verify(dummy_received_request) print(f"\nSignature is valid: {is_valid}") except Exception as e: print(f"\nSignature verification failed: {e}")
Debug
Known issues
breakingPython 3.8 and 3.9 are no longer supported. Version 2.0.0 dropped support for Python 3.9, and 2.0.1 explicitly removed metadata for Python 3.8/3.9. Projects must use Python 3.10 or newer.
fix
Upgrade your Python environment to 3.10 or newer. If you must use older Python versions, pin http-message-signatures to `<2.0.0`.
affects: >=2.0.0
breakingVersion 2.0.0 introduced support for multiple signatures on a single message. While this enhances functionality, it may involve changes to how signatures are added and retrieved from messages, potentially breaking existing code that assumed a single 'Signature' header.
fix
Review the documentation for `HTTPMessageSignatures` and adapt your signing/verification logic to correctly handle potentially multiple 'Signature' headers and their associated parameters.
affects: >=2.0.0
gotchaVersions prior to 1.0.1 had a bug in the `get_request_target` method, which could lead to an incorrect 'request-target' component in the signature (e.g., an extra '?'). This can cause signature mismatches between signers and verifiers on different versions.
fix
Upgrade to version 1.0.1 or newer to ensure correct 'request-target' calculation. If verifying old signatures with new verifiers (or vice versa), be aware of this potential discrepancy.
affects: <1.0.1
gotchaThe `max_clock_skew` parameter was added to `HTTPMessageVerifier` in version 0.5.0. Without this parameter, the verifier does not automatically account for clock differences between the signer and verifier, potentially making systems vulnerable to replay attacks if not handled externally.
fix
Ensure your `HTTPMessageVerifier` instances are configured with an appropriate `max_clock_skew` value to mitigate replay attacks. Upgrade to 0.5.0 or newer to use this feature directly.
affects: <0.5.0
gotchaMismanagement of cryptographic keys (e.g., using weak algorithms, exposing private keys, or reusing keys across different contexts) is a common security vulnerability. While the library provides the signing mechanisms, key management is left to the user.
fix
Always use strong, recommended algorithms (e.g., EDDSA_25519_SHA512, RSA-PSS with SHA-512). Store private keys securely, rotate them regularly, and avoid hardcoding them. Follow industry best practices for key lifecycle management.
affects: all
Upgrade
Version history
2.0.1latest on PyPI · released Jan 19, 2026
Audit
Dependencies
cryptographyrequiredProvides cryptographic primitives for signing and verification.
typing_extensionsrequiredUsed for advanced type hints, ensuring compatibility across Python versions.
http_sfvrequiredHandles Structured Field Values parsing and serialization as required by the spec.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
http-message-signatures — pip install http-message-signatures · libregistry