python webauthn依赖方库

pywarp的Python项目详细描述


pywarp是w3cWebAuthn标准依赖方的实现 python中的组件。webauthn标准用于为两个因素提供高级身份验证安全性, 通过使用专用硬件安全密钥和生物识别技术的多因素和无密码身份验证模型 设备,如Yubico YubiKeyGoogle TitanTPM,和 Touch ID

与hotp(RFC 4226)和totp等更基本的双因素标准相比 (RFC 6238),一个 FIDO U2Fwebauthn的配置文件使用非对称加密来 避免使用共享密钥设计,这样可以增强您的身份验证解决方案,防止服务器端攻击。硬件 u2f还将客户机机密存储在专用的单用途设备中,这增强了客户机对 客户端攻击。并通过自动将凭据范围限定为依赖方ID(应用程序源/域名), U2F增加了对网络钓鱼攻击的保护。

pywarp实现了webauthn的依赖方组件。依赖方是一个服务器端应用程序,它指示 浏览器(用户代理)使用webauthn api对其用户进行身份验证。

要查看pywarp的实际示例,请检查examples目录。包括两个演示:一个 AWS Chalice应用程序和Flask应用程序。

除了读取WebAuthn standard,我们建议实现者读取 以及OWASP Authentication Cheat SheetNIST SP 800-63-3: Digital Authentication Guideline用于高级概述 认证最佳实践。

安装

pip install pywarp

pywarp依赖于cryptography,而这又需要openssl和cffi。

概要

frompywarpimportRelyingPartyManager,Credentialfrompywarp.backendsimportDynamoBackend# 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 userrp.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 userrp.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)

examples/chalice/app.pyexamples/chalice/chalicelib/index.html(前端)获取完整示例。

存储后端

您的应用程序可能正在使用应用服务器,如uwsgi、数据库后端(如mysql、postgresql或 MongoDB,也许还有一个像Flask或Django这样的框架来把它们绑在一起。Pywarp对你的 数据库、架构或模型。相反,它提供了一个抽象类(pywarp.backends.CredentialStorageBackend) 表示用于存储和检索用户的WebAuthn凭据数据的接口。

要部署pywarp,请声明CredentialStorageBackend的子类。在子类中,实现对 数据库,然后将子类的实例传递给pywarp.RelyingPartyManager(credential_storage_backend=...)

classCredentialStorageBackend:def__init__(self):self.database_client=...defget_credential_by_email(self,email):user_record=self.database_client.get(email)returnCredential(credential_id=user_record["cred_id"],credential_public_key=user_record["cred_pub_key"])defsave_credential_for_user(self,email,credential):self.database_client.update(email,{"cred_id":credential.credential_id,"cred_pub_key":bytes(credential.public_key)})defsave_challenge_for_user(self,email,challenge,type):self.database_client.update(email,{type+"challenge":challenge})defget_challenge_for_user(self,email,type):user_record=self.database_client.get(email)returnuser_record[type+"challenge"]

示例:chalice app

chalice应用程序示例(在examples/chalice目录中)可以部署为AWS Lambda应用程序 与常规aws帐户凭据一起使用时(通过AWS CLI中的aws configure配置)。这个 示例使用DynamoDB作为存储后端。

有关详细信息,请参见API documentation

作者

  • 安德烈·基斯利克

错误

请在GitHub上报告错误、问题、功能请求等。

许可证

根据Apache License, Version 2.0条款授权。

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android Action_Edit Intent无法像以前一样调用App Gallery来编辑图片   确保JRE兼容性的java适当程序(32或64位)   java JSONArray。for循环中的add(JSONObject)正在替换for循环中的旧值,数组由循环中的最后一个值组成   java需要帮助创建一个返回数组的方法,该数组的元素是另一个数组的平方   使用SmbFile w/groovy XmlSluper()创建xml。解析()Java   检查大小后的java ArrayIndexOutOfBoundsException   乘法表中的第k个最小元素   java 401 on请求,其中指定了'permitAll()'   java如何附加ORC文件   java hibernate类模型   java IDEA没有看到由自定义注释处理器生成的方法   Servlet中未声明java SerialVersionId   java linkedlist到达列表末尾时   java如何正确对齐EditText光标?   java 6编译器1.6上的eclipse重写方法错误   java如何在基于Jersey的RESTful Web服务中读取post数据   java如何在活动中正确使用接口?   Java的JIT编译器的工作速度有多快?