SSPI API bindings for Python
Reason this release was yanked:
sspi will be renamed as it conflicts with a pywin32 namespace
Project description
Python SSPI Library
This library provides Python functions that wraps the Windows SSPI API.
It is designed to be both a high and low level interface that other libraries can easily leverage to use with SSPI integration.
The high level interface is under the sspi
namespace whereas the low-level interface is under the sspi.raw
interface.
Requirements
- Python 3.8+
More requires are needed to compile the code from scratch but this library is shipped as a wheel so it isn't mandatory for installation.
Installation
Simply run:
pip install sspi
To install from source run the following:
git clone https://github.com/jborean93/pysspi.git
python -m pip install build
python -m build
pip install dist/sspi-*.whl
Development
To run the tests or make changes to this repo run the following:
git clone https://github.com/jborean93/pysspi.git
pip install -r requirements-dev.txt
pre-commit install
python -m pip install -e .
# Can compile the sspi extensions on an adhoc basis
# python setup.py build_ext --inplace
From there an editor like VSCode can be used to make changes and run the test suite.
To recompile the Cython files after a change run the build_ext --inplace
command.
If building on Linux or macOS, a version of libsspi
from sspi-rs must be compiled with rust.
A copy of libicuuc
alongside its headers must be present during compile time.
To compile sspi-rs
, download the git repository and run the following.
cargo build \
--package sspi-ffi \
--release
export LD_LIBRARY_PATH="${PWD}/target/release"
export LIBRARY_PATH="${PWD}/target/release"
Structure
This library is merely a wrapper around the SSPI APIs.
The functions under the sspi
namespace expose the various SSPI functions under a more Pythonic snake_case format.
For example the AcquireCredentialsHandle function is exposed as sspi.acquire_credentials_handle
.
Errors are raised as a WindowsError
which contains the error message as formatted by Windows and the error code.
For non-Windows hosts there is a compatible sspi.WindowsError
class that is structured like the Windows only WindowsError
builtin.
Some of the objects and constants are exposed as Python classes/dataclasses/enums for ease of use.
Please read through the docstring of the function that will be used to learn more about how to use them.
Client Authentication Example
Here is a basic example of how to use this library for client authentication:
import sspi
cred = sspi.UserCredential(
"username@DOMAIN.COM",
"password",
)
ctx = sspi.ClientSecurityContext(
"host/server.domain.com",
credential=cred,
)
in_token = None
while not ctx.complete:
out_token = ctx.step(in_token)
if not out_token:
break
# exchange_with_server() is a function that sends the out_token to the
# server we are authenticating with. How this works depends on the app
# protocol being used, e.g. HTTP, sockets, LDAP, etc.
in_token = exchange_with_server(out_token)
# Once authenticated we can wrap messages when talking to the server. The final
# message being sent is dependent on the application protocol
secret = b"secret data"
wrapped_secret = ctx.wrap(secret)
server_enc_resp = exchange_with_server(wrapped_secret)
server_resp = ctx.unwrap(server_enc_resp).data
The UserCredential
supports more options, like selecting the authentication protocol used.
The ClientSecurityContext
requires the Service Principal Name (SPN) of the target server and optional credentials.
Other options can be used to control the context requested attributes, channel bindings, etc as needed.
How the tokens and wrapped data is sent is dependent on the underlying protocols used, this example just shows when to exchange the data.
Non-Windows Support
While SSPI is a Windows only API, this package ships with manylinux2014_x86_64
, macosx_x86_64
, and macosx_arm64
compatible wheels that use sspi-rs.
Support for this is experimental as all the authentication logic is contained in that external API.
The interface for sspi-rs
is exactly the same as SSPI on Windows so the same code should theoretically be possible.
In saying this, compatibility with SSPI actual is not 100% there so use at your own risk.
It is recommended to use a library that wraps GSSAPI on non-Windows platforms like python-gssapi.
There is no support for any other architectures on Linux except x86_64
and as sspi-rs
only supports glibc it cannot be used with musl based distributions like Alpine.
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 sspi-0.1.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47a34e2fdff261cd13a4dd6c8ec3f19b31a0cd2f00380002495dd17a5826a7ca |
|
MD5 | 59d2202ba9da62beb11fca19d1a33125 |
|
BLAKE2b-256 | 1f06a1525047ab0f4f6b8f058fd0e6a23ded0e207e628e572e2dd842ac838d21 |
Hashes for sspi-0.1.0-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6281f8b3b6a6dc5da0ecd4fcc490cbfad3a891b19bab688fbc01c4e14f6cad77 |
|
MD5 | e5f5b5675fe7dd4c70a26f3c317ab8af |
|
BLAKE2b-256 | c009e92dfa0e5fdea1b9b0bfa463ee0e01bf5226530ae1d4d03a1af936d09779 |
Hashes for sspi-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92aa7ca32f8bf1b9c00e762df94c77dd3b104531e339c2b1aa210c5e7e0303bd |
|
MD5 | ac5f4703ae289be4359f474253f74367 |
|
BLAKE2b-256 | 132d083886775d8d2d44ccfe1b4285aca85c37ee11ed2fe2566e9512e790225a |
Hashes for sspi-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7614d71677047d5dce6bb524db71ffd65b1413230feb6a20acffa009e50b7dc |
|
MD5 | c2b66af4563bcb5f7ba9abb7970ca7b1 |
|
BLAKE2b-256 | e9f32778748140e1562361886c01901dd818e0f9bb254b3053e1845be4694db9 |
Hashes for sspi-0.1.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ce3d4aebb107d1e8eb562c88358688c45fab751fcfa09499623cc7f0f811fa9 |
|
MD5 | 49df40f0f1ae62969a38fee195385a88 |
|
BLAKE2b-256 | 45a7a29a1d7eca5c66cfd8c8bf45a68620ef56d61df01805b28a2c090d8f5180 |
Hashes for sspi-0.1.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7966c48f178bc8753bb9ff1019ed00be1ac9fe87f0d59d0c8e1ac62cbff0d745 |
|
MD5 | 51c13acadec1872ce59be5e8d80f25ac |
|
BLAKE2b-256 | feeec492c1c937b2a5d771156a8321202b5cf0708d26cc8578dc62bef53ba5d3 |
Hashes for sspi-0.1.0-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ebd511d8bfeaaae603638a723186a98ea3a85a816a5e8e3eef745f2350a4deb |
|
MD5 | 269af9d5bfc963bc7408b223ce7b4ddb |
|
BLAKE2b-256 | 7061d1d3201d5e5e39908d6028191ca48afb1273e4ca05ec3a522b0783245413 |
Hashes for sspi-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12c4a89eb64210bbd9d22d1bdf47f2eaee0e444ffe7d2fe6b23c2f713bbcfafa |
|
MD5 | 2c2dfdf00f3ad025c4e2794a4922c0d3 |
|
BLAKE2b-256 | b487bc0eb6cdb22ed0b334dcb5a6691c73c2018ccd3e67124a84664f323edec3 |
Hashes for sspi-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6455215b4f73c2b17b0eadf7ac186b6c7c186c9f3aa0952de598d4f40fd2bdf9 |
|
MD5 | 211a0aeaab59cb335fda7306bfe7db11 |
|
BLAKE2b-256 | 5de95f7425e131ae78642c744e1b6e226b03fadda39e454ecf04dd0b19545d5c |
Hashes for sspi-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 300ee0f315b9ddf6ed9ad8fdfaabb8319a3936c9c6bb1d1d5175d9324dd23767 |
|
MD5 | a002620522ce9d1d046b32b4e3267f18 |
|
BLAKE2b-256 | 2b15be929f8ed5b5efa82550ee176b42838cd3d86a219046e3031aa2ab4efa5c |
Hashes for sspi-0.1.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22d3ae241c4d1bed0c5d979be969f8f2c8bfe5d68323492c39bb28c25267a260 |
|
MD5 | 9d7259e71a8c395752092f96f99e24b9 |
|
BLAKE2b-256 | 2fbdf65a63651c0e9c4ecc836c7db8585efe609d5ddaa0c6292521483e6b1968 |
Hashes for sspi-0.1.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f422c1bab0e11f2f45b9c6b5a3842c500092e736460982406ba6a238ad299cf7 |
|
MD5 | 18db020b227025a8bdb1033c05dea1f2 |
|
BLAKE2b-256 | 3d14fc0e74d7ff10056b1b1038137e35777fe0b433c7058b77b307a17902af26 |
Hashes for sspi-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7b125574ececda40c69034edc3a7dd240dc5634b5a37307f6a881807e8b6665 |
|
MD5 | 8c71689160bd5574df2db7fdc2f0734e |
|
BLAKE2b-256 | 20c6e08b5d4f984a4ff1440b9ba37cd1af9ca049afcae18d52fbbb9df2b47118 |
Hashes for sspi-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 712c6faedd3fa8b64bba5499577be6580e31d67467dc4b6d06dd7ba1bd35d090 |
|
MD5 | d481715edb9cbb746fa5ccb68f793272 |
|
BLAKE2b-256 | 31ed992eaf5116f4c447f0a84a6fcfc0006969e5811b54896b1e6ec4c1b7a30b |
Hashes for sspi-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81eb915068fd8b9db98767f8c8adcc64f2a0b650ca31f077e43f5bb8126453c4 |
|
MD5 | 44828932159e920b8d54de4cf791b3ba |
|
BLAKE2b-256 | 2c8d1130cff8f0a5caaed0073763b1e7597f284e817f1c9c81577e3d1efd4a38 |
Hashes for sspi-0.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3811b30b6020f4002f26d2d7ea200f36e8f6ae2e529c41dfba22f9b124601a0b |
|
MD5 | 724dfe2918516d26e69ed1e54617e220 |
|
BLAKE2b-256 | 71d4097a59e915f770ab7fd5e1f424b9edad5d081b389f34be5b4fe38a88e738 |
Hashes for sspi-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebbb3bbc1f9a9ab2cbe8d09fda41569262b1e83faf3e8506c0806f61d708f35f |
|
MD5 | 22ab3f4b4251c7c828b306e16197a279 |
|
BLAKE2b-256 | 648bb1d312c9844435bf052e3b0e5174d2e6baeba55a428cd5ac87259152f8a1 |
Hashes for sspi-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf723f4b1506b01574d1e87f02aa573bd0f0d36d730c797bf97ef6131ce0fcfe |
|
MD5 | 8c9c67c9f0abc19218a56ed4df8a01be |
|
BLAKE2b-256 | 8f1a692bde68536185cd0f668d609ce4130d4671590e3b8c33f6bae53db03958 |
Hashes for sspi-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef91ce4f816cf3439f2fceee01850c8ca877a82b4c7eeeb68ddddfad4a7c72ea |
|
MD5 | a4127e2bb67ea4cc331888cddf75c1be |
|
BLAKE2b-256 | 9eeeecc1c6cf04452cc30cc29270086152277b01d7d2d06a584cab301079bfbc |
Hashes for sspi-0.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68f403d65f943e850d54396b92c0fbae1f4922bb2dcb1bbd6259adfeae43a0a7 |
|
MD5 | 07f7d102e773ccebf82574a37edf1ac0 |
|
BLAKE2b-256 | ab6ee477f8d98a9018f35ba09d53cd1abf62dc2528120c4a80a478d10a54ab22 |
Hashes for sspi-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e70539618798956a12171287653d67ab4741a082d9d6385de1582bea6380a351 |
|
MD5 | e2bf26b132bf8cdf3e2f98267fa0f42c |
|
BLAKE2b-256 | 7231a4c354e2d222cc2b927fd25b3f3aad2522dcc32e5e01e239935baaf7cfed |
Hashes for sspi-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0e997b5bd01be76cd3a4699b22774ecae0fcba4d30b6ccb7c1b848c975c78b5 |
|
MD5 | d23f9f8d5932a89dc63376897dbd6e8c |
|
BLAKE2b-256 | a690451e72492a60a2a8139658ebe93c30cd88d149d35356c1b5b0c68ef94f8e |
Hashes for sspi-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58655b75c2a8e94a4f8c6f811bbe83bb9da44e6064443abb743bf25163be6da3 |
|
MD5 | 81d711ffcb736ea7195a919f14152ac4 |
|
BLAKE2b-256 | 7a340dc2dc0845d22bbe5ca74ef5aac589ed46bb483db05d7f0346fdbc15ef91 |