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


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.11.0rc2.tar.gz (35.6 kB view details)

Uploaded Source

Built Distributions

winkerberos-0.11.0rc2-cp312-cp312-win_amd64.whl (27.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

winkerberos-0.11.0rc2-cp312-cp312-win32.whl (25.4 kB view details)

Uploaded CPython 3.12 Windows x86

winkerberos-0.11.0rc2-cp311-cp311-win_amd64.whl (27.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

winkerberos-0.11.0rc2-cp311-cp311-win32.whl (25.3 kB view details)

Uploaded CPython 3.11 Windows x86

winkerberos-0.11.0rc2-cp310-cp310-win_amd64.whl (27.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

winkerberos-0.11.0rc2-cp310-cp310-win32.whl (25.3 kB view details)

Uploaded CPython 3.10 Windows x86

winkerberos-0.11.0rc2-cp39-cp39-win_amd64.whl (27.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

winkerberos-0.11.0rc2-cp39-cp39-win32.whl (25.3 kB view details)

Uploaded CPython 3.9 Windows x86

winkerberos-0.11.0rc2-cp38-cp38-win_amd64.whl (27.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

winkerberos-0.11.0rc2-cp38-cp38-win32.whl (25.3 kB view details)

Uploaded CPython 3.8 Windows x86

File details

Details for the file winkerberos-0.11.0rc2.tar.gz.

File metadata

  • Download URL: winkerberos-0.11.0rc2.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for winkerberos-0.11.0rc2.tar.gz
Algorithm Hash digest
SHA256 1619245c335fab67fee138fc0e411d49656399f7f7ee753f7d65729a2078bc93
MD5 eea62f613b43f5d98585da675bdd6eb9
BLAKE2b-256 081e66b472be0cbc53eb5652ff055009d339bc964e3c556ae24f6cf2b30e3751

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9b681a1503f602972f8a955c6a0ee6abd670d1acac2799fdd4ae5b504894a1a5
MD5 d0aeb6411d53145e9ed9554d3e213b85
BLAKE2b-256 61b5096ac77a1aef447ee23fb745bc18817d116c4238904874b31126c02f1e7c

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 1624475fcf96c44d1643d6187ae4857be19cf32c4d665e4f3aa418822145030a
MD5 309247162d426f3eab6adca20e86ec30
BLAKE2b-256 83fdc7dece443672efe8943d7bdb166b1f2c21a7643b61ab2d1388108ad721f2

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 929e658d24a1674f8c744918b2621f6f50d39f26bd379e3e179953ebb050f552
MD5 8a90333077165b7f422e67125de616f2
BLAKE2b-256 dde8a2724fd6e01dc637a3802b0943968d91d9b3ae4122066a94768a0416d1f2

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 fb6ee14be01697a94a61ab0631fe77b4b82e5130fe9b622d4de6ae657933eddf
MD5 088aa43f2347d96f582fd3574352be57
BLAKE2b-256 4a189381c8245845ef32852ba874055db893c909421d76a479d1b865a37ef86b

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8d6cac43f7ad8d8b8e86555006cd7dd9c1231ad6f4910d47fdd61c2e78d66e7f
MD5 56ce9c8811fe4038ed6edc6ac10f93fb
BLAKE2b-256 cd1277e915f7fadafe4654e4380ddd171b341c346c33d1b01c4f7ef457bbcc69

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp310-cp310-win32.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 b7180105d56fdbcec1cee602893296c7c3f0c41733c5242e653373e436ea56a2
MD5 8e89999200d4158059d253c02060d748
BLAKE2b-256 e131eebaebcc4829c0f7ade2f1921f3c8a308a87ccc43cd11f2be674b98bfd7b

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 984abf5671b00b530e2c597cad4c94182f4b1e71be3d67e7956c7364d7df7406
MD5 e3d0a93047a090db31b978a9deaddac4
BLAKE2b-256 94d3930cc8077632e352c24dcec7dfc810c876e1cb865735819dc7c0e760d613

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp39-cp39-win32.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 a82a0f2f0861a155d246d68ded53e9158344e7432d52f29fc9686e14e2e29cd9
MD5 ebbd5ca6c14f57e80f29c097501a54fe
BLAKE2b-256 be797453c007045d697e00c5bfa09e63f28d5ecb821e882d12d611b71d375893

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 cac6129044e12f0c8adb631005fc849c3931a29e16bc882b58589f8429bb7560
MD5 9b998a5fabbd0992d8bc516d5eb50d28
BLAKE2b-256 3624a60b28e8d33ddaedcc8cd38577676a6d5465ff5286911c5c631be5a818b4

See more details on using hashes here.

File details

Details for the file winkerberos-0.11.0rc2-cp38-cp38-win32.whl.

File metadata

File hashes

Hashes for winkerberos-0.11.0rc2-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 4cc796aa20f25b0a4b97f555671d4b0c1d3ddf0b3552b79873cadc8d0458c9e9
MD5 a7a8ff26b8af755d4e21ef562f6fd606
BLAKE2b-256 62fdfe503b785d8996a785874944fe45afd238f77a77e2a633b075325802a8d1

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