Skip to main content

High level interface to SSPI for Kerberos client auth

Project description

Info:

See github for the latest source.

Author:

Bernie Hackett <bernie@mongodb.com>

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 2.7 and 3.5+.

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:

Once you have the required compiler installed, run the following command from the root directory of the WinKerberos source:

python setup.py 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:

python setup.py doc

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 recieve 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

winkerberos-0.9.0.zip (44.0 kB view details)

Uploaded Source

Built Distributions

winkerberos-0.9.0-cp310-cp310-win_amd64.whl (23.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

winkerberos-0.9.0-cp310-cp310-win32.whl (21.3 kB view details)

Uploaded CPython 3.10 Windows x86

winkerberos-0.9.0-cp39-cp39-win_amd64.whl (23.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

winkerberos-0.9.0-cp39-cp39-win32.whl (21.3 kB view details)

Uploaded CPython 3.9 Windows x86

winkerberos-0.9.0-cp38-cp38-win_amd64.whl (23.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

winkerberos-0.9.0-cp38-cp38-win32.whl (21.3 kB view details)

Uploaded CPython 3.8 Windows x86

winkerberos-0.9.0-cp37-cp37m-win_amd64.whl (23.7 kB view details)

Uploaded CPython 3.7m Windows x86-64

winkerberos-0.9.0-cp37-cp37m-win32.whl (21.2 kB view details)

Uploaded CPython 3.7m Windows x86

winkerberos-0.9.0-cp36-cp36m-win_amd64.whl (25.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

winkerberos-0.9.0-cp36-cp36m-win32.whl (22.0 kB view details)

Uploaded CPython 3.6m Windows x86

winkerberos-0.9.0-cp35-cp35m-win_amd64.whl (25.1 kB view details)

Uploaded CPython 3.5m Windows x86-64

winkerberos-0.9.0-cp35-cp35m-win32.whl (22.0 kB view details)

Uploaded CPython 3.5m Windows x86

winkerberos-0.9.0-cp27-cp27m-win_amd64.whl (22.6 kB view details)

Uploaded CPython 2.7m Windows x86-64

winkerberos-0.9.0-cp27-cp27m-win32.whl (20.1 kB view details)

Uploaded CPython 2.7m Windows x86

File details

Details for the file winkerberos-0.9.0.zip.

File metadata

  • Download URL: winkerberos-0.9.0.zip
  • Upload date:
  • Size: 44.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for winkerberos-0.9.0.zip
Algorithm Hash digest
SHA256 be14d27ce7a3b29775dd1018b0ae06f29a4025070839ffb1465ab120e287c479
MD5 1e15fcfd7ca6dd347f8f5965969aa132
BLAKE2b-256 bdba91d285631c7e8cfa7d9b36869b522de6e7b52447c5dabbc7181c168d7016

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.9.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 935d781229163968235289c307a64d187655fef9a520fe939ab9b07022e90df5
MD5 08b2b852538a4c8b54cca7c265edc2ee
BLAKE2b-256 c9ad64c6cc14f91ed442faa9fe39270b719ccdf7a97cbd4a969e4c771ae0a588

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for winkerberos-0.9.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 53d78f100e21560bd4bf6caad9d151a4b19c9221e4024c79c05b0aad7b4eac76
MD5 8a12dd2dd5521371f252db9fb6a6a190
BLAKE2b-256 d8293e26b1caea945f9f91023ccb519f8e2366617e4899ae63de68402ce314c7

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.9.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 90f9f94a2720852a7c71b36f60dffbd905ce33f21eb2148aeee8ad92d0e91dd9
MD5 3343707fc0f1c5fb94bf02100714bb8a
BLAKE2b-256 e13c245cdbbdfd328eb78706314f4eb4131c49ab26b368614941e8c17689d690

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for winkerberos-0.9.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 e58b3259f3e08b32d24b84f527a159422bec92b3b19780e1a7886a0da951e76d
MD5 3babc2dc6a1673c1a248bfd5b954936a
BLAKE2b-256 82e2cb92bfb7b8b77cef36f435ee5365a1988ef75e965ef973dd28c03c23d5ad

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.9.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 eab514d756d3dfe3a37e52aa20ca2ce096eed619134606b1fd6709870a26a414
MD5 b15d82034deb6d5c9204fb5cee89e295
BLAKE2b-256 e48b027330d4990a8a295419b14e312500d9ef723088ecba57f4eed341f0b184

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp38-cp38-win32.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for winkerberos-0.9.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 35db43bd74e0c4fc8de255da7d50d0a5171da3c5a479db0c023ac0eba34d409e
MD5 04e7c9c4615a06be5b6d7587d0c853ea
BLAKE2b-256 a9efd3c1dc2b26f7395d0ae3997dbf70c1c89c878aa6516285f23b1da0c6f876

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.9.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 4b8633c371b6cc7fcf12232239c10a60ee4263234797f6bbe96eec914f7b4a5a
MD5 feeed13f21a02099440061dfdace5c61
BLAKE2b-256 b52e0cfab259d8323b933b6bb5d7d11123f7bf010d141337bda8df677886a070

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for winkerberos-0.9.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 16c4372feec133ca9909904d8a059f44c223540ccc36292e5ad5c5573f66b749
MD5 463d38f74153229a06253a426c323330
BLAKE2b-256 2ce9da073745b210184f4a01a6323218a80c5ae428f0967a2f4bb5a096eb6609

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.9.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 8ee8dd8620dde796184b06558b75c43d00202af7e23d7f3625355ae44a5dfc2d
MD5 ffd015c0fc93941d77d29e73ea26639d
BLAKE2b-256 7fd147c0dea1192a0da99794ee59eaaf913196ac8460eb6f11511297cd733784

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp36-cp36m-win32.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for winkerberos-0.9.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 b0ed44a30378db382cdbcc24dedc317b26fba08d16f4902cd05a578e33e426e6
MD5 fc1d8324bafd68f0cad5cd5ea4a5547f
BLAKE2b-256 1cbb15cc23746ab3cf6b8e73a9fef699143a1b4a7896cc24cc127332643ce1f7

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.9.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 451bd69e55a467e5c156b2324ab98e42441105be08f7247f2465aea08da85aec
MD5 94a625e76a8276a132f1e997edd27fe6
BLAKE2b-256 d798907c78035f96bf048873a001e00afbaa4541c3dfddbf0f48bcca140f728a

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp35-cp35m-win32.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for winkerberos-0.9.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 d00b2c4197761a03db2000e2ef977aebdd12384c5214917c21b6168014c1f331
MD5 5e0611de21138f8f9ebe12e189ecc6f8
BLAKE2b-256 96bc4e4b290b58951fb51560256c14199d34d9612aec0546a74940f0a0ee1cc7

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for winkerberos-0.9.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 b77f39220215fab5e5586602a3401726c1e751d2b7a47fa2699e59f8de1dfa45
MD5 24d8445f47d8480afec0adedfbb8391c
BLAKE2b-256 18e471e5bf1e2c1af5a0afa2aeb00aa4aed4885a054e2db3ee275dc6731b2da1

See more details on using hashes here.

File details

Details for the file winkerberos-0.9.0-cp27-cp27m-win32.whl.

File metadata

  • Download URL: winkerberos-0.9.0-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for winkerberos-0.9.0-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 4c26c14f17132135077eedfda53f4d517a24d9543b40e93f03864f95caa3c57c
MD5 a55adca1c06fad8e7ac8e4c3cb1ec6a8
BLAKE2b-256 6422b089d9db3e3c678592f2d0a4d1887b68124ce86951e4c9dba48a933aeb99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page