Skip to main content

PyWARP: Python Web Authentication Relying Party library

PyWARP is an implementation of the W3C WebAuthn standard’s Relying Party component in Python. The WebAuthn standard is used to provide advanced authentication security for two-factor, multifactor and passwordless authentication models through the use of dedicated hardware security keys and biometric devices such as Yubico YubiKey, Google Titan, TPM, and Touch ID.

Compared to more basic two-factor standards like HOTP (RFC 4226) and TOTP (RFC 6238), the FIDO U2F profile of WebAuthn uses asymmetric cryptography to avoid using a shared secret design, which strengthens your authentication solution against server-side attacks. Hardware U2F also sequesters the client secret in a dedicated single-purpose device, which strengthens your clients against client-side attacks. And by automating scoping of credentials to relying party IDs (application origin/domain names), U2F adds protection against phishing attacks.

PyWARP implements the Relying Party component of WebAuthn. A Relying Party is a server-side application that instructs the browser (user agent) to use WebAuthn APIs to authenticate its users.

To see an example of PyWARP in action, check the examples directory. Two demos are included: an AWS Chalice app and a Flask app.

In addition to reading the WebAuthn standard, we recommend that implementers read the OWASP Authentication Cheat Sheet and NIST SP 800-63-3: Digital Authentication Guideline for a high level overview of authentication best practices.

Installation

pip install pywarp

PyWARP depends on cryptography, which in turn requires OpenSSL and CFFI.

Synopsis

from pywarp import RelyingPartyManager, Credential
from pywarp.backends import DynamoBackend  # This is an example. See "storage backends" below for other databases.

rp_id = "myapp.example.com"  # This must match the origin domain of your app, as seen by the browser.
rp = RelyingPartyManager("PyWARP demo", rp_id=rp_id, credential_storage_backend=DynamoBackend())

# Get options for navigator.credentials.create() - pass these to your frontend when registering a user
rp.get_registration_options(email=str)

# Run the protocol in https://www.w3.org/TR/webauthn/#registering-a-new-credential,
# then call the credential storage backend to store the credential public key.
rp.register(attestation_object=bytes, client_data_json=bytes, email=bytes)

# Get options for navigator.credentials.get() - pass these to your frontend when logging in a user
rp.get_authentication_options(email=str)

# Run the protocol in https://www.w3.org/TR/webauthn/#verifying-assertion,
# calling the credential storage backend to retrieve the credential public key.
# If no exception is raised, proceed with user login.
rp.verify(authenticator_data=bytes, client_data_json=bytes, signature=bytes, user_handle=bytes, raw_id=bytes,
          email=bytes)

See examples/chalice/app.py and examples/chalice/chalicelib/index.html (frontend) for a complete example.

Storage backends

Your application is presumably using an application server like uWSGI, a database backend like MySQL, PostgreSQL or MongoDB, and maybe a framework like Flask or Django to tie them together. PyWARP makes no assumptions about your database, schema, or model. Instead, it provides an abstract class (pywarp.backends.CredentialStorageBackend) representing an interface for storing and retrieving WebAuthn credential data for your users.

To deploy PyWARP, declare a subclass of CredentialStorageBackend. In your subclass, implement bindings to your database, then pass an instance of your subclass to pywarp.RelyingPartyManager(credential_storage_backend=...):

class CredentialStorageBackend:
    def __init__(self):
        self.database_client = ...

    def get_credential_by_email(self, email):
        user_record = self.database_client.get(email)
        return Credential(credential_id=user_record["cred_id"],
                          credential_public_key=user_record["cred_pub_key"])

    def save_credential_for_user(self, email, credential):
        self.database_client.update(email, {"cred_id": credential.credential_id,
                                            "cred_pub_key": bytes(credential.public_key)})

    def save_challenge_for_user(self, email, challenge, type):
        self.database_client.update(email, {type + "challenge": challenge})

    def get_challenge_for_user(self, email, type):
        user_record = self.database_client.get(email)
        return user_record[type + "challenge"]

Example: Chalice app

The Chalice app example (in the examples/chalice directory) can be deployed as an AWS Lambda application when used with conventional AWS account credentials (configured via aws configure in the AWS CLI. This example uses DynamoDB as a storage backend.

See the API documentation for more.

Authors

  • Andrey Kislyuk

Bugs

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

License

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

https://img.shields.io/travis/pyauth/pywarp.svg https://codecov.io/github/pyauth/pywarp/coverage.svg?branch=master https://img.shields.io/pypi/v/pywarp.svg https://img.shields.io/pypi/l/pywarp.svg https://readthedocs.org/projects/pywarp/badge/?version=latest

Metadata

Release files for pywarp 0.0.4

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

Source distribution (sdist)

Source distribution for pywarp 0.0.4
File Size Uploaded
pywarp-0.0.4.tar.gz 11.7 kB Details

Built distribution (wheel)

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

Total release size: 22.2 kB

Release files / pywarp-0.0.4.tar.gz

Download URL pywarp-0.0.4.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bda9312cdb3fa2d19d10cead6764a716f803ee77eb2cf15fc1f08c8c3902ca05
BLAKE2b-256 checksum
How to use checksums
962dfbb95b3c0c7e26a6df730555736c9f7c08c86d3d069d48ff374bcd155e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release files / pywarp-0.0.4-py2.py3-none-any.whl

Download URL pywarp-0.0.4-py2.py3-none-any.whl
Size 10.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
da5bc50307e1cd9b055cde1c3a1f67a42ff3e61854b0c1792ddbcfd7d8b11479
BLAKE2b-256 checksum
How to use checksums
08df25c2143a0566f0be50c5caf910d8cef52c951eefa7e7f0c86e84d95e3c11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.2

1 release file

0.0.1

1 release file

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