Skip to main content
httpsig_cffi
============

.. image:: https://travis-ci.org/hawkowl/httpsig_cffi.svg?branch=master
:target: https://travis-ci.org/hawkowl/httpsig_cffi

Sign HTTP requests with secure signatures according to the IETF HTTP Signatures specification (`Draft 3`_).
This is `a fork`_ of the fork_ of the original module_ that was made to fully support both RSA and HMAC schemes as well as unit test both schemes to prove they work.
This particular fork moves from PyCrypto to Cryptography, which provides PyPy support.

See the original project_, original Python module_, original spec_, and `current IETF draft`_ for more details on the signing scheme.

.. _project: https://github.com/joyent/node-http-signature
.. _module: https://github.com/zzsnzmn/py-http-signature
.. _fork: https://github.com/ahknight/httpsig
.. _spec: https://github.com/joyent/node-http-signature/blob/master/http_signing.md
.. _`current IETF draft`: https://datatracker.ietf.org/doc/draft-cavage-http-signatures/
.. _`Draft 3`: http://tools.ietf.org/html/draft-cavage-http-signatures-03
.. _`a fork`: https://github.com/hawkowl/httpsig_cffi


Requirements
------------

* Python 2.7, 3.2, 3.3, 3.4, PyPy, PyPy3
* Cryptography_

Optional:

* requests_

.. _Cryptography: https://pypi.python.org/pypi/cryptography
.. _requests: https://pypi.python.org/pypi/requests


Usage
-----

Real documentation is forthcoming, but for now this should get you started.

For simple raw signing:

.. code:: python

import httpsig_cffi as httpsig

secret = open('rsa_private.pem', 'rb').read()

sig_maker = httpsig.Signer(secret=secret, algorithm='rsa-sha256')
sig_maker.sign('hello world!')

For general use with web frameworks:

.. code:: python

import httpsig_cffi as httpsig

key_id = "Some Key ID"
secret = b'some big secret'

hs = httpsig.HeaderSigner(key_id, secret, algorithm="hmac-sha256", headers=['(request-target)', 'host', 'date'])
signed_headers_dict = hs.sign({"Date": "Tue, 01 Jan 2014 01:01:01 GMT", "Host": "example.com"}, method="GET", path="/api/1/object/1")

For use with requests:

.. code:: python

import json
import requests
from httpsig_cffi.requests_auth import HTTPSignatureAuth

secret = open('rsa_private.pem', 'rb').read()

auth = HTTPSignatureAuth(key_id='Test', secret=secret)
z = requests.get('https://api.example.com/path/to/endpoint',
auth=auth, headers={'X-Api-Version': '~6.5'})

Class initialization parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that keys and secrets should be bytes objects. At attempt will be made to convert them, but if that fails then exceptions will be thrown.

.. code:: python

httpsig_cffi.Signer(secret, algorithm='rsa-sha256')

``secret``, in the case of an RSA signature, is a string containing private RSA pem. In the case of HMAC, it is a secret password.
``algorithm`` is one of the six allowed signatures: ``rsa-sha1``, ``rsa-sha256``, ``rsa-sha512``, ``hmac-sha1``, ``hmac-sha256``,
``hmac-sha512``.


.. code:: python

httpsig_cffi.requests_auth.HTTPSignatureAuth(key_id, secret, algorithm='rsa-sha256', headers=None)

``key_id`` is the label by which the server system knows your RSA signature or password.
``headers`` is the list of HTTP headers that are concatenated and used as signing objects. By default it is the specification's minimum, the ``Date`` HTTP header.
``secret`` and ``algorithm`` are as above.


Tests
-----

To run tests::

tox


License
-------

Both this module and the original module_ are licensed under the MIT license.


httpsig_cffi
============

15.0.0 (2015-Jan-16)
--------------------

* Move from PyCrypto to Cryptography.
* Move to py.test.


httpsig (previous)
==================

1.1.0 (2014-Jul-24)
-------------------

