python webauthn依赖方库
pywarp的Python项目详细描述
pywarp是w3cWebAuthn标准依赖方的实现 python中的组件。webauthn标准用于为两个因素提供高级身份验证安全性, 通过使用专用硬件安全密钥和生物识别技术的多因素和无密码身份验证模型 设备,如Yubico YubiKey, Google Titan, TPM,和 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用于高级概述 认证最佳实践。
概要
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.py和 examples/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上报告错误、问题、功能请求等。