用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第三方库


热门话题
jenkins在java代码的csv中使用前导零传递数字   终止java应用程序javaw。exe eclipse   java平均字长。文本   java在事务中关闭连接时会发生什么?   java如何为rich faces extendedDatatable启用可调整大小的列?   SpringJavaWebApp头nosniff不适合js和css文件   Java:抛出异常   java获取拒绝ArrayList中存在的用户名的代码。   关于编写JNDI服务提供者的java教程   java Android emulator电子书示例已停止   java如何防止双向关系中的循环   在Java中,如何将接口的实现作为变量传递给方法?   java有没有办法通过注释来监听CoreNLP处理的进度?   java Eclipse错误:导入项目时“无法读取项目描述文件”   java为什么findViewById返回null?