{"id":450,"library":"pyopenssl","title":"PyOpenSSL","description":"PyOpenSSL is a Python wrapper around the OpenSSL library, providing a high-level interface for cryptographic operations. The current version is 26.0.0, with releases following a regular cadence to incorporate updates and fixes.","status":"active","version":"26.0.0","language":"python","source_language":"en","source_url":"https://github.com/pyca/pyopenssl","tags":["cryptography","OpenSSL","security","Python"],"install":[{"cmd":"pip install pyopenssl","lang":"bash","label":"Install PyOpenSSL"}],"dependencies":[{"reason":"Provides cryptographic recipes and primitives; required for PyOpenSSL to function properly.","package":"cryptography"}],"imports":[{"note":"Ensure correct import path to access cryptographic functionalities.","symbol":"OpenSSL.crypto","correct":"from OpenSSL import crypto"}],"quickstart":{"code":"from OpenSSL import crypto\n\n# Generate a new RSA key pair\nkey = crypto.PKey()\nkey.generate_key(crypto.TYPE_RSA, 2048)\n\n# Create a self-signed certificate\ncert = crypto.X509()\ncert.set_version(2)\ncert.set_serial_number(1000)\ncert.get_subject().CN = 'example.com'\ncert.set_issuer(cert.get_subject())\ncert.set_pubkey(key)\ncert.sign(key, 'sha256')\n\n# Save the private key and certificate to files\nwith open('private_key.pem', 'wb') as key_file:\n    key_file.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, key))\n\nwith open('certificate.pem', 'wb') as cert_file:\n    cert_file.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))\n\nprint('Private key and certificate have been generated and saved.')","lang":"python","description":"This script demonstrates how to generate a new RSA key pair and create a self-signed certificate using PyOpenSSL."},"warnings":[{"fix":"Upgrade PyOpenSSL to a version compatible with cryptography 39.0.0 or later.","message":"PyOpenSSL version 23.0.0 is incompatible with cryptography version 39.0.0 due to the removal of the 'x509' module.","severity":"breaking","affected_versions":"23.0.0"},{"fix":"Use alternative methods for handling PKCS12 files.","message":"The 'load_pkcs12' function in PyOpenSSL is deprecated and may be removed in future versions.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T13:53:44.822Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"pip install pyopenssl","cause":"The pyopenssl library (which provides the OpenSSL package) is not installed or not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'OpenSSL'"},{"fix":"Ensure the certificate or key data is correctly formatted as PEM, starting with `-----BEGIN...` and ending with `-----END...`.","cause":"The file or data provided for loading a certificate or private key does not contain valid PEM-encoded data, missing the expected 'BEGIN' line.","error":"OpenSSL.SSL.Error: [('PEM routines', 'PEM_read_bio', 'no start line')]"},{"fix":"Encode the certificate/key string to bytes before passing it:\n```python\ncert_string = \"...\"\ncert_bytes = cert_string.encode('utf-8')\ncert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert_bytes)\n```","cause":"Functions like `OpenSSL.crypto.load_certificate` expect byte strings for certificate/key data, but a regular string was provided.","error":"TypeError: argument of type 'str' is not iterable"},{"fix":"Use the generic `TLS_METHOD` and then set the minimum/maximum protocol versions on the context:\n```python\ncontext = OpenSSL.SSL.Context(OpenSSL.SSL.TLS_METHOD)\ncontext.set_min_proto_version(OpenSSL.SSL.TLS1_2_VERSION)\ncontext.set_max_proto_version(OpenSSL.SSL.TLS1_2_VERSION)\n```","cause":"Direct protocol methods like `TLSv1_2_METHOD` are deprecated in newer pyopenssl versions; use `TLS_METHOD` with explicit version settings.","error":"AttributeError: module 'OpenSSL.SSL' has no attribute 'TLSv1_2_METHOD'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.32,"mem_mb":8,"disk_size":"33.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.22,"mem_mb":8,"disk_size":"34M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.69,"mem_mb":9.1,"disk_size":"36.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.55,"mem_mb":9.1,"disk_size":"37M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.74,"mem_mb":12.1,"disk_size":"28.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.75,"mem_mb":12.1,"disk_size":"28M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.36,"mem_mb":6.2,"disk_size":"27.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.38,"mem_mb":6.2,"disk_size":"28M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.3,"mem_mb":8.1,"disk_size":"33.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.3,"mem_mb":8.1,"disk_size":"34M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}