All Projects → pyauth → requests-http-signature

pyauth / requests-http-signature

Licence: Apache-2.0 license
A Requests auth module for the IETF HTTP Message Signatures draft standard

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to requests-http-signature

Otplib
🔑 One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator
Stars: ✭ 916 (+1353.97%)
Mutual labels:  hmac
Practical Cryptography For Developers Book
Practical Cryptography for Developers: Hashes, MAC, Key Derivation, DHKE, Symmetric and Asymmetric Ciphers, Public Key Cryptosystems, RSA, Elliptic Curves, ECC, secp256k1, ECDH, ECIES, Digital Signatures, ECDSA, EdDSA
Stars: ✭ 2,400 (+3709.52%)
Mutual labels:  hmac
Privy
An easy, fast lib to correctly password-protect your data
Stars: ✭ 230 (+265.08%)
Mutual labels:  hmac
Cl Tls
An implementation of TLS and related specifications in Common Lisp
Stars: ✭ 32 (-49.21%)
Mutual labels:  hmac
Docker Cloud Platform
使用Docker构建云平台,Docker云平台系列共三讲,Docker基础、Docker进阶、基于Docker的云平台方案。OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 86 (+36.51%)
Mutual labels:  hmac
Jssha
A JavaScript/TypeScript implementation of the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC.
Stars: ✭ 2,089 (+3215.87%)
Mutual labels:  hmac
Jshashes
Fast and dependency-free cryptographic hashing library for node.js and browsers (supports MD5, SHA1, SHA256, SHA512, RIPEMD, HMAC)
Stars: ✭ 622 (+887.3%)
Mutual labels:  hmac
pbkdf2-hmac-sha256
sha256, hmac with sha256 and pbkdf2 with hmac-sha256 in one header file
Stars: ✭ 19 (-69.84%)
Mutual labels:  hmac
Hash Library
Portable C++ hashing library
Stars: ✭ 109 (+73.02%)
Mutual labels:  hmac
Orion
Usable, easy and safe pure-Rust crypto
Stars: ✭ 227 (+260.32%)
Mutual labels:  hmac
Iocane
An odorless, tasteless NodeJS crypto library that dissolves instantly in liquid
Stars: ✭ 35 (-44.44%)
Mutual labels:  hmac
Go Alone
A simple to use, high-performance, Go (golang) MAC signer.
Stars: ✭ 82 (+30.16%)
Mutual labels:  hmac
Itsdangerous
Safely pass trusted data to untrusted environments and back.
Stars: ✭ 2,358 (+3642.86%)
Mutual labels:  hmac
Php Storageless Sessions
Sessions handler which stores session data in HMAC-signed and encrypted cookies
Stars: ✭ 29 (-53.97%)
Mutual labels:  hmac
Jwt
JSON Web Token library
Stars: ✭ 242 (+284.13%)
Mutual labels:  hmac
Fwknop
Single Packet Authorization > Port Knocking
Stars: ✭ 664 (+953.97%)
Mutual labels:  hmac
Crypto Async
Fast, reliable cipher, hash and hmac methods executed in Node's threadpool for multi-core throughput.
Stars: ✭ 161 (+155.56%)
Mutual labels:  hmac
requests-arcgis-auth
Authentication handler for using Esri ArcGIS for Server and Portal (ArcGIS Online) Token Authentication with Python Requests
Stars: ✭ 21 (-66.67%)
Mutual labels:  python-requests
java-http-signature
Library for performing RSA signed HTTP requests in Java
Stars: ✭ 15 (-76.19%)
Mutual labels:  http-signature
Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (+244.44%)
Mutual labels:  hmac

requests-http-signature: A Requests auth module for HTTP Signature

requests-http-signature is a Requests authentication plugin (requests.auth.AuthBase subclass) implementing the IETF HTTP Message Signatures draft standard.

Installation

$ pip install requests-http-signature

Usage

import requests
from requests_http_signature import HTTPSignatureAuth, algorithms

preshared_key_id = 'squirrel'
preshared_secret = b'monorail_cat'
url = 'https://example.com/'

auth = HTTPSignatureAuth(key=preshared_secret,
                         key_id=preshared_key_id,
                         signature_algorithm=algorithms.HMAC_SHA256)
requests.get(url, auth=auth)

By default, only the Date header and the @method, @authority, and @target-uri derived component identifiers are signed for body-less requests such as GET. The Date header is set if it is absent. In addition, the Authorization header is signed if it is present, and for requests with bodies (such as POST), the Content-Digest header is set to the SHA256 of the request body using the format described in the IETF Digest Fields draft and signed. To add other headers to the signature, pass an array of header names in the covered_component_ids keyword argument. See the API documentation for the full list of options and details.

Verifying responses

The class method HTTPSignatureAuth.verify() can be used to verify responses received back from the server:

class MyKeyResolver:
    def resolve_public_key(self, key_id):
        assert key_id == 'squirrel'
        return 'monorail_cat'

response = requests.get(url, auth=auth)
verify_result = HTTPSignatureAuth.verify(response,
                                         signature_algorithm=algorithms.HMAC_SHA256,
                                         key_resolver=MyKeyResolver())

More generally, you can reconstruct an arbitrary request using the Requests API and pass it to verify():

request = requests.Request(...)  # Reconstruct the incoming request using the Requests API
prepared_request = request.prepare()  # Generate a PreparedRequest
HTTPSignatureAuth.verify(prepared_request, ...)

To verify incoming requests and sign responses in the context of an HTTP server, see the flask-http-signature and http-message-signatures packages.

See what is signed

It is important to understand and follow the best practice rule of "See what is signed" when verifying HTTP message signatures. The gist of this rule is: if your application neglects to verify that the information it trusts is what was actually signed, the attacker can supply a valid signature but point you to malicious data that wasn't signed by that signature. Failure to follow this rule can lead to vulnerability against signature wrapping and substitution attacks.

In requests-http-signature, you can ensure that the information signed is what you expect to be signed by only trusting the data returned by the verify() method:

verify_result = HTTPSignatureAuth.verify(message, ...)

See the API documentation for full details.

Asymmetric key algorithms

To sign or verify messages with an asymmetric key algorithm, set the signature_algorithm keyword argument to algorithms.ED25519, algorithms.ECDSA_P256_SHA256, algorithms.RSA_V1_5_SHA256, or algorithms.RSA_PSS_SHA512.

For asymmetric key algorithms, you can supply the private key as the key parameter to the HTTPSignatureAuth() constructor as bytes in the PEM format, or configure the key resolver as follows:

with open('key.pem', 'rb') as fh:
    auth = HTTPSignatureAuth(signature_algorithm=algorithms.RSA_V1_5_SHA256,
                             key=fh.read(),
                             key_id=preshared_key_id)
requests.get(url, auth=auth)

class MyKeyResolver:
    def resolve_public_key(self, key_id: str):
        return public_key_pem_bytes[key_id]

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

auth = HTTPSignatureAuth(signature_algorithm=algorithms.RSA_V1_5_SHA256,
                         key=fh.read(),
                         key_resolver=MyKeyResolver())
requests.get(url, auth=auth)

Digest algorithms

To generate a Content-Digest header using SHA-512 instead of the default SHA-256, subclass HTTPSignatureAuth as follows:

class MySigner(HTTPSignatureAuth):
    signing_content_digest_algorithm = "sha-512"

Links

Bugs

Please report bugs, issues, feature requests, etc. on GitHub.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].