Troy Hunt的“我被屏蔽了吗”公共API的接口
pyhibp的Python项目详细描述
pyhibp(pyhave i been pwned)
与特洛伊·亨特的“我被压过了吗?”(hibp)公共api。对api的完整引用 规范可以在HIBP API Reference找到。
此模块检测何时达到API的速率限制,并在达到该限制时引发运行时错误 已超过,或者根据提交的数据遇到另一个API定义的错误条件时。什么时候? 从调用中找到数据,返回的数据将采用从端点检索的格式,并记录 在相关函数的返回类型信息中。
注意,pwnedpasswords
api后端没有速率限制。如果您打算批量查询密码或
散列,您应该考虑下载可以通过Pwned Passwords页访问的原始数据文件。
安装
$ pip install pyhibp
示例用法
对于交互式示例,请查看jupyter笔记本中的^{
importpyhibpfrompyhibpimportpwnedpasswordsaspw# Required: A descriptive user agent must be set describing the application consuming# the HIBP APIpyhibp.set_user_agent(ua="Awesome application/0.0.1 (An awesome description)")# Check a password to see if it has been disclosed in a public breach corpusresp=pw.is_password_breached(password="secret")ifresp:print("Password breached!")print("This password was used {0} time(s) before.".format(resp))# Get data classes in the HIBP systemresp=pyhibp.get_data_classes()# Get all breach informationresp=pyhibp.get_all_breaches()# Get a single breachresp=pyhibp.get_single_breach(breach_name="Adobe")# An API key is required for calls which search by email address# (so get_pastes/get_account_breaches)# See <https://haveibeenpwned.com/API/Key>HIBP_API_KEY=NoneifHIBP_API_KEY:# Set the API key prior to using the functions which require it.pyhibp.set_api_key(key=HIBP_API_KEY)# Get pastes affecting a given email addressresp=pyhibp.get_pastes(email_address="test@example.com")# Get breaches that affect a given accountresp=pyhibp.get_account_breaches(account="test@example.com",truncate_response=True)
开发
这个项目目前打算与Python2和Python3兼容。因此,我们通过pipenv
使用虚拟环境。
要开发或测试,请执行以下操作:
# Install the prerequisite virtual environment provider $ pip install pipenv # Initialize the pipenv environment and install the module within it $ make dev # To run PEP8, tests, and check the manifest $ make tox
其他命令可以在Makefile
中找到。
目标
- 同步到最新的hibp api,在有意义的地方实现端点访问函数。例如, 为了安全起见,没有实现向pwned密码端点提交sha-1的功能。见 下面的“关于密码检查”了解更多详细信息。
- 对于违反和粘贴,充当中介;返回从服务接收到的json。
关于密码检查
- 对于密码,提供了提供要检查的明文密码的选项,以方便实现。
- 为了增加安全性,
pwnedpasswords.is_password_breached()
只传输sha-1的前五个字符 散列到pwned passwords api端点;安全密码将保持安全,而不会泄露完整的散列。