Skip to main content

Adds TLS-PSK support to the Python ssl package

Project description

sslpsk3

PyPI version

This module adds TLS-PSK support to the ssl package in Python 3.7+.

Installation

pip install sslpsk3

pip builds from source for Linux and Mac OSX, so a C compiler, the Python development headers, and the OpenSSL development headers are required. For Microsoft Windows, pre-built binaries are available so there are no such prerequisites.

Usage

The old method of using ssl.wrap_socket(...) is deprecated and not available in Python 3.12+, so the recommended way is SSLContext.

This library introduces a drop-in replacement SSLPSKContext class which supports TLS-PSK.

On Python 3.13 and newer, it uses the native implementation; on older versions, a custom implementation based on OpenSSL is used.

Server code example:

import ssl
from sslpsk3 import SSLPSKContext

context = SSLPSKContext(ssl.PROTOCOL_TLS_SERVER)
context.maximum_version = ssl.TLSVersion.TLSv1_2
context.set_ciphers("PSK")
context.set_psk_server_callback(lambda identity: b"abcdef", identity_hint="server_hint")
sock = context.wrap_socket(...)

Client code example:

import ssl
from sslpsk3 import SSLPSKContext

context = SSLPSKContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
context.maximum_version = ssl.TLSVersion.TLSv1_2
context.set_ciphers("PSK")
context.set_psk_client_callback(lambda hint: ("client_identity", b"abcdef"))
sock = context.wrap_socket(...)

For more information refer to the Python documentation as well as the test_context_simple.py test file.

That being said, this library also still contains a backported version of wrap_context(), which works the same way as in previous versions of sslpsk/sslpsk2/sslpsk3. If possible, please migrate to SSLPSKContext anyway.

Building for Windows

The binary Windows module can be built using FireDaemon OpenSSL Binary Distributions.

OpenSSL 1.x.x and 3.x.x libraries must be extracted to openssl1-win32/64 and openssl3-win32/64 folders respectively. The resulting folder structure should look as follows:

openssl#-win##/
    include/openssl/
        <headers>
    lib/
        libcrypto.lib
        libssl.lib
  1. To build and install the library, use pip install -e . (editable mode).
  2. To build a binary wheel distribution, use poetry build --format=wheel.

In both cases, the resulting PYD (DLL) must be patched using python sslpsk3_fixup.py. This makes sure the libssl3.dll reference is not erroneously using the -x64 suffix.

Backstory

There were two published versions on PyPI, both without Python 3.11 support.

Additionally, for whatever reason, the Windows build of sslpsk2 for Python 3.10 has been linked against OpenSSL 3, while Python 3.10 on Windows uses OpenSSL 1.1.1, which causes run-time crashes (Python started using OpenSSL 3 in 3.11.5).

This fork aims to fix the incompatibility between Python and OpenSSL versions.

Availability of binary wheels for Windows:

sslpsk sslpsk2 sslpsk3
Python 2.7 1.0.0 - -
Python 3.3 1.0.0 - -
Python 3.4 1.0.0 - -
Python 3.5 1.0.0 - -
Python 3.6 1.0.0 - -
Python 3.7 - 1.0.1 2.0.0+
Python 3.8 - 1.0.1 1.1.0+
Python 3.9 - 1.0.1 1.1.0+
Python 3.10 - 1.0.2 1.1.0+
Python 3.11 - - 1.1.0+
Python 3.12 - - 2.0.0+
Python 3.13 - - 2.0.0+
Python 3.14 - - 2.1.0+

Changelog

  • 0.1.0 (July 31, 2017)
    • initial release
  • 1.0.0 (August 2, 2017)
    • include tests in pip distribution
    • add support for Windows
  • 1.0.1 (August 11, 2020)
    • OpenSSL 1.1.1
    • Fix with _sslobj
    • Build from source in Windows with error description, when OpenSSL files are not present
  • 1.1.0 (September 13, 2023)
    • Migrate to GitHub actions
    • Reformat code
    • Support OpenSSL v1 and v3
  • 2.0.0 (September 2, 2025)
    • Rewrite library based on SSLContext
    • Support Python 3.13 and later
    • Add a new test suite
  • 2.1.0 (March 27, 2026)
    • Build for 32-bit Windows
    • Use OpenSSL from FireDaemon

Acknowledgments

Fork of drbild/sslpsk.

