High level interface to SSPI for Kerberos client auth
Project description
- Info:
See github for the latest source.
About
A native Kerberos client implementation for Python on Windows. This module mimics the API of pykerberos to implement Kerberos authentication with Microsoft’s Security Support Provider Interface (SSPI). It supports Python 3.8+.
Installation
WinKerberos is in the Python Package Index (pypi). Use pip to install it:
python -m pip install winkerberos
WinKerberos requires Windows 7 / Windows Server 2008 R2 or newer.
Building and installing from source
You must have the correct version of VC++ installed for your version of Python:
Python 3.8+ - Visual Studio 2015+ (Any version)
Once you have the required compiler installed, run the following command from the root directory of the WinKerberos source:
pip install .
Building HTML documentation
First install Sphinx:
python -m pip install Sphinx
Then run the following command from the root directory of the WinKerberos source:
pip install -e . python -m sphinx -b html doc doc/_build
Examples
This is a simplified example of a complete authentication session following RFC-4752, section 3.1:
import winkerberos as kerberos
def send_response_and_receive_challenge(response):
# Your server communication code here...
pass
def authenticate_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 receive its first
# challenge.
if channel_bindings is not None:
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.
while status == kerberos.AUTH_GSS_CONTINUE:
if channel_bindings is not None:
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 challenge
kerberos.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)
Channel bindings can be generated with help from the cryptography module. See https://tools.ietf.org/html/rfc5929#section-4.1 for the rules regarding hash algorithm choice:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
def channel_bindings(ssl_socket):
server_certificate = ssl_socket.getpeercert(True)
cert = x509.load_der_x509_certificate(server_certificate, default_backend())
hash_algorithm = cert.signature_hash_algorithm
if hash_algorithm.name in ("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()
return kerberos.channelBindings(application_data=application_data)
Viewing API Documentation without Sphinx
Use the help function in the python interactive shell:
>>> import winkerberos
>>> help(winkerberos)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for winkerberos-0.11.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52068fded003214c51084d98f5b3d8c43400eea190afd151fd2f480e9d2c571f |
|
MD5 | 46e2c4db190522738ac8bc0ff8aaa82c |
|
BLAKE2b-256 | 5312d4096c313833f15d561b648b5157f8e15b1da0c2a9b2ac650d060a4ed338 |
Hashes for winkerberos-0.11.0-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 546bbd9d83f0eeac7df1f9634c4c6865176fd624f41032dfa98e25420a161d7f |
|
MD5 | 7887e015d4f8d4f4124d119bd301b0ed |
|
BLAKE2b-256 | 7406b9d9a8ba334d264061cf34d20c81ca08fea09dd520edb2b9c3b2ca8df4d9 |
Hashes for winkerberos-0.11.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07a6f24a6c0da5e8a91cbd8c5f28b1a4ac68dcea3b73d43b036a697637b0c9a6 |
|
MD5 | a1c15791d15f42e6c0b516591a07277f |
|
BLAKE2b-256 | 7dd4174bf165754df8fb858ff08ca087df50c2f9cdf6e800ffb09a9a8e8f497f |
Hashes for winkerberos-0.11.0-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89a5572438aab17d51da75eb1101ea7183142869e3c69b23ebad4395a78a1bd2 |
|
MD5 | da64e961a01aa935f71d543eb126199b |
|
BLAKE2b-256 | 492f0964f68fc7f8ba19754352b88bf08d0da589b5332a3782f89c00eaecd73b |
Hashes for winkerberos-0.11.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9545356f438eb9de7e7196bd8cda7a8e3ab19a083951fec7c612b88a67d1e98 |
|
MD5 | 540eeeae76a1256eaf454c0c32f98f98 |
|
BLAKE2b-256 | 1d7c69f26f1d51ff543003c05984ee2e387a569a2857d0e3a49830d2d5436f51 |
Hashes for winkerberos-0.11.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cba83a4ad65d1ccba2b34476eded7564e94da390ab6ee240aab7ee8f856fd61e |
|
MD5 | 6a466e94479111c69e99f241616e9f0e |
|
BLAKE2b-256 | bdddd8d9ad427549537eae4bc175e685e285e0a8c32d9442e64e78e38397d52c |
Hashes for winkerberos-0.11.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f66075f9122bb13dadd2da33365177ccd4f41258f9410fba79d06402086db6 |
|
MD5 | cc9b6cbf57a5d42c3f342b4f66c039aa |
|
BLAKE2b-256 | 19734efdaa2b1ec868e235516d0db8dbb1e43a8b79c5c1f0a3e5f58c484039cc |
Hashes for winkerberos-0.11.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e03139558e3451d6971219ca49873e77e2f99871f8b2f0b0577bb616022f782a |
|
MD5 | 572752443eb8dcdb427d186466880c6c |
|
BLAKE2b-256 | fd7d21104f225ca0e1641d895864440ad0f24a605d2b83b179e2779feee4f2cd |
Hashes for winkerberos-0.11.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77282f7bbbf593b7bdf2c708ddef0f95be3d9e9dfc5e0e49a9e9ce233f427319 |
|
MD5 | 9cc51997506ed304a5c81a389f7c2cef |
|
BLAKE2b-256 | 28c0a28e225a707751ea9983f63763599633cc90a683ba9bbb3c60b014fd24e2 |
Hashes for winkerberos-0.11.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23f7711086bbce1e12991d04978a4b5ae9061ae5c717329ef8c46331d84a1114 |
|
MD5 | 43d544c4232591505778327daf24e2d2 |
|
BLAKE2b-256 | 31f5ef4ea2b0041a2a6b3b3ac0bad95962264ce13537896766e7125283eaa04c |