Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib-refresh #95

Merged
merged 33 commits into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5eefdd8
Delete flask_demo
MasterKale Oct 14, 2021
05e955e
Clear out tests
MasterKale Oct 14, 2021
5cfd4cc
Rename tox.ini
MasterKale Oct 14, 2021
35bb0c4
Tweak license date
MasterKale Oct 14, 2021
39e70fc
Ignore macOS files
MasterKale Oct 14, 2021
9145288
Delete lib files
MasterKale Oct 14, 2021
036998c
Update VERSION to 1.0.0
MasterKale Oct 14, 2021
e11fa36
Support last three versions of Python
MasterKale Oct 14, 2021
133662a
Add .vscode
MasterKale Oct 14, 2021
3b557c5
Add requirements.txt
MasterKale Oct 14, 2021
69893d7
Migrate examples
MasterKale Oct 14, 2021
fe889eb
Migrate primary functionality
MasterKale Oct 14, 2021
33f3688
Switch to Black for formatting
MasterKale Oct 14, 2021
fa29544
Migrate unit tests
MasterKale Oct 14, 2021
bad3f09
Replace `skip_defaults` with `exclude_unset`
MasterKale Oct 14, 2021
a815a2d
Form core API of library
MasterKale Oct 14, 2021
bf2570f
Update examples for new exports
MasterKale Oct 14, 2021
30114d2
Reorganize examples into reg and auth
MasterKale Oct 14, 2021
8d2c51d
Add README.md
MasterKale Oct 14, 2021
d77f081
Add Pythonic WebAuthn badge
MasterKale Oct 14, 2021
dac8c04
Tweak repo title header level
MasterKale Oct 14, 2021
6e9ce90
Update setup.py
MasterKale Oct 14, 2021
1f76c55
Prune Docker stuff (for now)
MasterKale Oct 14, 2021
3c63c0e
Clean up old build files
MasterKale Oct 14, 2021
16ed12c
Add -beta1 to version
MasterKale Oct 14, 2021
a634aa1
Remove old TODO
MasterKale Oct 14, 2021
faf7322
Use more absolute imports
MasterKale Oct 14, 2021
8a0b15d
Consolidate __init__ imports
MasterKale Oct 14, 2021
d935318
Update unit tests imports
MasterKale Oct 14, 2021
fe2b840
Update build_and_test.yml deps install
MasterKale Oct 15, 2021
da00b30
Support last three Python versions
MasterKale Oct 15, 2021
b78e0f3
Wrap python versions in strings and use v2
MasterKale Oct 15, 2021
8f22b04
Indicate Python 3.8 as minimum version
MasterKale Oct 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build_and_test.yml
Expand Up @@ -15,18 +15,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
python-version: ['3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r flask_demo/requirements.txt
pip install -r requirements.txt
- name: Test with unittest
run: |
python -m unittest
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -107,3 +107,4 @@ venv.bak/
# PyWebAuthn
py_webauthn.env
webauthn.db
.DS_Store
7 changes: 7 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,7 @@
{
"python.pythonPath": "venv/bin/python",
"python.linting.mypyEnabled": false,
"python.linting.flake8Enabled": false,
"python.formatting.blackPath": "venv/bin/black",
"python.linting.enabled": true
}
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2017 Duo Security, Inc. All rights reserved.
Copyright (c) 2017-2021 Duo Security, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand Down
11 changes: 0 additions & 11 deletions MANIFEST.in

This file was deleted.

72 changes: 72 additions & 0 deletions README.md
@@ -0,0 +1,72 @@
# py_webauthn
[![PyPI](https://img.shields.io/pypi/v/webauthn.svg)](https://pypi.python.org/pypi/webauthn) [![GitHub license](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/duo-labs/py_webauthn/master/LICENSE) ![Pythonic WebAuthn](https://img.shields.io/badge/Pythonic-WebAuthn-brightgreen?logo=python&logoColor=white)

A Python3 implementation of the [WebAuthn API](https://www.w3.org/TR/webauthn-2/) focused on making it easy to leverage the power of WebAuthn.

This library supports all FIDO2-compliant authenticators, including security keys, Touch ID, Face ID, Windows Hello, Android biometrics...and pretty much everything else.

## Installation

This module is available on **PyPI**:

`pip install webauthn`

## Requirements

- Python 3.8 and up

## Usage

The library exposes just a few core methods on the root `webauthn` module:

- `generate_registration_options()`
- `verify_registration_response()`
- `generate_authentication_options()`
- `verify_authentication_response()`

Two additional helper methods are also exposed:

- `options_to_json()`
- `base64url_to_bytes()`

### Registration

See **examples/registration.py** for practical examples of using `generate_registration_options()` and `verify_registration_response()`.

You can also run these examples with the following:

```sh
# See "Development" below for venv setup instructions
venv $> python -m examples.registration
```

### Authentication

See **examples/authentication.py** for practical examples of using `generate_authentication_options()` and `verify_authentication_response()`.

You can also run these examples with the following:

```sh
# See "Development" below for venv setup instructions
venv $> python -m examples.authentication
```

## Development

### Installation

Set up a virtual environment, and then install the project's requirements:

```sh
$> python3 -m venv venv
$> source venv/bin/activate
venv $> pip install -r requirements.txt
```

### Testing

Python's unittest module can be used to execute everything in the **tests/** directory:

```sh
venv $> python -m unittest
```
166 changes: 0 additions & 166 deletions README.rst

This file was deleted.

10 changes: 0 additions & 10 deletions docker-compose.yml

This file was deleted.

70 changes: 70 additions & 0 deletions examples/authentication.py
@@ -0,0 +1,70 @@
from webauthn import (
generate_authentication_options,
verify_authentication_response,
options_to_json,
base64url_to_bytes,
)
from webauthn.helpers.structs import (
PublicKeyCredentialDescriptor,
UserVerificationRequirement,
AuthenticationCredential,
)

################
#
# Examples of using webauthn for authentication ceremonies
#
# Authentication responses are representative of WebAuthn credential responses
# as they would be encoded for transmission from the browser to the RP as JSON. This
# primarily means byte arrays are encoded as Base64URL on the client.
#
################

# Simple Options
simple_authentication_options = generate_authentication_options(rp_id="example.com")

print("\n[Authentication Options - Simple]")
print(options_to_json(simple_authentication_options))

# Complex Options
complex_authentication_options = generate_authentication_options(
rp_id="example.com",
challenge=b"1234567890",
timeout=12000,
allow_credentials=[PublicKeyCredentialDescriptor(id=b"1234567890")],
user_verification=UserVerificationRequirement.REQUIRED,
)

print("\n[Authentication Options - Complex]")
print(options_to_json(complex_authentication_options))

# Authentication Response Verification
authentication_verification = verify_authentication_response(
credential=AuthenticationCredential.parse_raw(
"""{
"id": "ZoIKP1JQvKdrYj1bTUPJ2eTUsbLeFkv-X5xJQNr4k6s",
"rawId": "ZoIKP1JQvKdrYj1bTUPJ2eTUsbLeFkv-X5xJQNr4k6s",
"response": {
"authenticatorData": "SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MFAAAAAQ",
"clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoiaVBtQWkxUHAxWEw2b0FncTNQV1p0WlBuWmExekZVRG9HYmFRMF9LdlZHMWxGMnMzUnRfM280dVN6Y2N5MHRtY1RJcFRUVDRCVTFULUk0bWFhdm5kalEiLCJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjUwMDAiLCJjcm9zc09yaWdpbiI6ZmFsc2V9",
"signature": "iOHKX3erU5_OYP_r_9HLZ-CexCE4bQRrxM8WmuoKTDdhAnZSeTP0sjECjvjfeS8MJzN1ArmvV0H0C3yy_FdRFfcpUPZzdZ7bBcmPh1XPdxRwY747OrIzcTLTFQUPdn1U-izCZtP_78VGw9pCpdMsv4CUzZdJbEcRtQuRS03qUjqDaovoJhOqEBmxJn9Wu8tBi_Qx7A33RbYjlfyLm_EDqimzDZhyietyop6XUcpKarKqVH0M6mMrM5zTjp8xf3W7odFCadXEJg-ERZqFM0-9Uup6kJNLbr6C5J4NDYmSm3HCSA6lp2iEiMPKU8Ii7QZ61kybXLxsX4w4Dm3fOLjmDw",
"userHandle": "T1RWa1l6VXdPRFV0WW1NNVlTMDBOVEkxTFRnd056Z3RabVZpWVdZNFpEVm1ZMk5p"
},
"type": "public-key",
"clientExtensionResults": {}
}"""
),
expected_challenge=base64url_to_bytes(
"iPmAi1Pp1XL6oAgq3PWZtZPnZa1zFUDoGbaQ0_KvVG1lF2s3Rt_3o4uSzccy0tmcTIpTTT4BU1T-I4maavndjQ"
),
expected_rp_id="localhost",
expected_origin="http://localhost:5000",
credential_public_key=base64url_to_bytes(
"pAEDAzkBACBZAQDfV20epzvQP-HtcdDpX-cGzdOxy73WQEvsU7Dnr9UWJophEfpngouvgnRLXaEUn_d8HGkp_HIx8rrpkx4BVs6X_B6ZjhLlezjIdJbLbVeb92BaEsmNn1HW2N9Xj2QM8cH-yx28_vCjf82ahQ9gyAr552Bn96G22n8jqFRQKdVpO-f-bvpvaP3IQ9F5LCX7CUaxptgbog1SFO6FI6ob5SlVVB00lVXsaYg8cIDZxCkkENkGiFPgwEaZ7995SCbiyCpUJbMqToLMgojPkAhWeyktu7TlK6UBWdJMHc3FPAIs0lH_2_2hKS-mGI1uZAFVAfW1X-mzKL0czUm2P1UlUox7IUMBAAE"
),
credential_current_sign_count=0,
require_user_verification=True,
)
print("\n[Authentication Verification]")
print(authentication_verification.json(indent=2))
assert authentication_verification.new_sign_count == 1