* Changed "(request-line)" to "(request-target)" to comply with Draft 3.

1.0.3 (2014-Jul-09)
-------------------

* Unified the default signing algo under one setting. Setting httpsig.sign.DEFAULT_SIGN_ALGORITHM changes it for all future instances.
* Handle invalid params a little better.

1.0.2 (2014-Jul-02)
-------------------

* Ensure we treat headers as ASCII strings.
* Handle a case in the authorization header where there's garbage (non-keypairs) after the method name.

1.0.1 (2014-Jul-02)
-------------------

* Python 3 support (2.7 + 3.2-3.4)
* Updated tox and Travis CI configs to test the supported Python versions.
* Updated README.

1.0.0 (2014-Jul-01)
-------------------
* Written against http://tools.ietf.org/html/draft-cavage-http-signatures-02
* Added "setup.py test" and tox support.
* Added sign/verify unit tests for all currently-supported algorithms.
* HeaderSigner and HeaderVerifier now share the same message-building logic.
* The HTTP method in the message is now properly lower-case.
* Resolved unit test failures.
* Updated Verifier and HeaderVerifier to handle verifying both RSA and HMAC sigs.
* Updated versioneer.
* Updated contact/author info.
* Removed stray keypair in test dir.
* Removed SSH agent support.
* Removed suport for reading keyfiles from disk as this is a huge security hole if this is used in a server framework like drf-httpsig.

1.0b1 (2014-Jun-23)
-------------------
* Removed HTTP version from request-line, per spec (breaks backwards compatability).
* Removed auto-generation of missing Date header (ensures client compatability).


http-signature (previous)
=========================

0.2.0 (unreleased)
~~~~~~~~~~~~~~~~~~

* Update to newer spec (incompatible with prior version).
* Handle `request-line` meta-header.
* Allow secret to be a PEM encoded string.
* Add test cases from spec.

0.1.4 (2012-10-03)
~~~~~~~~~~~~~~~~~~

* Account for ssh now being re-merged into paramiko: either package is acceptable (but paramiko should ideally be >= 1.8.0)

0.1.3 (2012-10-02)
~~~~~~~~~~~~~~~~~~

* Stop enabling `allow_agent` by default
* Stop requiring `ssh` package by default -- it is imported only when `allow_agent=True`
* Changed logic around ssh-agent: if one key is available, don't bother with any other authentication method
* Changed logic around key file usage: if decryption fails, prompt for password
* Bug fix: ssh-agent resulted in a nonsensical error if it found no correct keys (thanks, petervolpe)
* Introduce versioneer.py

Metadata

Release files for httpsig_cffi 15.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for httpsig_cffi 15.0.0
File Size Uploaded Provenance Actions
httpsig_cffi-15.0.0.tar.gz 22.3 kB Without provenance Details for httpsig_cffi-15.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for httpsig_cffi 15.0.0
File Interpreter ABI Platform Actions
httpsig_cffi-15.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for httpsig_cffi-15.0.0-py2.py3-none-any.whl

Total release size: 41.6 kB

Release files / httpsig_cffi-15.0.0.tar.gz

Download URL httpsig_cffi-15.0.0.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
12b61008cd21cb18986de743959d63caaf8ac5b3cf3ee1d49fd1c53fe4f5d47a
BLAKE2b-256 checksum
How to use checksums
2b2609b2f9b962e821abb41a7b5d15b60aedeccfe68f7fafd2040617f0b27c29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / httpsig_cffi-15.0.0-py2.py3-none-any.whl

Download URL httpsig_cffi-15.0.0-py2.py3-none-any.whl
Size 19.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
62cfee03b8a43aaefb2b5b4da72514d581f3b527a24a1316152c08052eec9795
BLAKE2b-256 checksum
How to use checksums
93f5c9a213c0f906654c933f1192148d8aded2022678ad6bce8803d3300501c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for httpsig_cffi 15.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

15.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page