跳转到主要内容

由python的keyring库支持的CTAP(客户端到认证器协议)设备

项目描述

PyPi version Python version Code style: Black Read the docs CI workflow

此库提供了一个虚拟CTAP2(客户端到认证器协议)设备的实现,它使用keyring库作为其后端。

可以使用此实现作为CTAP2兼容设备的参考,或者使用主机机器作为认证器,而不是使用外部设备。

一个常见的用例是将此库用作webauthn流的认证器,在机器上配置的密钥环中存储密钥并检索断言。

支持的功能包括
  • make-credential、get-assertion、get-next-assertion和get-info CTAP2流程

  • 使用以下COSE算法管理密钥:RS1、RS256、PS256、EC256、EdDSA

  • 使用任何可用的密钥环作为创建的密钥对的后端(例如WinCred、Keychain等)

  • 在OSX和Windows上通过Touch-ID和Windows-Hello进行用户存在和验证

  • 以安全的方式存储密钥,不附带任何PII(个人识别信息)


安装

在darwin机器上运行以下命令

$ pip install ctap-keyring-device

使用此库

创建凭证流程

from fido2.webauthn import PublicKeyCredentialCreationOptions, PublicKeyCredentialType, PublicKeyCredentialParameters
from ctap_keyring_device.ctap_keyring_device import CtapKeyringDevice
from fido2.client import Fido2Client
from fido2 import cose
import base64

device = CtapKeyringDevice.list_devices()[0]
origin = 'https://rp.pasten.com'
client = Fido2Client(device, origin)

rp = {'id': 'pasten.com', 'name': origin[8:], 'icon': '...'}
user = {'id': 'danny@pasten.io', 'name': 'Danny Shemesh', 'icon': '...', 'displayName': 'Danny Pastanny'}
challenge = base64.b64encode(b'my-challenge')
timeout_ms = 30_000

pub_key_cred_params = [PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY, cose.ES256.ALGORITHM)]
options = PublicKeyCredentialCreationOptions(rp, user, challenge, pub_key_cred_params, timeout=timeout_ms)

attestation, client_data = client.make_credential(options)

获取断言流程

from fido2.webauthn import PublicKeyCredentialRequestOptions, PublicKeyCredentialType, \
    PublicKeyCredentialParameters, PublicKeyCredentialDescriptor, UserVerificationRequirement
from ctap_keyring_device.ctap_keyring_device import CtapKeyringDevice
from fido2.client import Fido2Client
from fido2 import cose
import base64

device = CtapKeyringDevice.list_devices()[0]
origin = 'https://rp.pasten.com'
client = Fido2Client(device, origin)

challenge = base64.b64encode(b'my-challenge')
rp = {'id': 'pasten.com', 'name': origin[8:], 'icon': '...'}
credential_id = b'.......'
allow_list = [
    PublicKeyCredentialDescriptor(PublicKeyCredentialType.PUBLIC_KEY, credential_id)
]
timeout_ms = 30_000

pub_key_cred_params = [PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY, cose.ES256.ALGORITHM)]
options = PublicKeyCredentialRequestOptions(challenge=challenge, rp_id=rp['id'],
                                            allow_credentials=allow_list, timeout=timeout_ms,
                                            user_verification=UserVerificationRequirement.PREFERRED)
assertions, client_data = client.get_assertion(options)

请参阅ctap-keyring-device/tests中的示例。


CTAP流程图

创建凭证流程

Make Credential Flow

获取断言流程

Get Assertion Flow

安全考虑

使用此库可以帮助用户将机器的密钥环作为CTAP2合规的FIDO认证器。

凭证存储在配置的密钥环中,默认为平台代码运行时的合理实现(例如,OSX上的keychain,Windows上的WinCred等)

创建凭证流程将创建一个用于签名的密钥对,使用请求的COSE算法

私钥使用随机UUID4作为密码短语进行加密,使用hazard的最佳可用加密

凭据ID由<用户ID的UUID5>_<密钥密码短语>组成,并返回给请求的客户端;假定凭据ID保存在远程机器上,并且在ctap获取断言请求的允许列表中始终提供。

上述方法使我们能够以加密密钥的方式生成和存储密钥,从而降低密钥泄露的风险;并且不直接存储用户ID,即使解密也难以使用该密钥。

除了上述安全措施外,还可以请求UV(用户验证)选项,以便在返回断言之前触发第二个因素;在OSX上使用Touch-ID/密码提示,在Windows上使用Windows-Hello。


发布版本

在GitHub上设置了CI/CD管道 - 一旦将PR合并到master,就会自动将预发布版部署到GitHub;当标记发布时,它将自动部署到PyPI。


运行测试

要本地运行测试,请安装并调用tox

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

ctap-keyring-device-1.0.6.tar.gz (266.8 kB 查看哈希值)

上传时间

构建分布

ctap_keyring_device-1.0.6-py2.py3-none-any.whl (16.7 kB 查看哈希值)

上传时间 Python 2 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面