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 Tictoe Minimax算法不断引发异常   java弹性时间计算器字符串开关   java从表单post操作中检索值   java Selenium webdriver无法在youtube上找到元素   java如何自动填写XFA(PDF)表单?   java为什么我的秒表程序不能运行?   raspberry pi禁用java中的其他声音   java如何配置web。xml,glassfishweb。JSF的xml文件?   使用浏览器运行自动测试时出现java错误。如何运行它?   java如何阻止Swing程序在每次向JTextArea添加文本时调整组件的大小   javajavax。注射注射无效   java如何改进Solaris服务器配置   java如何在elasticsearch后端脱机时处理Hibernate搜索启动   java TCPsocket的延迟很差,除非持续流式传输