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.9+.

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.9+ - 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.12.1.tar.gz (35.7 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 Windows x86

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 Windows x86

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 Windows x86

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 Windows x86

File details

Details for the file winkerberos-0.12.1.tar.gz.

File metadata

  • Download URL: winkerberos-0.12.1.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for winkerberos-0.12.1.tar.gz
Algorithm Hash digest
SHA256 3c52a64f875bd2ba47cf1fc34ba9bb27ee84de4489c6e7cf5481cd48b8529416
MD5 6affae838008295aa9835951ccbf21d1
BLAKE2b-256 6462003a499c4f4602d45fa9020bb4ec374e8b45b7236af4359f7ad6bc926059

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1.tar.gz:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file winkerberos-0.12.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.12.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dd72211b4f54e6b5f667a180d0dd86df063829f5e4bbd85a7fd92b9b7316148b
MD5 5fdea3ea40b03bae536cd17e73fc4f2f
BLAKE2b-256 4a9af37857a72373feb936b18e809a68c54e1e4fc6d2fdd8f8bd3fdfbf36be36

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp312-cp312-win_amd64.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file winkerberos-0.12.1-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for winkerberos-0.12.1-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 acc409d597bacbf74972390d0bb292579669afc3ba74292ea11d6031ceffd279
MD5 e67a4d991a9b362b1974bba94bcb062b
BLAKE2b-256 1d8830830724a8ac5bc4bf6c768f282984cb952196f6bfd03e587bbf66113ffc

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp312-cp312-win32.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file winkerberos-0.12.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for winkerberos-0.12.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 526561b1a0544c6687558946b2c26e095be61e4c26f15bbd8abeff052706c87c
MD5 4ef4cc5464d47c3df5dc72f74b17d20e
BLAKE2b-256 a285ecffb1d50da287ddd2d30676846ce0f3688d695fc501a866331eddef1895

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp311-cp311-win_amd64.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file winkerberos-0.12.1-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for winkerberos-0.12.1-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 43d24a99df0c49c470d268004e5299baad09929eeb648d85261388077a4aa377
MD5 429af6ac1c4e09b6fc15c36b3ab30473
BLAKE2b-256 db2712de468cff29840254a1e8d7a76c044141ee903082a9650c8ff3576dec49

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp311-cp311-win32.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.12.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9a3c1ff629b4bad9c15f0a6dc08f9340c56381469b70cc809597946a4fbeef3b
MD5 2b79b62b95f0cf1e8f2b35ac9d6947b1
BLAKE2b-256 84bc008b8ee876fc480a872079f4bd4f8a5bda2c4e2a66b0e58a85d8f8936f32

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp310-cp310-win_amd64.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.12.1-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 6f3892f207598fe5eba6accf3010a89c19a390b47dbc5e3564ef1f71acd6cfc5
MD5 bcdbc70ad546de7f6e83ef9ee8d191d7
BLAKE2b-256 9ee38ad7d41725159a8d61b170af3c85433cbf49e60219075f26ea6d5316167a

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp310-cp310-win32.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.12.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b09b22a918784d38b1e0e3bcb359c601ad93cb1b43cd2c76d42126214480918f
MD5 2c57bbd63225108d64c743f42026e29a
BLAKE2b-256 c45ff17d0cdf371b6107dd9d5542e19abb86297f088d1dc7d8addfcc36c03717

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp39-cp39-win_amd64.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: winkerberos-0.12.1-cp39-cp39-win32.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for winkerberos-0.12.1-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 8d4502c2b3cbf99635690f46da93716656cec989f7b9e7a26d0be0b3a90265a4
MD5 1c1b67d75bc5f9da488dbea9980a633d
BLAKE2b-256 0e9114f6b48638905d222e3d05b333943916c5041744c52274044e918f1ba40f

See more details on using hashes here.

Provenance

The following attestation bundles were made for winkerberos-0.12.1-cp39-cp39-win32.whl:

Publisher: release-python.yml on mongodb/winkerberos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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