ska
Symmetric-key algorithm encryption. Lets you easily generate signatures for signing of the HTTP requests. Allows you to validate signed requests and identify possible validation errors.
Key concepts
Host and server share the Secret Key, which is used to sign requests. Secret key is never sent around.
Each HTTP request is signed on the client side using the shared Secret Key and as an outcome produces the triple (signature, auth_user, valid_until) which are used to sign the requests.
signature (str): Signature generated.
auth_user (str): User making the request. Can be anything.
valid_until (float|str): Signature expiration time (Unix timestamp).
On the server side, HTTP request is validated using the shared Secret Key. It’s being checked whether signature is valid and not expired.
Installation
$ pip install ska
Usage examples
Client side
Required imports.
>>> from ska import Signature, RequestHelper
Generate a signature.
>>> signature = Signature.generate_signature( >>> auth_user = 'user', >>> secret_key = 'your-secret-key' >>> )
Create a request helper. Your endpoint operates with certain param names. In order to have the job done in an easy way, we feed those params to the request helper and let it make a signed endpoint URL for us.
>>> request_helper = RequestHelper( >>> signature_param = 'signature', >>> auth_user_param = 'auth_user', >>> valid_until_param = 'valid_until' >>> )
Append signature params to the endpoint URL.
>>> url = request_helper.signature_to_url( >>> signature = signature, >>> endpoint_url = 'http://e.com/api/' >>> ) http://e.com/api/?valid_until=1378045287.0&auth_user=user&signature=YlZpLFsjUKBalL4x5trhkeEgqE8%3D
Make a request.
>>> import requests >>> r = requests.get(url)
Server side
Required imports.
>>> from ska import RequestHelper
Create a request helper. Your endpoint operates with certain param names. In order to have the job done in an easy way, we feed those params to the request helper and let it extract data from signed request for us.
>>> request_helper = RequestHelper( >>> signature_param = 'signature', >>> auth_user_param = 'auth_user', >>> valid_until_param = 'valid_until' >>> )
Validate the request data. Note, that request.GET is given just as an example.
>>> validation_result = request_helper.validate_request_data( >>> data = request.GET, >>> secret_key = 'your-secret-key' >>> )
Your implementation further depends on you, but may look as follows.
>>> if validation_result.result: >>> # Validated, proceed further >>> # ... >>> else: >>> # Validation not passed. >>> raise Http404(validation_result.reason)
License
GPL 2.0/LGPL 2.1
Support
For any issues contact me at the e-mail given in the Author section.
Metadata
Release files for ska 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ska-0.1.tar.gz | 5.7 kB | Without provenance | Details for ska-0.1.tar.gz |
Release files / ska-0.1.tar.gz
| Download URL | ska-0.1.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1686383629e6b39cf786e0045b5b7a628cf928a755a3bc2a1cad70b5edf9b834
|
|
BLAKE2b-256 checksum How to use checksums |
16fc37d42744a03a49d15d2a2d98a79a16689898a27d99628b57f3f5f3fab247
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ska 0.1
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.