用python 3.5+编写的符合rfc 6960标准的ocsp响应程序框架。

ocspresponder的Python项目详细描述


Build statusPyPI VersionPyPI DownloadsLicensePython VersionsStability Status

用python 3.5+编写的符合rfc 6960标准的ocsp响应程序框架。

它基于ocspbuilderasn1crypto库。http 服务器是使用Bottle实现的。

当前状态:alpha。还没用在生产上。

功能

目标

  • 简单:不要用无数的选项压倒用户。
  • 灵活:可使用Python代码进行配置。

支持的扩展

  • Nonce(RFC 6960第4.4.1节)

尚未实现

  • 每个请求/响应有多个证书

用法

现在,ocspresponder假设自定义密钥对仅用于 正在签署OCSP响应。

要能够实例化OCSPResponder服务器,需要提供 此密钥对以及颁发CA的证书。

ISSUER_CERT='path/to/issuer_cert.pem'OCSP_CERT='path/to/responder_cert.pem'OCSP_KEY='path/to/responder_key.pem'

此外,您还需要提供两个自定义函数:

  • 一个函数-给定一个证书序列-将返回适当的 CertificateStatus和-取决于状态-吊销 日期时间。
  • 一个函数-给定一个证书序列-将返回相应的 作为字符串的证书。

您需要自己实现这些功能。在未来,顺道来 可以提供典型用例的库。

示例实现:

fromocspresponderimportOCSPResponder,CertificateStatusdefvalidate(serial:int)->(CertificateStatus,Optional[datetime]):ifcertificate_is_valid(serial):return(CertificateStatus.good,None)elifcertificate_is_expired(serial):expired_at=get_expiration_date(serial)return(CertificateStatus.revoked,expired_at)elifcertificate_is_revoked(serial):revoked_at=get_revocation_date(serial)return(CertificateStatus.revoked,revoked_at)else:return(CertificateStatus.unknown,None)defget_cert(serial:int)->str:"""
    Assume the certificates are stored in the ``certs`` directory with the
    serial as base filename.
    """withopen('certs/%s.cert.pem'%serial,'r')asf:returnf.read().strip()

如果两个函数中的任何一个发生异常,则ocsp响应 将返回设置为internal_errorresponse_status

现在您可以实例化OCSPResponder并启动开发服务器:

print('Initializing OCSP responder')app=OCSPResponder(ISSUER_CERT,OCSP_CERT,OCSP_KEY,validate_func=validate,cert_retrieve_func=get_cert,)print('Starting OCSP responder')app.serve(port=8080,debug=True)

键入提示

此库使用PEP484中定义的可选类型提示。那typing 模块仅在Python3.5+中提供,但旧版本的Python可以运行 如果typing模块是从pypi安装的,则也会显示代码。

测试

要运行测试,请使用pip安装requirements-dev.txt,然后运行pytest:

py.test -v

释放过程

更新setup.pyCHANGELOG.md中的版本号:

vim -p setup.py CHANGELOG.md

执行发行版的提交和签名标记:

export VERSION={VERSION}
git add setup.py CHANGELOG.md
git commit -m "Release v${VERSION}"
git tag -u C75D77C8 -m "Release v${VERSION}" v${VERSION}

生成源和二进制分布:

python3 setup.py sdist
python3 setup.py bdist_wheel

签署文件:

gpg --detach-sign -u C75D77C8 -a dist/ocspresponder-${VERSION}.tar.gz
gpg --detach-sign -u C75D77C8 -a dist/ocspresponder-${VERSION}-py3-none-any.whl

在pypi上注册包:

twine3 register -r pypi-threema dist/ocspresponder-${VERSION}.tar.gz

上载包:

twine3 upload -r pypi-threema dist/ocspresponder-${VERSION}*
git push
git push --tags

许可证

Copyright 2016 Threema GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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

推荐PyPI第三方库


热门话题
java在交叉表jasperreport中拆分行   java将数据从customdialog类传输到父类   在EclipseKepler中导入一个java项目,而不使用。项目文件   java找不到符号错误Netbeans   java反射和远程处理在内部是如何工作的?   java如何为少数测试类而不是所有测试类运行cobertura代码覆盖率?   java Hibernate增量起始数   xml需要帮助在java中获取横向克拉之间的文本   swing Java嵌套JPanel未保持指定的大小   如何使用自定义java库(来自github)   java移动应用程序在调用@OAuthSecurity资源时保持加载   错误:从C启动java jar时无法访问jarfile#   javascript如何将html页面移动到新的project/war文件?   java HTTP状态404–未找到spring tc服务器   具有多个使用者的java Producer使用notify()失败   java在运行时使用neo4j创建连接数据,每天的数据量为10.2亿个节点   当通过Eclipse插件部署时,java无法加载部署到独立GlassFish的web应用程序   java使用多种编程语言:重点是什么?   intellij idea Java不能将lambda用于自制接口lambda转换的目标类型必须是接口   java对所有扩展类只访问一次静态变量