The main approach was borrowed from webgravel/common-ssl.

Version from autinerd/sslpsk2 updated to work with OpenSSL v1 and v3.

Updates for SSLContext inspired by a PR created by @doronz88.

Contributing

Please submit bugs, questions, suggestions, or (ideally) contributions as issues and pull requests on GitHub.

License

Copyright 2017 David R. Bild, 2020 Sidney Kuyateh, 2025 Kuba Szczodrzyński

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License from the LICENSE.txt file or at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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

sslpsk3-2.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sslpsk3-2.1.0-cp314-cp314-win_amd64.whl (25.1 kB view details)

Uploaded CPython 3.14Windows x86-64

sslpsk3-2.1.0-cp314-cp314-win32.whl (24.1 kB view details)

Uploaded CPython 3.14Windows x86

sslpsk3-2.1.0-cp313-cp313-win_amd64.whl (24.7 kB view details)

Uploaded CPython 3.13Windows x86-64

sslpsk3-2.1.0-cp313-cp313-win32.whl (23.7 kB view details)

Uploaded CPython 3.13Windows x86

sslpsk3-2.1.0-cp312-cp312-win_amd64.whl (24.7 kB view details)

Uploaded CPython 3.12Windows x86-64

sslpsk3-2.1.0-cp312-cp312-win32.whl (23.7 kB view details)

Uploaded CPython 3.12Windows x86

sslpsk3-2.1.0-cp311-cp311-win_amd64.whl (24.6 kB view details)

Uploaded CPython 3.11Windows x86-64

sslpsk3-2.1.0-cp311-cp311-win32.whl (23.7 kB view details)

Uploaded CPython 3.11Windows x86

sslpsk3-2.1.0-cp310-cp310-win_amd64.whl (24.6 kB view details)

Uploaded CPython 3.10Windows x86-64

sslpsk3-2.1.0-cp310-cp310-win32.whl (23.7 kB view details)

Uploaded CPython 3.10Windows x86

sslpsk3-2.1.0-cp39-cp39-win_amd64.whl (24.6 kB view details)

Uploaded CPython 3.9Windows x86-64

sslpsk3-2.1.0-cp39-cp39-win32.whl (23.7 kB view details)

Uploaded CPython 3.9Windows x86

sslpsk3-2.1.0-cp38-cp38-win_amd64.whl (24.4 kB view details)

Uploaded CPython 3.8Windows x86-64

sslpsk3-2.1.0-cp38-cp38-win32.whl (23.5 kB view details)

Uploaded CPython 3.8Windows x86

sslpsk3-2.1.0-cp37-cp37m-win_amd64.whl (23.9 kB view details)

Uploaded CPython 3.7mWindows x86-64

sslpsk3-2.1.0-cp37-cp37m-win32.whl (22.9 kB view details)

Uploaded CPython 3.7mWindows x86

File details

Details for the file sslpsk3-2.1.0.tar.gz.

File metadata

  • Download URL: sslpsk3-2.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0.tar.gz
