跳转到主要内容

Kerberos高级接口

项目描述

PyKerberos软件包

这个Python软件包是对Kerberos (GSSAPI)操作的高级包装。目标是避免构建一个包装整个Kerberos.framework的模块,而是提供一组有限的功能,这些功能用于基于http://www.ietf.org/rfc/rfc4559.txt的客户端/服务器Kerberos认证。

此处的大部分C代码改编自Apache的mod_auth_kerb-5.0rc7。

构建

在此目录下,运行

python setup.py build

测试

要在tests文件夹中运行测试,测试机器上必须有一个有效的Kerberos设置。您可以使用.travis.sh脚本快速轻松地设置Kerberos KDC和Apache网络端点,用于测试。否则,您也可以运行以下命令来运行一个自包含的Docker容器

docker run \
-v $(pwd):/app \
-w /app \
-e PYENV=2.7.13 \
-e KERBEROS_USERNAME=administrator \
-e KERBEROS_PASSWORD=Password01 \
-e KERBEROS_REALM=example.com \
-e KERBEROS_PORT=80 \
ubuntu:16.04 \
/bin/bash .travis.sh

需要在该库相同的目录下运行docker命令,并且您可以通过更改命令中设置的PYENV环境变量值来使用不同的Python版本进行测试。

请参阅testing_notes.md以获取更多信息。

重要

该库提供的checkPassword方法仅用于测试目的,因为它不提供任何针对可能的KDC欺骗的保护。该方法不应在生产代码中使用。

通道绑定

您可以使用此库进行具有通道绑定支持的认证。通道绑定是标识用于认证的特定数据通道的标签。您可以使用通道绑定提供更多有效身份的证明。一些服务,如微软的扩展保护,可以在授权上强制执行通道绑定支持,您可以使用此库来满足这些要求。

有关通过GSSAPI设置的通道绑定的更多详细信息,请参阅此处 https://docs.oracle.com/cd/E19455-01/806-3814/overview-52/index.html。以TLS为例,这是如何在您的认证机制中添加通道绑定支持的方式。以下代码片段基于RFC5929 https://tools.ietf.org/html/rfc5929,使用'tls-server-endpoint-point'类型。

import hashlib

def get_channel_bindings_application_data(socket):
    # This is a highly simplified example, there are other use cases
    # where you might need to use different hash types or get a socket
    # object somehow.
    server_certificate = socket.getpeercert(True)
    certificate_hash = hashlib.sha256(server_certificate).hexdigest().upper()
    certificate_digest = base64.b16decode(certificate_hash)
    application_data = b'tls-server-end-point:%s' % certificate_digest

    return application_data

def main():
    # Code to setup a socket with the server
    # A lot of code to setup the handshake and start the auth process
    socket = getsocketsomehow()

    # Connect to the host and start the auth process

    # Build the channel bindings object
    application_data = get_channel_bindings_application_data(socket)
    channel_bindings = kerberos.channelBindings(application_data=application_data)

    # More work to get responses from the server

    result, context = kerberos.authGSSClientInit(kerb_spn, gssflags=gssflags, principal=principal)

    # Pass through the channel_bindings object as created in the kerberos.channelBindings method
    result = kerberos.authGSSClientStep(context, neg_resp_value, channel_bindings=channel_bindings)

    # Repeat as necessary

Python API

请参阅kerberos.py。

版权和许可

版权(c)2006-2021苹果公司。保留所有权利。

本软件根据Apache许可证第2版许可。Apache许可证是一种成熟的开源许可证,它使协作开源软件开发成为可能。

有关许可条款的完整文本,请参阅“LICENSE”文件。

项目详情


下载文件

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

源分布

kerberos-1.3.1.tar.gz (19.1 kB 查看哈希值)

上传时间

构建分布

kerberos-1.3.1-cp39-cp39-macosx_10_9_x86_64.whl (20.2 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ x86-64

kerberos-1.3.1-cp38-cp38-macosx_10_15_x86_64.whl (33.2 kB 查看哈希值)

上传时间 CPython 3.8 macOS 10.15+ x86-64

kerberos-1.3.1-cp27-cp27m-macosx_11_1_x86_64.whl (20.3 kB 查看哈希值)

上传于 CPython 2.7m macOS 11.1+ x86-64

由...支持

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