kerberos客户端身份验证的sspi高级接口

winkerberos的Python项目详细描述


Info:See github for the latest source.
Author:Bernie Hackett <bernie@mongodb.com>

关于

windows上python的本机kerberos客户端实现。本模块 模拟pykerberos到的api 使用Microsoft的安全支持提供程序实现kerberos身份验证 接口(SSPI)。它支持Python2.6、2.7和3.3+。

安装

温克贝罗斯在Python Package Index (pypi)里面。使用pip安装:

python -m pip install winkerberos

WinkerBeros需要Windows 7/Windows Server 2008 R2或更高版本。

从源代码构建和安装

您必须为您的版本安装VC++的正确版本 Python:

一旦安装了所需的编译器,请从 winkerberos源的根目录:

python setup.py install

构建HTML文档

首先安装Sphinx

python -m pip install Sphinx

然后从winkerberos的根目录运行以下命令 来源:

python setup.py doc

示例

这是完整身份验证会话的简化示例 遵循RFC-4752第3.1节:

importwinkerberosaskerberosdefsend_response_and_receive_challenge(response):# Your server communication code here...passdefauthenticate_kerberos(service,user,channel_bindings=None):# Initialize the context object with a service principal.status,ctx=kerberos.authGSSClientInit(service)# GSSAPI is a "client goes first" SASL mechanism. Send the# first "response" to the server and recieve its first# challenge.ifchannel_bindingsisnotNone:status=kerberos.authGSSClientStep(ctx,"",channel_bindings=channel_bindings)else:status=kerberos.authGSSClientStep(ctx,"")response=kerberos.authGSSClientResponse(ctx)challenge=send_response_and_receive_challenge(response)# Keep processing challenges and sending responses until# authGSSClientStep reports AUTH_GSS_COMPLETE.whilestatus==kerberos.AUTH_GSS_CONTINUE:ifchannel_bindingsisnotNone:status=kerberos.authGSSClientStep(ctx,challenge,channel_bindings=channel_bindings)else:status=kerberos.authGSSClientStep(ctx,challenge)response=kerberos.authGSSClientResponse(ctx)or''challenge=send_response_and_receive_challenge(response)# Decrypt the server's last challengekerberos.authGSSClientUnwrap(ctx,challenge)data=kerberos.authGSSClientResponse(ctx)# Encrypt a response including the user principal to authorize.kerberos.authGSSClientWrap(ctx,data,user)response=kerberos.authGSSClientResponse(ctx)# Complete authentication.send_response_and_receive_challenge(response)

通道绑定可以在cryptography模块的帮助下生成。见 https://tools.ietf.org/html/rfc5929#section-4.1关于 哈希算法选择:

fromcryptographyimportx509fromcryptography.hazmat.backendsimportdefault_backendfromcryptography.hazmat.primitivesimporthashesdefchannel_bindings(ssl_socket):server_certificate=ssl_socket.getpeercert(True)cert=x509.load_der_x509_certificate(server_certificate,default_backend())hash_algorithm=cert.signature_hash_algorithmifhash_algorithm.namein('md5','sha1'):digest=hashes.Hash(hashes.SHA256(),default_backend())else:digest=hashes.Hash(hash_algorithm,default_backend())digest.update(server_certificate)application_data=b"tls-server-end-point:"+digest.finalize()returnkerberos.channelBindings(application_data=application_data)

在没有Sphinx的情况下查看API文档

使用python交互式shell中的帮助函数:

>>>importwinkerberos>>>help(winkerberos)

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

推荐PyPI第三方库


热门话题
java播放流媒体音乐   LWJGL中的java纹理未显示   java从父集合中删除时删除子对象   mysql希望在我的代码中添加验证,如果表不存在,它应该用java创建新表   java我可以关闭客户端的socket而不引起服务器端的EOFEException吗?   java Primefaces对话框框架咆哮和showMessageInDialog不工作   hadoop配置单元无法初始化类java。网网络接口   关键字中缺少oracle11g Java iBatis   java在RESTAPI中创建PUT和POST端点,而不创建GET端点?   java Math abs和ceil输出编译错误   java Tomcat 8.017代md5及其摘要。球棒   java SpringBean配置xml文件在IteliJ Idea中加载   java为什么在使用Powershell指定Xms和Xmx时,它们什么都不做,但通过Netbeans IDE可以正常工作?   java Drools项目构建失败,kjar打包从7.7版开始