Algorithm Hash digest
SHA256 ac06ad206f1a503da63d50528d4e47cb9c01f52dc90ffccc6326d0e5f55692eb
MD5 5a52b4ee5499abe3571aae625ca8ce07
BLAKE2b-256 6cf32c353fe0a46d2d5a89c44f125cc656863d86e485cf36ece3891b2125dc83

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 f248f716a2e7b532b778a265547a2e0e92e1f584fb3d4b3c772eac57381bdbdc
MD5 e666d753d4250b2fa8d4ee6cfd8813ed
BLAKE2b-256 8fe3e7cc405f0ee535430f2465dda86ba05facc6684621a311c38bc3d1131b3f

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp314-cp314-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp314-cp314-win32.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: CPython 3.14, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 082824177f3a6c041475744baade5ffcad2e18d90ac53c7a677debb9a7981116
MD5 17a32a078eecbd5014d6763d55e3ca23
BLAKE2b-256 f9ec8b773cc07b439de85d420d81f5f0bd6884b269529717edcda8063801ce0f

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6cc31b9bc56362e16f399130d430b8ae91949bf165bdab1900aa4bf15d1098a4
MD5 c45c8678a705c0a6d4565cb0dcd6b0cb
BLAKE2b-256 ac76134f44c0957b7175df80d4c8f2bb59c9e7b015bb96d643faece7f52f0783

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp313-cp313-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp313-cp313-win32.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 a36be39d218343bc43cfe0c129ac98a7f2b6af42009213135e299a55b2f2ba2a
MD5 3e8b0a468afaa2baa84ae419347bce35
BLAKE2b-256 edc4f0c2e5af647625fec9f4943ca163474f37bf297b60a607194fff90909208

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 17a4b4d56d11572640ff7c651f18c741bf0f09defed738204dc390a7698dbf00
MD5 c770a719d321b642ed34556c2531c845
BLAKE2b-256 c0769170067f32d719a8359f7acf45d410e0f55cdf0cb63c56ff39b443ee401a

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp312-cp312-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp312-cp312-win32.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 c31575d7274e16e712bb9cce868acde47f6de90b0f2fc8f5ae0fd5475753860d
MD5 31e192fb3a261162ceae6b7ddae65138
BLAKE2b-256 596f753886714ec9c214367a02abeca377aefe26dde9410119f8632a1672cec4

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 150bd2da479146650b1a382f73ce69c34ac9fe529bd963fcdcba56ef2f6241a9
MD5 c1f5a0ff52fdee75c76c7432603b390f
BLAKE2b-256 e0f2b12dfaab095c9be3e89ec65521f8ba503d6519e8cb33d3a16925e3a16584

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp311-cp311-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 6d510b69236a22a5ded23f44d98501d3a853e3b8c2b9a7ccd9bfec36ffc2a8ac
MD5 c175a699e331468cb4789d6ee1d499e1
BLAKE2b-256 e1b199a089eb32b3cbf7dde4bbf044471e84d41510e0be856c4026d11e6aae11

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9dbe128765c56d54bb6d136f0a4f23eccc8edb2f4f25dd08b4e6fc52ee52a9fb
MD5 97d9e5f6a959bb3bc9409da777432268
BLAKE2b-256 9290ad27cb7ffe0fbf6c53f044e5cb368d0b9d566720bf8bcb891ae83f5a65ea

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 cedc2be9e9b5f96bd638c731bbd13c03fbaf71d1ca4cad163e69a089e1f098bf
MD5 be750d0bf647fc9d44cf65413c6c985c
BLAKE2b-256 0e5434a768c7637b486010fadaf85dce0e3fa8c9056e396a60747d2fa4d63678

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 085c7a06322bc2801432c1ea89e8aad4630c55b3fce7fbfbfe06b00fe568d3cd
MD5 aaa14781c40a4dc895c3f70d9d1ee357
BLAKE2b-256 13f143a00587d818ebce4a91da6bb483bfce9d1e540b203308a500d53933c73f

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 4938d8c6bcf00f72aaa0ced989f7a50de3edc4b53f987dd9828725101d9c6169
MD5 f68e31738be807504bd066cac00cc49f
BLAKE2b-256 da9a91dee10c42d6fcda8e777938b2a6ba5e3d88e39a85e2f92b6d3f8d05f394

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 833d60459fba2e34f8437a871cf86d4afe85c46d99155c2c7c4687c974b9fe04
MD5 64f1ee369110bbf073d999b17b9a2840
BLAKE2b-256 ffab29527f16294d18278dc424828028205b19bfadd768413a687f4dc286c5b3

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp38-cp38-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 d8bbbb6e5e8a9eec0ba8be494392f49c94a2f0fe425a59c66839f7949f978e16
MD5 47e07a13d10ba1df6e790e38a7ba119f
BLAKE2b-256 a1d50a0a1d497602b19f73b5b05b64dde52ad2ecba01590ee99921605281583a

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 df51dcab59afb18d9b6be7c34742ab15c527c07a60aacbe9478285f3d1e79363
MD5 50085f15472edb803bdd1031d764dcaa
BLAKE2b-256 596cc64979b9870f0716debd608e16944750f00be6aa0f8e3baafa154f8aaeda

See more details on using hashes here.

File details

Details for the file sslpsk3-2.1.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: sslpsk3-2.1.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.17.0-1008-azure

File hashes

Hashes for sslpsk3-2.1.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 84983d3d9c36077b49b7d71b30cc4430367b811f51378862d4893580817ed51d
MD5 2a5dfa795673987970d584812eda3c04
BLAKE2b-256 fd40366cfb03816442754e0079466d9edb76f48313e9bb19d7b2d646ea32b3f8

See more details on using hashes here.

Supported by

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