{"id":7793,"library":"tlslite-ng","title":"tlslite-ng","description":"tlslite-ng is a pure Python implementation of SSL and TLS protocols, supporting modern standards like TLS 1.3 and various cryptographic algorithms. It aims to provide a flexible and robust solution for secure communication without relying on OpenSSL bindings. The current stable version is 0.8.2, with beta versions (0.9.x) introducing new features.","status":"active","version":"0.8.2","language":"en","source_language":"en","source_url":"https://github.com/tlsfuzzer/tlslite-ng","tags":["tls","ssl","cryptography","network","security","pure-python"],"install":[{"cmd":"pip install tlslite-ng","lang":"bash","label":"Install stable version"},{"cmd":"pip install tlslite-ng==0.9.0b2","lang":"bash","label":"Install latest beta (e.g., for Python 3.6+ or new features)"}],"dependencies":[],"imports":[{"note":"`TLSConnection` and other core classes are exposed via the `tlslite.api` module.","wrong":"from tlslite import TLSConnection","symbol":"TLSConnection","correct":"from tlslite.api import TLSConnection"},{"note":"While `HandshakeSettings` exists in its own module, the recommended way is to import from `tlslite.api` for consistency.","wrong":"from tlslite.handshakesettings import HandshakeSettings","symbol":"HandshakeSettings","correct":"from tlslite.api import HandshakeSettings"}],"quickstart":{"code":"import socket\nfrom tlslite.api import TLSConnection, HandshakeSettings\n\n# Minimal TLS client example connecting to a public HTTPS server\nHOST = 'www.google.com'\nPORT = 443\n\ndef run_client():\n    sock = None\n    connection = None\n    try:\n        # 1. Create a standard socket\n        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n        sock.connect((HOST, PORT))\n        print(f\"Connected to {HOST}:{PORT}\")\n\n        # 2. Wrap the socket with TLSConnection\n        connection = TLSConnection(sock)\n\n        # 3. Perform the TLS handshake as a client\n        settings = HandshakeSettings()\n        settings.minVersion = (3, 3) # TLS 1.2\n        settings.maxVersion = (3, 4) # TLS 1.3\n\n        connection.handshakeClient(\n            settings=settings,\n            reqCert=True # Request server certificate\n        )\n        print(f\"TLS handshake successful. Protocol: {connection.version_name}\")\n\n        # 4. Send and receive application data\n        request = b\"GET / HTTP/1.1\\r\\nHost: www.google.com\\r\\nConnection: close\\r\\n\\r\\n\"\n        connection.write(request)\n        print(\"Sent HTTP GET request.\")\n\n        response = connection.read()\n        print(\"Received data (first 200 bytes):\")\n        print(response[:200].decode(errors='ignore'))\n\n    except Exception as e:\n        print(f\"TLS client failed: {e}\")\n    finally:\n        if connection: # Closes both the TLS connection and underlying socket\n            connection.close()\n        elif sock:\n            sock.close()\n\nif __name__ == '__main__':\n    run_client()\n","lang":"python","description":"This quickstart demonstrates how to establish a TLS client connection to a public HTTPS server using `tlslite-ng`. It covers creating a socket, wrapping it with `TLSConnection`, performing the handshake with specific `HandshakeSettings`, and then sending/receiving application data. It also includes error handling and proper connection closure."},"warnings":[{"fix":"Run your test suite with `-Wd` to identify deprecated calls. Update your code to use the snake_case equivalents (e.g., `handshakeClient` -> `handshake_client`).","message":"Starting with tlslite-ng 0.8.0, `camelCase` method and argument names are deprecated in favor of `underscore_separator` (snake_case) naming conventions. New code should use snake_case, and deprecation warnings will be emitted for camelCase usage.","severity":"deprecated","affected_versions":">=0.8.0"},{"fix":"Ensure your Python environment is 2.6, 2.7, or >=3.6. For Python 3.6+, consider upgrading to `tlslite-ng>=0.9.0b2` for restored 3.6 support.","message":"Version 0.8.0 removed support for Python 3.2, 3.3, 3.4, and 3.5. Users on these Python versions must either remain on `tlslite-ng <0.8.0` or upgrade their Python interpreter.","severity":"breaking","affected_versions":">=0.8.0, <0.9.0b2"},{"fix":"To utilize the latest features, install a beta version (e.g., `pip install tlslite-ng==0.9.0b2`). Be aware that beta versions may be less stable and intended for testing.","message":"New features like Delegated Credentials and ML-DSA certificates, as well as restored Python 3.6 support, are available in the 0.9.0b1/b2 beta releases. They are not present in the current stable 0.8.x series.","severity":"gotcha","affected_versions":"<0.9.0b1"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Update method calls to `underscore_separator` (snake_case) style. For example, change `connection.handshakeClient(...)` to `connection.handshake_client(...)`.","cause":"Using `camelCase` method names that have been deprecated since version 0.8.0.","error":"DeprecationWarning: Call to deprecated function (e.g., handshakeClient): Use handshake_client instead."},{"fix":"Ensure `tlslite-ng` is correctly installed: `pip install tlslite-ng`. Verify your import statement: `from tlslite.api import ...`.","cause":"The `tlslite-ng` package is either not installed, or you are trying to import from an incorrect path (e.g., `tlslite` instead of `tlslite-ng` if you have an older, conflicting package).","error":"ImportError: No module named 'tlslite.api'"},{"fix":"Review the `minVersion` and `maxVersion` in your `HandshakeSettings`. Ensure the versions you specify are supported by the server you are connecting to, and that your `tlslite-ng` library version supports those protocols (e.g., TLS 1.3 requires newer `tlslite-ng`).","cause":"The client and server could not agree on a mutually supported TLS protocol version. This can happen if one side is too old or configured to use only specific versions not supported by the other.","error":"tlslite.errors.TLSError: AlertDescription.protocol_version"}]}