Skip to main content

HTTP Message Signatures

Project description

HTTP Message Signatures

This library implements HTTP Message Signatures. The underlying crypto is provided by PyCryptodomex.

Pypi Page: https://pypi.org/project/httpsigpy/

Usage:

from httpsig import *

Signing

To sign an HTTP message, first it has to be parsed into its message components:

msg = event['body'].encode('utf-8')
components = parse_components(msg)

This provides a data structure with each possible message component indexed by its name, identifier, and value.

To create the signature input, pass in the parsed components structure as well as a list of components to sign, with the signature parameters:

siginput = generate_input(
    components, 
    ( # covered components list
        { 'id': "@method" }, 
        { 'id': "@authority" },
        { 'id': "@path" },
        { 'id': "content-digest" },
        { 'id': "content-length" },
        { 'id': "content-type" }
    ),
    {
        'created': 1618884473,
        'keyid': 'test-key-rsa-pss'
    }
)

base = siginput['signatureInput']
sigparams = siginput['signatureParams']

This outputs a base string that can be passed to the signer.

key = RSA.import_key(PKCS8.unwrap(PEM.decode(rsaTestKeyPssPrivate)[0])[1])

h = SHA512.new(base.encode('utf-8'))
signer = pss.new(key, mask_func=mgf512, salt_bytes=64)

signed = http_sfv.Item(signer.sign(h))

Verify

To verify an HTTP message, first it has to be parsed into its message components:

msg = event['body'].encode('utf-8')
components = parse_components(msg)

This provides a data structure with each possible message component indexed by its name, identifier, and value.

To create the signature input, pass in the parsed components structure as well as a list of components to sign, and the signature parameters.

siginput = generate_input(
    components, 
    ( # covered components list
        { 'id': "@method" }, 
        { 'id': "@authority" },
        { 'id': "@path" },
        { 'id': "content-digest" },
        { 'id': "content-length" },
        { 'id': "content-type" }
    ),
    {
        'created': 1618884473,
        'keyid': 'test-key-rsa-pss'
    }
)

This can be passed to the verifier function:

h = SHA512.new(base.encode('utf-8'))

pubKey = RSA.import_key(rsaTestKeyPssPublic)
verifier = pss.new(pubKey, mask_func=mgf512, salt_bytes=64)

try:
    verified = verifier.verify(h, signed.value)
    print('> YES!')
except (ValueError, TypeError):
    print('> NO!')

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

httpsigpy-0.0.8.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

httpsigpy-0.0.8-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file httpsigpy-0.0.8.tar.gz.

File metadata

  • Download URL: httpsigpy-0.0.8.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.5

File hashes

Hashes for httpsigpy-0.0.8.tar.gz
Algorithm Hash digest
SHA256 0afd504aa839f14d26578c9747736ffd40930f2402d072321db083c3f0b7565e
MD5 768283696a674070f93a64e06a3e3039
BLAKE2b-256 91854ef60a22e6b29852a005859f1c5bbd8a0874d081f998eb4c5d9d994cd553

See more details on using hashes here.

File details

Details for the file httpsigpy-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: httpsigpy-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.5

File hashes

Hashes for httpsigpy-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0d4a7af9a5a765008d6187c61d4c12e8f82142b4cf981f1a4792d0efed3789cc
MD5 228f8656b9e7b9bb9e07056ff7522988
BLAKE2b-256 55263f01fcdc96335b048d7d6dd6fe1b1a4430309095affbb695288bdf81344f

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