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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 Windows x86

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 Windows x86

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 Windows x86

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 Windows x86

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

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.8 Windows x86

File details

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

File metadata

  • Download URL: winkerberos-0.11.0rc3.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.0rc3.tar.gz
Algorithm Hash digest
SHA256 ca38129ef9cb2413ef3d73e4928c15a9a738ef2185c82d9e7cdcbb53cde7a8ab
MD5 7ff2bb93c1eb85803e501cc69e128ccd
BLAKE2b-256 40830f9c83d7902ba2ad8de8140fa3d6c6cbf816574296cc6533ad527410b263

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a68e651306246f54abd1f226172b81e72d6fd9eb8db5c9788c3af0dbdbdb3db7
MD5 dd8bd6331ad92b90a159444041df0fe4
BLAKE2b-256 c820bfbdd7d99f316b5f9fa54b769ca8028eddf71c8e4427176f73ec61059fbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 141d2b8cae899610351156799d8c6cd59fb61543a0382a2e071b368e3a968caf
MD5 c8e8c6a241c401f0effd4f80e19bdb49
BLAKE2b-256 16665ef88e6be883ae76c17e2c9fa7b8aad9c80d4c0b2bf2bba128cba1fbb0dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a732e9053923dc0c3272abf7c6900ad42a84d6288b3b6fa57cd36c8a48b71093
MD5 d219a63f2a2a2bbe796608eb5ad3861b
BLAKE2b-256 c37a8a1f1d1e240214b776de32e842541f47de0b61c36ac0befe74b0bf6bad9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 ee6b496a5b73235a17c18f29380545be38bed6fcc457d4be74866b555d8aedb2
MD5 1aa0ac1cd1a35d49ae5da9e6e06df03d
BLAKE2b-256 78db9574b816590adfbcd7bde4cb73166f9f4ad76dd137d2a8adf7ee8c1d3fae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 33ec58e453aeb50f4d11e9c05a826f958bf55d196558f55b6d247083c55372d0
MD5 05b05151d421e333ad430f192febcd71
BLAKE2b-256 c48cc7e400936f4037e581e6d7e5cdee2e4b4acd98676f005964c91d16d86b94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 9e6ba50d4e5f2fbb1cef865aea08962c28ba85133674df6ce3336b1fe3d20d5e
MD5 c36885f812485b40782073fe2d183fc3
BLAKE2b-256 ca7f8047726f4f33c2dbacd4db4e137dc8734a1c1c872d169f93839922a4a7c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 24f4b26812884d0f85f4797d74ac54d2d77a490ab93d275ae60ae393f9ca97b1
MD5 8cd60a56051cfa027bd87c123cf15ec0
BLAKE2b-256 6c91b4b96c8e1195056ad4e1738d9c8f43cf13d4b24926c4c532dd21de8248cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 846e3c59c495379afd52a47fe191b9e05c8d1c1a22654eb5c9f28118e80aa444
MD5 edbca5179608d357463158b7a844f25c
BLAKE2b-256 37626d912fbda69e4d8717897806c88714e5e0985d205a65a6c933188bcc01f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c7530a37a4641634aeec1621f9682e74a51c69019065e1ca5f745e8fbb4cc31d
MD5 77b9b46c227c6f60fc2d403e1822dbf0
BLAKE2b-256 ba9d04e2fded8bd546c64100c54bf3b6a9d45724ea95f652ee264116bcb4a94a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for winkerberos-0.11.0rc3-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 2956359394ca005d28580992d5f2bf3beee1e46cc68f75b0ca7b5ba9c79b8b66
MD5 3700c43d7250294a15233505efd113de
BLAKE2b-256 865ca8923a5c855590d9b23a9b81284743772e15acc51dcf536f6b97eb930062

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