├── .checkignore ├── .codeclimate.yml ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .landscape.yaml ├── .pep257 ├── .readthedocs.yaml ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README ├── README.md ├── SECURITY.md ├── build-requirements-2.6.txt ├── build-requirements-2.7.txt ├── build-requirements-3.3.txt ├── build-requirements-3.4.txt ├── build-requirements.txt ├── docs ├── Makefile ├── conf.py ├── index.rst ├── make.bat ├── modules.rst ├── requirements.txt ├── tlslite.api.rst ├── tlslite.basedb.rst ├── tlslite.bufferedsocket.rst ├── tlslite.checker.rst ├── tlslite.constants.rst ├── tlslite.defragmenter.rst ├── tlslite.dh.rst ├── tlslite.errors.rst ├── tlslite.extensions.rst ├── tlslite.handshakehashes.rst ├── tlslite.handshakehelpers.rst ├── tlslite.handshakesettings.rst ├── tlslite.integration.asyncstatemachine.rst ├── tlslite.integration.clienthelper.rst ├── tlslite.integration.httptlsconnection.rst ├── tlslite.integration.imap4_tls.rst ├── tlslite.integration.pop3_tls.rst ├── tlslite.integration.rst ├── tlslite.integration.smtp_tls.rst ├── tlslite.integration.tlsasyncdispatchermixin.rst ├── tlslite.integration.tlsasynciodispatchermixin ├── tlslite.integration.tlssocketservermixin.rst ├── tlslite.integration.xmlrpcserver.rst ├── tlslite.integration.xmlrpctransport.rst ├── tlslite.keyexchange.rst ├── tlslite.mathtls.rst ├── tlslite.messages.rst ├── tlslite.messagesocket.rst ├── tlslite.recordlayer.rst ├── tlslite.rst ├── tlslite.session.rst ├── tlslite.sessioncache.rst ├── tlslite.tlsconnection.rst ├── tlslite.tlsrecordlayer.rst ├── tlslite.utils.aes.rst ├── tlslite.utils.aesgcm.rst ├── tlslite.utils.asn1parser.rst ├── tlslite.utils.chacha.rst ├── tlslite.utils.chacha20_poly1305.rst ├── tlslite.utils.cipherfactory.rst ├── tlslite.utils.codec.rst ├── tlslite.utils.compat.rst ├── tlslite.utils.constanttime.rst ├── tlslite.utils.cryptomath.rst ├── tlslite.utils.datefuncs.rst ├── tlslite.utils.deprecations.rst ├── tlslite.utils.dns_utils.rst ├── tlslite.utils.ecc.rst ├── tlslite.utils.ecdsakey.rst ├── tlslite.utils.keyfactory.rst ├── tlslite.utils.lists.rst ├── tlslite.utils.openssl_aes.rst ├── tlslite.utils.openssl_rc4.rst ├── tlslite.utils.openssl_rsakey.rst ├── tlslite.utils.openssl_tripledes.rst ├── tlslite.utils.pem.rst ├── tlslite.utils.poly1305.rst ├── tlslite.utils.pycrypto_aes.rst ├── tlslite.utils.pycrypto_aesgcm.rst ├── tlslite.utils.pycrypto_rc4.rst ├── tlslite.utils.pycrypto_rsakey.rst ├── tlslite.utils.pycrypto_tripledes.rst ├── tlslite.utils.python_aes.rst ├── tlslite.utils.python_aesgcm.rst ├── tlslite.utils.python_chacha20_poly1305.rst ├── tlslite.utils.python_rc4.rst ├── tlslite.utils.python_rsakey.rst ├── tlslite.utils.rc4.rst ├── tlslite.utils.rijndael.rst ├── tlslite.utils.rsakey.rst ├── tlslite.utils.rst ├── tlslite.utils.tackwrapper.rst ├── tlslite.utils.tlshashlib.rst ├── tlslite.utils.tripledes.rst ├── tlslite.utils.x25519.rst ├── tlslite.verifierdb.rst ├── tlslite.x509.rst └── tlslite.x509certchain.rst ├── pylintrc ├── requirements.txt ├── scripts ├── speed.py ├── tls.py └── tlsdb.py ├── setup.py ├── tests ├── TACK1.pem ├── TACK2.pem ├── TACK_Key1.pem ├── TACK_Key2.pem ├── TACKs.pem ├── TACKunrelated.pem ├── clientDSACert.pem ├── clientDSAKey.pem ├── clientECCert.pem ├── clientECKey.pem ├── clientEd25519Cert.pem ├── clientEd25519Key.pem ├── clientX509Cert.pem ├── clientX509Key.pem ├── httpsclient.py ├── httpsserver.sh ├── index.html ├── serverBrainpoolP256r1ECCert.pem ├── serverBrainpoolP256r1ECKey.pem ├── serverBrainpoolP384r1ECCert.pem ├── serverBrainpoolP384r1ECKey.pem ├── serverBrainpoolP512r1ECCert.pem ├── serverBrainpoolP512r1ECKey.pem ├── serverDSACert.pem ├── serverDSAKey.pem ├── serverECCert.pem ├── serverECDSANonCACert.pem ├── serverECDSANonCAKey.pem ├── serverECKey.pem ├── serverEd25519Cert.pem ├── serverEd25519Key.pem ├── serverEd448Cert.pem ├── serverEd448Key.pem ├── serverP384ECCert.pem ├── serverP384ECKey.pem ├── serverP521ECCert.pem ├── serverP521ECKey.pem ├── serverRSANonCACert.pem ├── serverRSANonCAKey.pem ├── serverRSAPSSCert.pem ├── serverRSAPSSKey.pem ├── serverRSAPSSSigCert.pem ├── serverRSAPSSSigKey.pem ├── serverX509Cert.pem ├── serverX509Key.pem ├── tlstest.py └── verifierDB ├── tlslite ├── __init__.py ├── api.py ├── basedb.py ├── bufferedsocket.py ├── checker.py ├── constants.py ├── defragmenter.py ├── dh.py ├── errors.py ├── extensions.py ├── handshakehashes.py ├── handshakehelpers.py ├── handshakesettings.py ├── integration │ ├── __init__.py │ ├── asyncstatemachine.py │ ├── clienthelper.py │ ├── httptlsconnection.py │ ├── imap4_tls.py │ ├── pop3_tls.py │ ├── smtp_tls.py │ ├── tlsasyncdispatchermixin.py │ ├── tlsasynciodispatchermixin.py │ ├── tlssocketservermixin.py │ ├── xmlrpcserver.py │ └── xmlrpctransport.py ├── keyexchange.py ├── mathtls.py ├── messages.py ├── messagesocket.py ├── ocsp.py ├── recordlayer.py ├── session.py ├── sessioncache.py ├── signed.py ├── tlsconnection.py ├── tlsrecordlayer.py ├── utils │ ├── __init__.py │ ├── aes.py │ ├── aesccm.py │ ├── aesgcm.py │ ├── asn1parser.py │ ├── brotlidecpy │ │ ├── LICENCE │ │ ├── __init__.py │ │ ├── bit_reader.py │ │ ├── brotli-dict │ │ ├── context.py │ │ ├── decode.py │ │ ├── dictionary.py │ │ ├── huffman.py │ │ ├── prefix.py │ │ └── transform.py │ ├── chacha.py │ ├── chacha20_poly1305.py │ ├── cipherfactory.py │ ├── codec.py │ ├── compat.py │ ├── compression.py │ ├── constanttime.py │ ├── cryptomath.py │ ├── datefuncs.py │ ├── deprecations.py │ ├── dns_utils.py │ ├── dsakey.py │ ├── ecc.py │ ├── ecdsakey.py │ ├── eddsakey.py │ ├── format_output.py │ ├── keyfactory.py │ ├── lists.py │ ├── openssl_aes.py │ ├── openssl_aesccm.py │ ├── openssl_aesgcm.py │ ├── openssl_rc4.py │ ├── openssl_rsakey.py │ ├── openssl_tripledes.py │ ├── pem.py │ ├── poly1305.py │ ├── pycrypto_aes.py │ ├── pycrypto_aesgcm.py │ ├── pycrypto_rc4.py │ ├── pycrypto_rsakey.py │ ├── pycrypto_tripledes.py │ ├── python_aes.py │ ├── python_aesccm.py │ ├── python_aesgcm.py │ ├── python_chacha20_poly1305.py │ ├── python_dsakey.py │ ├── python_ecdsakey.py │ ├── python_eddsakey.py │ ├── python_key.py │ ├── python_rc4.py │ ├── python_rsakey.py │ ├── python_tripledes.py │ ├── rc4.py │ ├── rijndael.py │ ├── rsakey.py │ ├── tackwrapper.py │ ├── tlshashlib.py │ ├── tlshmac.py │ ├── tripledes.py │ └── x25519.py ├── verifierdb.py ├── x509.py └── x509certchain.py └── unit_tests ├── __init__.py ├── mocksock.py ├── test_tls1_3_vectors.py ├── test_tlslite_bufferedsocket.py ├── test_tlslite_constants.py ├── test_tlslite_defragmenter.py ├── test_tlslite_dh.py ├── test_tlslite_extensions.py ├── test_tlslite_handshakehashes.py ├── test_tlslite_handshakehelpers.py ├── test_tlslite_handshakesettings.py ├── test_tlslite_integration_tlsasynciodispatchermixin.py ├── test_tlslite_keyexchange.py ├── test_tlslite_mathtls.py ├── test_tlslite_messages.py ├── test_tlslite_messagesocket.py ├── test_tlslite_ocsp.py ├── test_tlslite_recordlayer.py ├── test_tlslite_session.py ├── test_tlslite_sessioncache.py ├── test_tlslite_signed.py ├── test_tlslite_tlsconnection.py ├── test_tlslite_tlsrecordlayer.py ├── test_tlslite_utils_aes_split.py ├── test_tlslite_utils_aescbc.py ├── test_tlslite_utils_aesccm.py ├── test_tlslite_utils_aesctr.py ├── test_tlslite_utils_aesgcm.py ├── test_tlslite_utils_asn1.py ├── test_tlslite_utils_chacha.py ├── test_tlslite_utils_chacha20_poly1305.py ├── test_tlslite_utils_codec.py ├── test_tlslite_utils_compat.py ├── test_tlslite_utils_compression.py ├── test_tlslite_utils_constanttime.py ├── test_tlslite_utils_cryptomath.py ├── test_tlslite_utils_cryptomath_m2crypto.py ├── test_tlslite_utils_deprecations.py ├── test_tlslite_utils_dns_utils.py ├── test_tlslite_utils_ecc.py ├── test_tlslite_utils_ecdsakey.py ├── test_tlslite_utils_keyfactory.py ├── test_tlslite_utils_lists.py ├── test_tlslite_utils_poly1305.py ├── test_tlslite_utils_python_dsakey.py ├── test_tlslite_utils_python_ecdsakey.py ├── test_tlslite_utils_python_key.py ├── test_tlslite_utils_rijndael.py ├── test_tlslite_utils_rsakey.py ├── test_tlslite_utils_tlshashlib.py ├── test_tlslite_utils_tripledes.py ├── test_tlslite_utils_tripledes_split.py ├── test_tlslite_utils_x25519.py └── test_tlslite_x509.py /.checkignore: -------------------------------------------------------------------------------- 1 | scripts/** 2 | tests/** 3 | unit_tests/** 4 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | engines: 2 | radon: 3 | enabled: true 4 | config: 5 | threshold: "C" 6 | pep8: 7 | enabled: true 8 | duplication: 9 | enabled: true 10 | exclude_fingerprints: 11 | # duplication in tlslite/utils/codec.py Writer.addTwo() .addFour() 12 | - 2e783666ce368f4223c1e7f5b162e2d9 13 | - 2c398389f33ea2572edefc5370ed49c0 14 | config: 15 | languages: 16 | python: 17 | python_version: 3 18 | mass_threshold: 35 19 | fixme: 20 | enabled: true 21 | config: 22 | strings: 23 | - TODO 24 | - FIXME 25 | - HACK 26 | - BUG 27 | checks: 28 | bug: 29 | enabled: true 30 | markdownlint: 31 | enabled: true 32 | ratings: 33 | paths: 34 | - "tlslite/**" 35 | - "**.py" 36 | exclude_paths: 37 | - "tests/**/*" 38 | - "scripts/**/*" 39 | - "unit_tests/**/*" 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *venv* 2 | *.pyc 3 | .project 4 | .pydevproject 5 | .settings 6 | .coverage 7 | .hypothesis 8 | coverage.xml 9 | pylint_report.txt 10 | build/ 11 | docs/_build/ 12 | htmlcov/ -------------------------------------------------------------------------------- /.landscape.yaml: -------------------------------------------------------------------------------- 1 | doc-warnings: true 2 | 3 | test-warnings: false 4 | 5 | strictness: medium 6 | 7 | max-line-length: 80 8 | 9 | ignore-paths: 10 | - tests 11 | - unit_tests 12 | - scripts 13 | 14 | pep257: 15 | disable: 16 | - D203 17 | -------------------------------------------------------------------------------- /.pep257: -------------------------------------------------------------------------------- 1 | [pep257] 2 | 3 | add-ignore = D203 4 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the version of Python and other tools you might need 9 | build: 10 | os: ubuntu-22.04 11 | tools: 12 | python: "3.11" 13 | 14 | # Build documentation in the docs/ directory with Sphinx 15 | sphinx: 16 | configuration: docs/conf.py 17 | 18 | # We recommend specifying your dependencies to enable reproducible builds: 19 | # https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 20 | python: 21 | install: 22 | - requirements: requirements.txt 23 | - requirements: docs/requirements.txt 24 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include tests * 2 | recursive-include docs/_build/html * 3 | include LICENSE 4 | include README 5 | include Makefile 6 | include MANIFEST.in 7 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | tlslite-ng is a pure python implementation of SSLv3.0, TLS 1.0, TLS 1.1, 2 | TLS 1.2 and TLS 1.3 protocols. 3 | 4 | It can use pycrypto, m2crypto and gmp for acceleration of cryptographic 5 | operations but is not dependant upon them. 6 | 7 | Functionality implemented include: 8 | - all above mentioned protocols, including support for client certificates 9 | (RFC 6101, RFC 2246, RFC 4346, RFC 5246, RFC 8446 - not complete) 10 | - RSA, RSA-PSS, DSA, and ECDSA certificates 11 | - RC4, 3DES-CBC, AES-CBC, AES-GCM, AES-CCM, AES-CCM_8 and ChaCha20 ciphers 12 | (RFC 5246, RFC 6347, RFC 4492, RFC 5288, RFC 5289, RFC 7539, RFC 7905, 13 | RFC 6655, RFC 7251) 14 | - MD5, SHA1, SHA256 and SHA384 HMACs as well as AEAD mode of operation with 15 | GCM or Poly1305 authenticator 16 | - RSA, DHE_RSA, DHE_DSS, ECDHE_RSA, ECDHE_ECDSA key exchange 17 | - full set of signature hashes (md5, sha1, sha224, sha256, sha384, sha512, 18 | rsa_pss_rsae_sha256, rsa_pss_rsae_sha384 and rsa_pss_rsae_sha512) for 19 | ServerKeyExchange and CertfificateVerify 20 | - secp256r1, secp384r1, secp521r1, secp256k1, secp224r1 and secp192r1 curves 21 | for ECDHE key exchange (support for last two depends on the version of ecdsa 22 | library used) 23 | - x25519 and x448 curves for ECDHE key exchage (RFC 7748. RFC 4492bis) 24 | - anonymous DHE key exchange 25 | - anonymous ECDH key exchange 26 | - PSK and PSK-DH key exchange in TLS 1.3 27 | - session ticket based resumption (RFC 5077) and in TLS 1.3 28 | - post-handshake client authentication in TLS 1.3 29 | - NULL encryption ciphersuites 30 | - FALLBACK_SCSV (RFC 7507) 31 | - encrypt-then-MAC mode of operation for CBC ciphersuites (RFC 7366) 32 | - TACK certificate pinning 33 | - SRP_SHA_RSA and SRP_SHA ciphersuites (RFC 5054) 34 | - Extended Master Secret calculation for TLS connections (RFC 7627) 35 | - padding extension (RFC 7685) 36 | - Keying material exporter (RFC 5705) 37 | - Next Protocol Negotiation 38 | - Application-Layer Protocol Negotiation Extension (RFC 7301) 39 | - FFDHE prime/group negotiation (RFC 7919) 40 | - Heartbeat Extension (RFC 6520) 41 | - Record Size Limit (RFC 8449) 42 | - TLS Certificate Compression (RFC 8879) 43 | - Hybrid ML-KEM key exchage groups (draft-kwiatkowski-tls-ecdhe-mlkem-02) 44 | - support for Brainpool curves in TLS 1.2 and TLS 1.3 45 | 46 | 47 | tlslite-ng aims to be a drop-in replacement for tlslite while providing more 48 | comprehensive set of features and more secure defaults. 49 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | tlslite-ng received little-to-none 3rd party security review. 4 | 5 | tlslite-ng **CANNOT** verify certificates – users of the library must use 6 | external means to check if certificate of the peer is the expected one. 7 | 8 | Because python execution environment uses hash tables to store variables (that 9 | includes functions, objects and classes) it's very hard to create 10 | implementations that are timing attack resistant. Additionally, all integers 11 | use arbitrary precision arithmentic, so binary operations are data dependant 12 | (see Hubert Kario 13 | [blog post](https://securitypitfalls.wordpress.com/2018/08/03/constant-time-compare-in-python/) 14 | on this topic). This means that CBC MAC-then-encrypt de-padding leaks timing 15 | information and all pure python cipher implementations will leak timing 16 | information. None of the included cipher implementations are written in a way 17 | that even tries to hide the data dependance. 18 | 19 | In other words, pure-python (tlslite-ng internal) implementations of all 20 | ciphers, as well as all CBC mode ciphers working in MAC-then-encrypt mode are 21 | **NOT** secure. Don't use them. In addition to that, use AEAD ciphersuites 22 | (AES-GCM) or encrypt-then-MAC mode for CBC ciphers. 23 | 24 | (Note: PyCrypto aes-gcm cipher is also not secure as it uses Python to 25 | calculate GCM tag, see issue 26 | [#301](https://github.com/tlsfuzzer/tlslite-ng/issues/301)) 27 | 28 | ## Supported Versions 29 | 30 | Only the current stable release is considered supported (will have fixes to 31 | security issues backported and new patches will trigger a new release). 32 | 33 | | Version | Supported | 34 | | ------- | ------------------ | 35 | | 0.8.0-alpha | :x: | 36 | | 0.7.x | :white_check_mark: | 37 | | < 0.7 | :x: | 38 | 39 | ## Reporting a Vulnerability 40 | 41 | Security issues can be reported by sending an email to hkario@redhat.com. 42 | Answer to the initial email can be expected in 2 work-days. 43 | 44 | If an issue is recognised as a vulnerability, fixes for it will be developed 45 | on a good faith basis. 46 | 47 | Unless otherwise agreed to, we'd like to request the reporter to keep the 48 | vulnerability confidential for the industry-accepted period for responsible 49 | disclosure of 90 days. The period will be cut short if the fix is released 50 | earlier. 51 | -------------------------------------------------------------------------------- /build-requirements-2.6.txt: -------------------------------------------------------------------------------- 1 | isort<4.3 2 | inflect<0.3.1 3 | pyopenssl<18 4 | cffi<1.14 5 | unittest2 6 | coverage 7 | hypothesis<3 8 | git+https://github.com/tomato42/coveralls-python.git@add-py26#egg=coveralls 9 | pylint 10 | diff_cover 11 | pycparser<2.19 12 | idna<2.8 13 | mock==2.0.0 14 | -------------------------------------------------------------------------------- /build-requirements-2.7.txt: -------------------------------------------------------------------------------- 1 | unittest2 2 | coverage 3 | hypothesis 4 | git+https://github.com/tomato42/coveralls-python.git@add-py26#egg=coveralls 5 | pylint 6 | mock 7 | diff_cover<2.5.0 8 | pytest>=4.6.5 9 | -------------------------------------------------------------------------------- /build-requirements-3.3.txt: -------------------------------------------------------------------------------- 1 | six>=1.10.0 2 | enum34 3 | coverage<5.0 4 | hypothesis<3.44 5 | git+https://github.com/tomato42/coveralls-python.git@add-py26#egg=coveralls 6 | wrapt<1.13.0 7 | pylint<2.12.2 8 | diff_cover<2.5.0 9 | typed-ast<1.3.0 10 | inflect<4.0.0 11 | typing<3.7.4 12 | isort==4.2.5 13 | -------------------------------------------------------------------------------- /build-requirements-3.4.txt: -------------------------------------------------------------------------------- 1 | coverage 2 | hypothesis 3 | git+https://github.com/tomato42/coveralls-python.git@add-py26#egg=coveralls 4 | pylint 5 | diff_cover 6 | pytest>=4.6.5 7 | pluggy>=0.7 8 | -------------------------------------------------------------------------------- /build-requirements.txt: -------------------------------------------------------------------------------- 1 | coverage 2 | hypothesis 3 | coveralls 4 | pylint<2.10 5 | diff_cover 6 | pytest>=4.6.5 7 | pluggy>=0.7 8 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. tlslite-ng documentation master file, created by 2 | sphinx-quickstart on Thu Jul 20 13:51:42 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to tlslite-ng's documentation! 7 | ====================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | modules 15 | 16 | Indices and tables 17 | ================== 18 | 19 | * :ref:`genindex` 20 | * :ref:`modindex` 21 | * :ref:`search` 22 | 23 | -------------------------------------------------------------------------------- /docs/modules.rst: -------------------------------------------------------------------------------- 1 | tlslite 2 | ======= 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | tlslite 8 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx-rtd-theme 2 | -------------------------------------------------------------------------------- /docs/tlslite.api.rst: -------------------------------------------------------------------------------- 1 | tlslite.api module 2 | ================== 3 | 4 | .. automodule:: tlslite.api 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.basedb.rst: -------------------------------------------------------------------------------- 1 | tlslite.basedb module 2 | ===================== 3 | 4 | .. automodule:: tlslite.basedb 5 | :members: 6 | :special-members: __contains__, __delitem__, __getitem__, __init__, 7 | __setitem__ 8 | :undoc-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /docs/tlslite.bufferedsocket.rst: -------------------------------------------------------------------------------- 1 | tlslite.bufferedsocket module 2 | ============================= 3 | 4 | .. automodule:: tlslite.bufferedsocket 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.checker.rst: -------------------------------------------------------------------------------- 1 | tlslite.checker module 2 | ====================== 3 | 4 | .. automodule:: tlslite.checker 5 | :members: 6 | :special-members: __init__, __call__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.constants.rst: -------------------------------------------------------------------------------- 1 | tlslite.constants module 2 | ======================== 3 | 4 | .. automodule:: tlslite.constants 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/tlslite.defragmenter.rst: -------------------------------------------------------------------------------- 1 | tlslite.defragmenter module 2 | =========================== 3 | 4 | .. automodule:: tlslite.defragmenter 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.dh.rst: -------------------------------------------------------------------------------- 1 | tlslite.dh module 2 | ================= 3 | 4 | .. automodule:: tlslite.dh 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.errors.rst: -------------------------------------------------------------------------------- 1 | tlslite.errors module 2 | ===================== 3 | 4 | .. automodule:: tlslite.errors 5 | :members: 6 | :special-members: __init__, __str__, __repr__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.extensions.rst: -------------------------------------------------------------------------------- 1 | tlslite.extensions module 2 | ========================= 3 | 4 | .. automodule:: tlslite.extensions 5 | :members: 6 | :special-members: __init__, __repr__, __str__, __eq__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.handshakehashes.rst: -------------------------------------------------------------------------------- 1 | tlslite.handshakehashes module 2 | ============================== 3 | 4 | .. automodule:: tlslite.handshakehashes 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.handshakehelpers.rst: -------------------------------------------------------------------------------- 1 | tlslite.handshakehelpers module 2 | =============================== 3 | 4 | .. automodule:: tlslite.handshakehelpers 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/tlslite.handshakesettings.rst: -------------------------------------------------------------------------------- 1 | tlslite.handshakesettings module 2 | ================================ 3 | 4 | .. automodule:: tlslite.handshakesettings 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.asyncstatemachine.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.asyncstatemachine module 2 | ============================================ 3 | 4 | .. automodule:: tlslite.integration.asyncstatemachine 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.clienthelper.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.clienthelper module 2 | ======================================= 3 | 4 | .. automodule:: tlslite.integration.clienthelper 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.httptlsconnection.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.httptlsconnection module 2 | ============================================ 3 | 4 | .. automodule:: tlslite.integration.httptlsconnection 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.imap4_tls.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.imap4_tls module 2 | ==================================== 3 | 4 | .. automodule:: tlslite.integration.imap4_tls 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.pop3_tls.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.pop3_tls module 2 | =================================== 3 | 4 | .. automodule:: tlslite.integration.pop3_tls 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration package 2 | =========================== 3 | 4 | .. automodule:: tlslite.integration 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | 10 | Submodules 11 | ---------- 12 | 13 | .. toctree:: 14 | 15 | tlslite.integration.asyncstatemachine 16 | tlslite.integration.clienthelper 17 | tlslite.integration.httptlsconnection 18 | tlslite.integration.imap4_tls 19 | tlslite.integration.pop3_tls 20 | tlslite.integration.smtp_tls 21 | tlslite.integration.tlsasyncdispatchermixin 22 | tlslite.integration.tlssocketservermixin 23 | tlslite.integration.xmlrpcserver 24 | tlslite.integration.xmlrpctransport 25 | 26 | -------------------------------------------------------------------------------- /docs/tlslite.integration.smtp_tls.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.smtp_tls module 2 | =================================== 3 | 4 | .. automodule:: tlslite.integration.smtp_tls 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.tlsasyncdispatchermixin.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.tlsasyncdispatchermixin module 2 | ================================================== 3 | 4 | .. automodule:: tlslite.integration.tlsasyncdispatchermixin 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.tlsasynciodispatchermixin: -------------------------------------------------------------------------------- 1 | tlslite.integration.tlsasynciodispatchermixin module 2 | ================================================== 3 | 4 | .. automodule:: tlslite.integration.tlsasynciodispatchermixin 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.tlssocketservermixin.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.tlssocketservermixin module 2 | =============================================== 3 | 4 | .. automodule:: tlslite.integration.tlssocketservermixin 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.xmlrpcserver.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.xmlrpcserver module 2 | ======================================= 3 | 4 | .. automodule:: tlslite.integration.xmlrpcserver 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.integration.xmlrpctransport.rst: -------------------------------------------------------------------------------- 1 | tlslite.integration.xmlrpctransport module 2 | ========================================== 3 | 4 | .. automodule:: tlslite.integration.xmlrpctransport 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.keyexchange.rst: -------------------------------------------------------------------------------- 1 | tlslite.keyexchange module 2 | ========================== 3 | 4 | .. automodule:: tlslite.keyexchange 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.mathtls.rst: -------------------------------------------------------------------------------- 1 | tlslite.mathtls module 2 | ====================== 3 | 4 | .. automodule:: tlslite.mathtls 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.messages.rst: -------------------------------------------------------------------------------- 1 | tlslite.messages module 2 | ======================= 3 | 4 | .. automodule:: tlslite.messages 5 | :members: 6 | :special-members: __init__, __repr__, __str__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.messagesocket.rst: -------------------------------------------------------------------------------- 1 | tlslite.messagesocket module 2 | ============================ 3 | 4 | .. automodule:: tlslite.messagesocket 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.recordlayer.rst: -------------------------------------------------------------------------------- 1 | tlslite.recordlayer module 2 | ========================== 3 | 4 | .. automodule:: tlslite.recordlayer 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.rst: -------------------------------------------------------------------------------- 1 | tlslite package 2 | =============== 3 | 4 | .. automodule:: tlslite 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | 10 | Subpackages 11 | ----------- 12 | 13 | .. toctree:: 14 | 15 | tlslite.integration 16 | tlslite.utils 17 | 18 | Submodules 19 | ---------- 20 | 21 | .. toctree:: 22 | 23 | tlslite.api 24 | tlslite.basedb 25 | tlslite.bufferedsocket 26 | tlslite.checker 27 | tlslite.constants 28 | tlslite.defragmenter 29 | tlslite.dh 30 | tlslite.errors 31 | tlslite.extensions 32 | tlslite.handshakehashes 33 | tlslite.handshakehelpers 34 | tlslite.handshakesettings 35 | tlslite.keyexchange 36 | tlslite.mathtls 37 | tlslite.messages 38 | tlslite.messagesocket 39 | tlslite.recordlayer 40 | tlslite.session 41 | tlslite.sessioncache 42 | tlslite.tlsconnection 43 | tlslite.tlsrecordlayer 44 | tlslite.verifierdb 45 | tlslite.x509 46 | tlslite.x509certchain 47 | 48 | -------------------------------------------------------------------------------- /docs/tlslite.session.rst: -------------------------------------------------------------------------------- 1 | tlslite.session module 2 | ====================== 3 | 4 | .. automodule:: tlslite.session 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.sessioncache.rst: -------------------------------------------------------------------------------- 1 | tlslite.sessioncache module 2 | =========================== 3 | 4 | .. automodule:: tlslite.sessioncache 5 | :members: 6 | :special-members: __init__, __getitem__, __setitem__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.tlsconnection.rst: -------------------------------------------------------------------------------- 1 | tlslite.tlsconnection module 2 | ============================ 3 | 4 | .. automodule:: tlslite.tlsconnection 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.tlsrecordlayer.rst: -------------------------------------------------------------------------------- 1 | tlslite.tlsrecordlayer module 2 | ============================= 3 | 4 | .. automodule:: tlslite.tlsrecordlayer 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.aes.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.aes module 2 | ======================== 3 | 4 | .. automodule:: tlslite.utils.aes 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.aesgcm.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.aesgcm module 2 | =========================== 3 | 4 | .. automodule:: tlslite.utils.aesgcm 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.asn1parser.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.asn1parser module 2 | =============================== 3 | 4 | .. automodule:: tlslite.utils.asn1parser 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.chacha.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.chacha module 2 | =========================== 3 | 4 | .. automodule:: tlslite.utils.chacha 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.chacha20_poly1305.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.chacha20_poly1305 module 2 | ====================================== 3 | 4 | .. automodule:: tlslite.utils.chacha20_poly1305 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.cipherfactory.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.cipherfactory module 2 | ================================== 3 | 4 | .. automodule:: tlslite.utils.cipherfactory 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.codec.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.codec module 2 | ========================== 3 | 4 | .. automodule:: tlslite.utils.codec 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.compat.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.compat module 2 | =========================== 3 | 4 | .. automodule:: tlslite.utils.compat 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.constanttime.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.constanttime module 2 | ================================= 3 | 4 | .. automodule:: tlslite.utils.constanttime 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.cryptomath.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.cryptomath module 2 | =============================== 3 | 4 | .. automodule:: tlslite.utils.cryptomath 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.datefuncs.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.datefuncs module 2 | ============================== 3 | 4 | .. automodule:: tlslite.utils.datefuncs 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.deprecations.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.deprecations module 2 | ================================= 3 | 4 | .. automodule:: tlslite.utils.deprecations 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.dns_utils.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.dns_utils module 2 | ============================== 3 | 4 | .. automodule:: tlslite.utils.dns_utils 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.ecc.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.ecc module 2 | ======================== 3 | 4 | .. automodule:: tlslite.utils.ecc 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.ecdsakey.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.ecdsakey module 2 | ============================= 3 | 4 | .. automodule:: tlslite.utils.ecdsakey 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.keyfactory.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.keyfactory module 2 | =============================== 3 | 4 | .. automodule:: tlslite.utils.keyfactory 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.lists.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.lists module 2 | ========================== 3 | 4 | .. automodule:: tlslite.utils.lists 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.openssl_aes.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.openssl_aes module 2 | ================================ 3 | 4 | .. automodule:: tlslite.utils.openssl_aes 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.openssl_rc4.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.openssl_rc4 module 2 | ================================ 3 | 4 | .. automodule:: tlslite.utils.openssl_rc4 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.openssl_rsakey.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.openssl_rsakey module 2 | =================================== 3 | 4 | .. automodule:: tlslite.utils.openssl_rsakey 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.openssl_tripledes.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.openssl_tripledes module 2 | ====================================== 3 | 4 | .. automodule:: tlslite.utils.openssl_tripledes 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.pem.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.pem module 2 | ======================== 3 | 4 | .. automodule:: tlslite.utils.pem 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.poly1305.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.poly1305 module 2 | ============================= 3 | 4 | .. automodule:: tlslite.utils.poly1305 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.pycrypto_aes.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.pycrypto_aes module 2 | ================================= 3 | 4 | .. automodule:: tlslite.utils.pycrypto_aes 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.pycrypto_aesgcm.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.pycrypto_aesgcm module 2 | ==================================== 3 | 4 | .. automodule:: tlslite.utils.pycrypto_aesgcm 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.pycrypto_rc4.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.pycrypto_rc4 module 2 | ================================= 3 | 4 | .. automodule:: tlslite.utils.pycrypto_rc4 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.pycrypto_rsakey.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.pycrypto_rsakey module 2 | ==================================== 3 | 4 | .. automodule:: tlslite.utils.pycrypto_rsakey 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.pycrypto_tripledes.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.pycrypto_tripledes module 2 | ======================================= 3 | 4 | .. automodule:: tlslite.utils.pycrypto_tripledes 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.python_aes.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.python_aes module 2 | =============================== 3 | 4 | .. automodule:: tlslite.utils.python_aes 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.python_aesgcm.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.python_aesgcm module 2 | ================================== 3 | 4 | .. automodule:: tlslite.utils.python_aesgcm 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.python_chacha20_poly1305.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.python_chacha20_poly1305 module 2 | ============================================= 3 | 4 | .. automodule:: tlslite.utils.python_chacha20_poly1305 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.python_rc4.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.python_rc4 module 2 | =============================== 3 | 4 | .. automodule:: tlslite.utils.python_rc4 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.python_rsakey.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.python_rsakey module 2 | ================================== 3 | 4 | .. automodule:: tlslite.utils.python_rsakey 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.rc4.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.rc4 module 2 | ======================== 3 | 4 | .. automodule:: tlslite.utils.rc4 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.rijndael.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.rijndael module 2 | ============================= 3 | 4 | .. automodule:: tlslite.utils.rijndael 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.rsakey.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.rsakey module 2 | =========================== 3 | 4 | .. automodule:: tlslite.utils.rsakey 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils package 2 | ===================== 3 | 4 | .. automodule:: tlslite.utils 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | 10 | Submodules 11 | ---------- 12 | 13 | .. toctree:: 14 | 15 | tlslite.utils.aes 16 | tlslite.utils.aesgcm 17 | tlslite.utils.asn1parser 18 | tlslite.utils.chacha 19 | tlslite.utils.chacha20_poly1305 20 | tlslite.utils.cipherfactory 21 | tlslite.utils.codec 22 | tlslite.utils.compat 23 | tlslite.utils.constanttime 24 | tlslite.utils.cryptomath 25 | tlslite.utils.datefuncs 26 | tlslite.utils.deprecations 27 | tlslite.utils.dns_utils 28 | tlslite.utils.ecc 29 | tlslite.utils.ecdsakey 30 | tlslite.utils.keyfactory 31 | tlslite.utils.lists 32 | tlslite.utils.openssl_aes 33 | tlslite.utils.openssl_rc4 34 | tlslite.utils.openssl_rsakey 35 | tlslite.utils.openssl_tripledes 36 | tlslite.utils.pem 37 | tlslite.utils.poly1305 38 | tlslite.utils.pycrypto_aes 39 | tlslite.utils.pycrypto_aesgcm 40 | tlslite.utils.pycrypto_rc4 41 | tlslite.utils.pycrypto_rsakey 42 | tlslite.utils.pycrypto_tripledes 43 | tlslite.utils.python_aes 44 | tlslite.utils.python_aesgcm 45 | tlslite.utils.python_chacha20_poly1305 46 | tlslite.utils.python_rc4 47 | tlslite.utils.python_rsakey 48 | tlslite.utils.rc4 49 | tlslite.utils.rijndael 50 | tlslite.utils.rsakey 51 | tlslite.utils.tackwrapper 52 | tlslite.utils.tlshashlib 53 | tlslite.utils.tripledes 54 | tlslite.utils.x25519 55 | 56 | -------------------------------------------------------------------------------- /docs/tlslite.utils.tackwrapper.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.tackwrapper module 2 | ================================ 3 | 4 | .. automodule:: tlslite.utils.tackwrapper 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.tlshashlib.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.tlshashlib module 2 | =============================== 3 | 4 | .. automodule:: tlslite.utils.tlshashlib 5 | :members: 6 | :special-members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.tripledes.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.tripledes module 2 | ============================== 3 | 4 | .. automodule:: tlslite.utils.tripledes 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.utils.x25519.rst: -------------------------------------------------------------------------------- 1 | tlslite.utils.x25519 module 2 | =========================== 3 | 4 | .. automodule:: tlslite.utils.x25519 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.verifierdb.rst: -------------------------------------------------------------------------------- 1 | tlslite.verifierdb module 2 | ========================= 3 | 4 | .. automodule:: tlslite.verifierdb 5 | :members: 6 | :special-members: __init__, __setitem__, __getitem__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.x509.rst: -------------------------------------------------------------------------------- 1 | tlslite.x509 module 2 | =================== 3 | 4 | .. automodule:: tlslite.x509 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/tlslite.x509certchain.rst: -------------------------------------------------------------------------------- 1 | tlslite.x509certchain module 2 | ============================ 3 | 4 | .. automodule:: tlslite.x509certchain 5 | :members: 6 | :special-members: __init__ 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ecdsa>=0.18.0b1 2 | -------------------------------------------------------------------------------- /scripts/speed.py: -------------------------------------------------------------------------------- 1 | import timeit 2 | 3 | from tlslite.utils.cryptomath import gmpyLoaded, GMPY2_LOADED 4 | 5 | print("Acceleration backends loaded:") 6 | print("gmpy: {0}".format(gmpyLoaded)) 7 | print("gmpy2: {0}".format(GMPY2_LOADED)) 8 | print("") 9 | 10 | def do(setup_statements, statement): 11 | # extracted from timeit.py 12 | t = timeit.Timer(stmt=statement, setup="\n".join(setup_statements)) 13 | # determine number so that 0.2 <= total time < 2.0 14 | for i in range(1, 10): 15 | number = 10 ** i 16 | x = t.timeit(number) 17 | if x >= 0.2: 18 | break 19 | return x / number 20 | 21 | 22 | prnt_form = ( 23 | "{name:>16}{sep:1} {keygen:>9{form}}{unit:1} " 24 | "{keygen_inv:>9{form_inv}} {sign:>9{form}}{unit:1} " 25 | "{sign_inv:>9{form_inv}} {verify:>9{form}}{unit:1} " 26 | "{verify_inv:>9{form_inv}}" 27 | ) 28 | 29 | print( 30 | prnt_form.format( 31 | keygen="keygen", 32 | keygen_inv="keygen/s", 33 | sign="sign", 34 | sign_inv="sign/s", 35 | verify="verify", 36 | verify_inv="verify/s", 37 | name="", 38 | sep="", 39 | unit="", 40 | form="", 41 | form_inv="", 42 | ) 43 | ) 44 | 45 | for size in [1024, 2048, 3072, 4096]: 46 | S1 = "from tlslite.utils.python_rsakey import Python_RSAKey" 47 | S2 = "from tlslite.utils.cryptomath import secureHash" 48 | S3 = "key = Python_RSAKey.generate(%s)" % size 49 | S4 = "msg = b'msg'" 50 | S5 = "msg_hash = secureHash(msg, 'sha1')" 51 | S6 = "sig = key.sign(msg_hash)" 52 | S7 = "key.verify(sig, msg_hash)" 53 | keygen = do([S1, S2], S3) 54 | sign = do([S1, S2, S3, S4, S5], S6) 55 | verf = do([S1, S2, S3, S4, S5, S6], S7) 56 | 57 | print( 58 | prnt_form.format( 59 | name="RSA {0} bits".format(size), 60 | sep=":", 61 | unit="s", 62 | keygen=keygen, 63 | keygen_inv=1.0 / keygen, 64 | sign=sign, 65 | sign_inv=1.0 / sign, 66 | verify=verf, 67 | verify_inv=1.0 / verf, 68 | form=".5f", 69 | form_inv=".2f", 70 | ) 71 | ) 72 | 73 | print("") 74 | 75 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Trevor Perrin 4 | # See the LICENSE file for legal information regarding use of this file. 5 | 6 | from distutils.core import setup 7 | import os 8 | 9 | here = os.path.abspath(os.path.dirname(__file__)) 10 | with open(os.path.join(here, "README")) as f: 11 | README = f.read() 12 | 13 | setup(name="tlslite-ng", 14 | version="0.8.2", 15 | author="Alicja Kario", 16 | author_email="hkario@redhat.com", 17 | url="https://github.com/tlsfuzzer/tlslite-ng", 18 | description="Pure python implementation of SSL and TLS.", 19 | long_description=README, 20 | license="LGPLv2", 21 | scripts=["scripts/tls.py", "scripts/tlsdb.py"], 22 | packages=["tlslite", "tlslite.utils", "tlslite.integration"], 23 | package_data={ 24 | 'package1': ['LICENSE', 'README.md']}, 25 | install_requires=['ecdsa>=0.18.0b1'], 26 | obsoletes=["tlslite"], 27 | python_requires=">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*", 28 | classifiers=[ 29 | 'Development Status :: 5 - Production/Stable', 30 | 'Intended Audience :: Developers', 31 | 'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)', 32 | 'Operating System :: OS Independent', 33 | 'Programming Language :: Python', 34 | 'Programming Language :: Python :: 2', 35 | 'Programming Language :: Python :: 2.6', 36 | 'Programming Language :: Python :: 2.7', 37 | 'Programming Language :: Python :: 3', 38 | 'Programming Language :: Python :: 3.7', 39 | 'Programming Language :: Python :: 3.8', 40 | 'Programming Language :: Python :: 3.9', 41 | 'Programming Language :: Python :: 3.10', 42 | 'Programming Language :: Python :: 3.11', 43 | 'Programming Language :: Python :: 3.12', 44 | 'Topic :: Security :: Cryptography', 45 | 'Topic :: Software Development :: Libraries :: Python Modules', 46 | 'Topic :: System :: Networking' 47 | ], 48 | keywords="ssl, tls, pure-python" 49 | ) 50 | -------------------------------------------------------------------------------- /tests/TACK1.pem: -------------------------------------------------------------------------------- 1 | Created by tack.py 0.9.9 2 | Created at 2015-03-03T21:10:40Z 3 | -----BEGIN TACK----- 4 | QjeXykNtxc22jUSQHO32Uq0HVfg9jKEUHNlqfxtpPAaiJ3mA1O+lI2ZDs8uS+Zdb 5 | /uxswqubymN2Fg5ujrQr2QAAAbtbWsbjtgd+sy84p8w/aiD1a08WGz1A6IsN36Hs 6 | Z5wb70F54Y8N6jZxJp9PZcT4MnFiv58MxrmJAQnIlqx6y8TEzHMS7zj2uu6d+m1N 7 | HhZK/UtLpncs2wwqw8PI5Ea9kcYQXw== 8 | -----END TACK----- 9 | -------------------------------------------------------------------------------- /tests/TACK2.pem: -------------------------------------------------------------------------------- 1 | Created by tack.py 0.9.9 2 | Created at 2015-03-03T21:10:41Z 3 | -----BEGIN TACK----- 4 | 9C+V4IbqF3l/GsK4y1X2wWhis+f2Jw4pX2bCpB22NFDdUV+QiI5Ztpvd1jQFtIH+ 5 | ayr7ycK52KsU7/rRYjX7JwAAAbtbWsbjtgd+sy84p8w/aiD1a08WGz1A6IsN36Hs 6 | Z5wb70F5bmWSnoZ8rqEHkLbqmqjiM+XCDZW+57MUqzT5sid4mkS00g7hMZCFw1q+ 7 | pmv6B7SqyKd5IumU/bdmqt3g/g6xzw== 8 | -----END TACK----- 9 | -------------------------------------------------------------------------------- /tests/TACK_Key1.pem: -------------------------------------------------------------------------------- 1 | Created by tack.py 0.9.9 2 | Created at 2015-03-03T21:09:21Z 3 | -----BEGIN TACK PRIVATE KEY----- 4 | AQAAIABwzwuq6r+poACwbpVJ/DI9GWMdPNh2r5C+khOxccgvTtnb36Rz+YRvdWM5 5 | uFwZKh5CN5fKQ23FzbaNRJAc7fZSrQdV+D2MoRQc2Wp/G2k8BqIneYDU76UjZkOz 6 | y5L5l1v+7GzCq5vKY3YWDm6OtCvZCEvqRIl7bOvhNKa608Xj+49YlJeVzFxlX8Sb 7 | HN1BlEU= 8 | -----END TACK PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /tests/TACK_Key2.pem: -------------------------------------------------------------------------------- 1 | Created by tack.py 0.9.9 2 | Created at 2015-03-03T21:09:21Z 3 | -----BEGIN TACK PRIVATE KEY----- 4 | AQAAIABrNu+M/CwjNVTJe4gD7vow75Bws7ggXZNKl33QAAh81VS+tKgOiCPuLwYS 5 | ft6djk70L5XghuoXeX8awrjLVfbBaGKz5/YnDilfZsKkHbY0UN1RX5CIjlm2m93W 6 | NAW0gf5rKvvJwrnYqxTv+tFiNfsnllxaTH/Pi0hoCjdGNxqFnTGu53H6TYzpU7aK 7 | 3U4t/nA= 8 | -----END TACK PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /tests/TACKs.pem: -------------------------------------------------------------------------------- 1 | Created by TACK.py 0.9.6 2 | Created at 2012-05-08T15:53:56Z 3 | -----BEGIN TACK----- 4 | lJ7JcxIC9y6i/jTkTh+MXf0aO23J58PjUQCAI4vCMINlcMGSC8Vyq9On51hk5zAz 5 | DlIdXzC7zcUC7AN7/alXYwAAAkJ0Bb8+RaM9YEywaJEGViKJJmpYG/gJHgfGaefI 6 | 9kKbXSDmXHI2tbZPnCxzR4ZXz21HxFm1SPYijTKm4zm5dAzXzvneOTRf/SFbY0dZ 7 | s7UpHKK4yOhREoGH8z8kxxD5/BXb5A== 8 | -----END TACK----- 9 | Created by tack.py 0.9.7 10 | Created at 2012-08-31T19:15:38Z 11 | -----BEGIN TACK----- 12 | x7MspJSqsflA4qZ6qG8r8Hd5AB0+BB09n96vuF5Z1ayBeGzrny90WeCu3E3G2d8Y 13 | 620TVYfnALIaMg//MZ8ovQAAAkMcxb8+RaM9YEywaJEGViKJJmpYG/gJHgfGaefI 14 | 9kKbXSDmq3tmkncGftPeMAUh3T2vcXNiRnRqyFArnCKr2gCSj2vsCiS3F+qVhaUv 15 | OyxAcIhminamGruajdPSXMtlCCwWag== 16 | -----END TACK----- 17 | -------------------------------------------------------------------------------- /tests/TACKunrelated.pem: -------------------------------------------------------------------------------- 1 | Created by TACK.py 0.9.6 2 | Created at 2012-05-08T17:12:57Z 3 | -----BEGIN TACK----- 4 | lJ7JcxIC9y6i/jTkTh+MXf0aO23J58PjUQCAI4vCMINlcMGSC8Vyq9On51hk5zAz 5 | DlIdXzC7zcUC7AN7/alXYwMFAchwkzK2S2ZyeiBj5AZvO5WMsKruV2pezv2VM5m7 6 | iHRzHZWHnUVusrs/d04QnVS2Btmt5hECAKdcWK0qZHnMxhZhom9DExiqLQW0A05E 7 | xHvWKhN8y6J9UATLvGjjm3U7oyNxzQ== 8 | -----END TACK----- 9 | -------------------------------------------------------------------------------- /tests/clientDSACert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEYzCCBBGgAwIBAgIUeLiaH57flwaXt7G1ae3irblrBR0wCwYJYIZIAWUDBAMC 3 | MBQxEjAQBgNVBAMMCWxvY2FsaG9zdDAgFw0yMzA4MDQxNjQ5MzhaGA8yMTIzMDcx 4 | MTE2NDkzOFowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIDQjCCAjUGByqGSM44BAEw 5 | ggIoAoIBAQCKiKCtENzZfSCSfewPFVgV0vmOVw8WqO4uhiN/nSddlrxNOS58f5fk 6 | whAmtKxH7mQqlFPADuscHy5NQl9GsKZPi5ogVtxImJwP7enyf056tcOCtCUWnMIQ 7 | eEossgWdYE51KQeX+Hmr3XHqJwpsAW9yNkDS46SXut+uAAXLoQ2w+a71BJavCCuZ 8 | P5CqOjMbKVDBMIGPwDUKaL1prq2VBVSZ8WTiAtqqgaQUZQuV88G5R46teyNdOHt8 9 | zonXF8/6PUuDbI3KXvQZitLo6dhXGrAg99Pwg9k9ztzUJOeZ7kU6DZFaawRT+/9J 10 | f6iG0Le20jVc9aw9SbWNfJBY7szeaq11Ah0A/Rgp6nI7FlqEUqL9GaNBm+2B/E1D 11 | P3Z5n3prNQKCAQBV7L0KOF5OnXYMNUrVSZ7qP9hMP4dnhVPvqVa0LJhXbmYx8CO+ 12 | kdPGbX2t8skg5yM1vK+AZ/nM5tlbA2R/F6Nol3X9lwUwQT0RRlhsHoT7kTVMU+Ip 13 | lv1C3X+H3GthGAnMmGutGsK+48sHl6QAPmy8f6uVHWzh6WQe7pROZPD410U8t2GM 14 | wRUjlo8n5NdQx/Qw7bvT88HX3FpybNQQJvsefeX5gEpK8JQSLhOEEjAqafrJHtBM 15 | FBDsdpn5/5/H9gTBXqjq6zJRxQP+xggmLj2Eo9B249ANmi57pixM2m9NFXVneJJN 16 | zlIZ2DIEzOX8TVjDFyGLmldXIz2/BqG6dmYDA4IBBQACggEAQDA5L5QJubxun5sH 17 | w31gN/oXWyxF9qXoaUyLpUpt2V2lebNCJ6bdR+wstA7ddyAb/pM6kjnjEv+UxD3c 18 | SjzMtW+Eehn8kXv4gdYyJeJjFcziV5sFvjW6RGAQX0+YO1gAv8BxjGzySNoc7bpp 19 | Ta5YywN0sRPG3U0KsVGyBXakYNoS3Hq7n1JnrSuGBKVje1fQyesRtpkWBfD6Dlog 20 | iciOy/iQnTsMCFrlrETJPfOAJ12Gzsr+lL9TLVsIP9tAk++Arp1H/rICf2QpIjsZ 21 | uEehHgg3oA62RecmMBf+7HX2+bZeoRyYYCe6DMyDS7HLzKA/y31iw7E9VLNyKU4q 22 | i6VPLqNTMFEwHQYDVR0OBBYEFBFcfDeT5cNGJwP89U5VkvxojDuzMB8GA1UdIwQY 23 | MBaAFBFcfDeT5cNGJwP89U5VkvxojDuzMA8GA1UdEwEB/wQFMAMBAf8wCwYJYIZI 24 | AWUDBAMCAz8AMDwCHGaJRUSP9RhmtFPC7UZQ3KjyELgZ/vUcfoJa3ysCHEUavN6C 25 | jExdFwdKI/98/jX7Qz7IlKnDbww8K9c= 26 | -----END CERTIFICATE----- 27 | -------------------------------------------------------------------------------- /tests/clientDSAKey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIICXAIBADCCAjUGByqGSM44BAEwggIoAoIBAQCKiKCtENzZfSCSfewPFVgV0vmO 3 | Vw8WqO4uhiN/nSddlrxNOS58f5fkwhAmtKxH7mQqlFPADuscHy5NQl9GsKZPi5og 4 | VtxImJwP7enyf056tcOCtCUWnMIQeEossgWdYE51KQeX+Hmr3XHqJwpsAW9yNkDS 5 | 46SXut+uAAXLoQ2w+a71BJavCCuZP5CqOjMbKVDBMIGPwDUKaL1prq2VBVSZ8WTi 6 | AtqqgaQUZQuV88G5R46teyNdOHt8zonXF8/6PUuDbI3KXvQZitLo6dhXGrAg99Pw 7 | g9k9ztzUJOeZ7kU6DZFaawRT+/9Jf6iG0Le20jVc9aw9SbWNfJBY7szeaq11Ah0A 8 | /Rgp6nI7FlqEUqL9GaNBm+2B/E1DP3Z5n3prNQKCAQBV7L0KOF5OnXYMNUrVSZ7q 9 | P9hMP4dnhVPvqVa0LJhXbmYx8CO+kdPGbX2t8skg5yM1vK+AZ/nM5tlbA2R/F6No 10 | l3X9lwUwQT0RRlhsHoT7kTVMU+Iplv1C3X+H3GthGAnMmGutGsK+48sHl6QAPmy8 11 | f6uVHWzh6WQe7pROZPD410U8t2GMwRUjlo8n5NdQx/Qw7bvT88HX3FpybNQQJvse 12 | feX5gEpK8JQSLhOEEjAqafrJHtBMFBDsdpn5/5/H9gTBXqjq6zJRxQP+xggmLj2E 13 | o9B249ANmi57pixM2m9NFXVneJJNzlIZ2DIEzOX8TVjDFyGLmldXIz2/BqG6dmYD 14 | BB4CHCEci705ssiT3yVp22s8gZEDANgtPXZaMjAFEMw= 15 | -----END PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /tests/clientECCert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIBfjCCASOgAwIBAgIUTxkWwfl73xnqhoJqWZ+R4RPCX54wCgYIKoZIzj0EAwIw 3 | FDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTE5MDkyNTE2NDgzMloXDTI5MDkyMjE2 4 | NDgzMlowFDESMBAGA1UEAwwJbG9jYWxob3N0MFkwEwYHKoZIzj0CAQYIKoZIzj0D 5 | AQcDQgAEQNSgjtKQ2KEyIjcamNSSH83huV2aYpJMCRYAXvEBUNygmCwxCod2j97J 6 | Z4rnBmd9ySlceT65nXFuDuKlftIlLaNTMFEwHQYDVR0OBBYEFM9448HkxS8PnjT2 7 | CRzwBP3SWGK1MB8GA1UdIwQYMBaAFM9448HkxS8PnjT2CRzwBP3SWGK1MA8GA1Ud 8 | EwEB/wQFMAMBAf8wCgYIKoZIzj0EAwIDSQAwRgIhAKCSuUb8eWvb3WCQcA8Wj2av 9 | V8UXsXPk5N2HyDojhklvAiEA97Z8QDFxMg20hm8cPGMlQT1r3PtPwF0eRsL2rPu0 10 | nxY= 11 | -----END CERTIFICATE----- 12 | -------------------------------------------------------------------------------- /tests/clientECKey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgjIlFWfrrN8Rsn7RU 3 | 9mZsG6hTDEa/1pXw8oNBML7UjeihRANCAARA1KCO0pDYoTIiNxqY1JIfzeG5XZpi 4 | kkwJFgBe8QFQ3KCYLDEKh3aP3slniucGZ33JKVx5PrmdcW4O4qV+0iUt 5 | -----END PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /tests/clientEd25519Cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIBOjCB7aADAgECAhQ15c2VkK6IVUB62L0UG1houuxlozAFBgMrZXAwEzERMA8G 3 | A1UEAwwISm9obiBEb2UwHhcNMjEwNzI3MTgxMjA2WhcNMjEwODI2MTgxMjA2WjAT 4 | MREwDwYDVQQDDAhKb2huIERvZTAqMAUGAytlcAMhADjqYm4QU+seahrT1xHlASeM 5 | ZTe63eoQ95oBAeZRL8Ofo1MwUTAdBgNVHQ4EFgQUWW+x7NNy1nmJwl/gr6AoPGrC 6 | 0GgwHwYDVR0jBBgwFoAUWW+x7NNy1nmJwl/gr6AoPGrC0GgwDwYDVR0TAQH/BAUw 7 | AwEB/zAFBgMrZXADQQDQxNKFkySCfap/8yEtD8aJFDpDQLF/QL1rKIo/198n/18X 8 | D5K63FFkmQOS5dv2h/QiSHWkNpBklqe0bRfW0nEB 9 | -----END CERTIFICATE----- 10 | -------------------------------------------------------------------------------- /tests/clientEd25519Key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MC4CAQAwBQYDK2VwBCIEIOm5ZND3cKuM23aTESsnqkkunnQNuhksWOosOHf06vw6 3 | -----END PRIVATE KEY----- 4 | -------------------------------------------------------------------------------- /tests/clientX509Cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICfjCCAecCCQDgdeCLz7d92jANBgkqhkiG9w0BAQUFADCBgDELMAkGA1UEBhMC 3 | VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMQ8wDQYDVQQKEwZUcmV2 4 | Q28xCzAJBgNVBAsTAkNBMRIwEAYDVQQDEwlUcmV2Q28gQ0ExIDAeBgkqhkiG9w0B 5 | CQEWEXRsc2xpdGVAdHJldnAubmV0MB4XDTEyMDIwNjAxMDMxMVoXDTQyMDEyOTAx 6 | MDMxMVowgYUxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UEBxMHT2Fr 7 | bGFuZDEPMA0GA1UEChMGVHJldkNvMQwwCgYDVQQLFANSJkQxFjAUBgNVBAMTDVRy 8 | ZXZvciBQZXJyaW4xIDAeBgkqhkiG9w0BCQEWEXRsc2xpdGVAdHJldnAubmV0MIGf 9 | MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrncYzz0HWlT3ELBTZ1Jt/ZDFWlHW9 10 | SrhlwR5Pd8bEonXCxhomAssz4SkJMaByGFyAUAT4bqf41PV50y5lkYVfgUIy8qQS 11 | Gd/qJrNuFa6odWt3MExQdVCXKTOdjYQmhwvXo6zlf7u/Sj5NICAWmXRHZFBljqG8 12 | QasxPrLSbWUtWQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAJRqUTQ6pZ71rm46+qXo 13 | Sqc5tnj42uIn1eIfnm5pbPxXFvuP3RbuHVO140+LQL844c2JCOKeu9dQPKxoRNU7 14 | sQLdo8+o+KboiYif6m9Ial4ss0I5MhPPVi9heguRbcFHx+87q8xdN7vd6Wn2gw/l 15 | IV+b9EUQMWYFBCokR8o7o+IV 16 | -----END CERTIFICATE----- 17 | -------------------------------------------------------------------------------- /tests/clientX509Key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXwIBAAKBgQCrncYzz0HWlT3ELBTZ1Jt/ZDFWlHW9SrhlwR5Pd8bEonXCxhom 3 | Assz4SkJMaByGFyAUAT4bqf41PV50y5lkYVfgUIy8qQSGd/qJrNuFa6odWt3MExQ 4 | dVCXKTOdjYQmhwvXo6zlf7u/Sj5NICAWmXRHZFBljqG8QasxPrLSbWUtWQIDAQAB 5 | AoGBAIo99cMWWTq5zZ+QwtsV4Iyl8PiFbrKk1hVhk0EAgyUymRnk6ntkFLwdzCiT 6 | yWMfLKRP0TEuMjDHm1YfP2ih6ITMh83SLF4og0dDzU+tn3PX/XWaoYZr8HsFTDMi 7 | FhrWXXBX8ST3F2aEyOxXZj8SGFu5YIJ8iemztANzZVSvYkWBAkEA2EbI6rnpXc5t 8 | fKhdkXa0c8l+Uyn/8JadHJ8sobzNhZ/CeC0a9PwhZLQvsRgNXXjYUFJ7N2igoIrk 9 | y0e8f+iD/QJBAMsjFrsrhmXcksf4RX6ZAg1rcJS115JjH2EnbbWd2nBLHUBwywGh 10 | VJhNyQRWBNlVGMrYWCQwHcZNOdUsvmLX140CQQC5v2GDpxQ0irwh2gAylH67CwzB 11 | pEq6eMCK+nI8nojtAJ7m0+ZZDcooUVC8imnAI6+0nIJSvjtmZqPFquDMAgiJAkEA 12 | ox/mXR+yqZHbfSHuDJ+qekRQ/9qW5kMbK9WR0EqW454uO1VYcFKxsCymxAiflDc1 13 | 1Y6uGUFaZ6gUTQ/FQ3K48QJBAIlPKkD8VfNg/3B6wq7gmqRIy9MblLLZo2Qh4nZA 14 | 4icCv/vpHH+o6Ccxad03LQKsTNJl3z52G4sKgASudWiBbLs= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /tests/httpsclient.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | from tlslite import HTTPTLSConnection, HandshakeSettings 4 | 5 | settings = HandshakeSettings() 6 | settings.useExperimentalTackExtension = True 7 | 8 | h = HTTPTLSConnection("localhost", 4443, settings=settings) 9 | h.request("GET", "/index.html") 10 | r = h.getresponse() 11 | print(r.read()) 12 | -------------------------------------------------------------------------------- /tests/httpsserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | python ../scripts/tls.py server -k serverX509Key.pem -c serverX509Cert.pem -t TACK1.pem localhost:4443 3 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |253: 35 | return False 36 | 37 | # must not be all-numeric, so that it can't be confused with an ip-address 38 | if re.match(r"[\d.]+$", hostname): 39 | return False 40 | 41 | allowed = re.compile(r"(?!-)[A-Z\d-]{1,63}(?>= 8 30 | return bytearray(ret) 31 | 32 | def __init__(self, key): 33 | """Set the authenticator key""" 34 | if len(key) != 32: 35 | raise ValueError("Key must be 256 bit long") 36 | self.acc = 0 37 | self.r = self.le_bytes_to_num(key[0:16]) 38 | self.r &= 0x0ffffffc0ffffffc0ffffffc0fffffff 39 | self.s = self.le_bytes_to_num(key[16:32]) 40 | 41 | def create_tag(self, data): 42 | """Calculate authentication tag for data""" 43 | for i in range(0, divceil(len(data), 16)): 44 | n = self.le_bytes_to_num(data[i*16:(i+1)*16] + b'\x01') 45 | self.acc += n 46 | self.acc = (self.r * self.acc) % self.P 47 | self.acc += self.s 48 | return self.num_to_16_le_bytes(self.acc) 49 | 50 | -------------------------------------------------------------------------------- /tlslite/utils/pycrypto_aes.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """PyCrypto AES implementation.""" 5 | 6 | from .cryptomath import * 7 | from .aes import * 8 | 9 | if pycryptoLoaded: 10 | import Crypto.Cipher.AES 11 | 12 | def new(key, mode, IV): 13 | return PyCrypto_AES(key, mode, IV) 14 | 15 | class PyCrypto_AES(AES): 16 | 17 | def __init__(self, key, mode, IV): 18 | AES.__init__(self, key, mode, IV, "pycrypto") 19 | key = bytes(key) 20 | IV = bytes(IV) 21 | self.context = Crypto.Cipher.AES.new(key, mode, IV) 22 | 23 | def encrypt(self, plaintext): 24 | plaintext = bytes(plaintext) 25 | return bytearray(self.context.encrypt(plaintext)) 26 | 27 | def decrypt(self, ciphertext): 28 | ciphertext = bytes(ciphertext) 29 | return bytearray(self.context.decrypt(ciphertext)) 30 | -------------------------------------------------------------------------------- /tlslite/utils/pycrypto_aesgcm.py: -------------------------------------------------------------------------------- 1 | # Author: Google 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """PyCrypto AES-GCM implementation.""" 5 | 6 | from .cryptomath import * 7 | from .aesgcm import AESGCM 8 | 9 | if pycryptoLoaded: 10 | import Crypto.Cipher.AES 11 | 12 | def new(key): 13 | cipher = Crypto.Cipher.AES.new(bytes(key)) 14 | def encrypt(plaintext): 15 | return bytearray(cipher.encrypt(bytes(plaintext))) 16 | return AESGCM(key, "pycrypto", encrypt) 17 | -------------------------------------------------------------------------------- /tlslite/utils/pycrypto_rc4.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """PyCrypto RC4 implementation.""" 5 | 6 | from .cryptomath import * 7 | from .rc4 import * 8 | 9 | if pycryptoLoaded: 10 | import Crypto.Cipher.ARC4 11 | 12 | def new(key): 13 | return PyCrypto_RC4(key) 14 | 15 | class PyCrypto_RC4(RC4): 16 | 17 | def __init__(self, key): 18 | RC4.__init__(self, key, "pycrypto") 19 | key = bytes(key) 20 | self.context = Crypto.Cipher.ARC4.new(key) 21 | 22 | def encrypt(self, plaintext): 23 | plaintext = bytes(plaintext) 24 | return bytearray(self.context.encrypt(plaintext)) 25 | 26 | def decrypt(self, ciphertext): 27 | ciphertext = bytes(ciphertext) 28 | return bytearray(self.context.decrypt(ciphertext)) -------------------------------------------------------------------------------- /tlslite/utils/pycrypto_rsakey.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """PyCrypto RSA implementation.""" 5 | 6 | from __future__ import print_function 7 | import sys 8 | 9 | from .cryptomath import * 10 | 11 | from .rsakey import * 12 | from .python_rsakey import Python_RSAKey 13 | from .compat import compatLong 14 | 15 | if pycryptoLoaded: 16 | 17 | from Crypto.PublicKey import RSA 18 | 19 | class PyCrypto_RSAKey(RSAKey): 20 | def __init__(self, n=0, e=0, d=0, p=0, q=0, dP=0, dQ=0, qInv=0, 21 | key_type="rsa"): 22 | del dP, dQ, qInv # pycrypto calculates them by its own 23 | if not d: 24 | self.rsa = RSA.construct((compatLong(n), compatLong(e))) 25 | else: 26 | self.rsa = RSA.construct((compatLong(n), compatLong(e), 27 | compatLong(d), compatLong(p), 28 | compatLong(q))) 29 | self.key_type = key_type 30 | 31 | def __getattr__(self, name): 32 | return getattr(self.rsa, name) 33 | 34 | def hasPrivateKey(self): 35 | return self.rsa.has_private() 36 | 37 | def _rawPrivateKeyOp(self, message): 38 | try: 39 | return self.rsa.decrypt((compatLong(message),)) 40 | except ValueError as e: 41 | print("rsa: {0!r}".format(self.rsa), file=sys.stderr) 42 | values = [] 43 | for name in ["n", "e", "d", "p", "q", "dP", "dQ", "qInv"]: 44 | values.append("{0}: {1}".format(name, 45 | getattr(self, name, None))) 46 | print(", ".join(values), file=sys.stderr) 47 | print("message: {0}".format(message), file=sys.stderr) 48 | raise 49 | 50 | 51 | def _rawPublicKeyOp(self, ciphertext): 52 | try: 53 | return self.rsa.encrypt(compatLong(ciphertext), None)[0] 54 | except ValueError as e: 55 | print("rsa: {0!r}".format(self.rsa), file=sys.stderr) 56 | values = [] 57 | for name in ["n", "e", "d", "p", "q", "dP", "dQ", "qInv"]: 58 | values.append("{0}: {1}".format(name, 59 | getattr(self, name, None))) 60 | print(", ".join(values), file=sys.stderr) 61 | print("ciphertext: {0}".format(ciphertext), file=sys.stderr) 62 | raise 63 | 64 | @staticmethod 65 | def generate(bits, key_type="rsa"): 66 | key = PyCrypto_RSAKey() 67 | def f(numBytes): 68 | return bytes(getRandomBytes(numBytes)) 69 | key.rsa = RSA.generate(bits, f) 70 | key.key_type = key_type 71 | return key 72 | -------------------------------------------------------------------------------- /tlslite/utils/pycrypto_tripledes.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """PyCrypto 3DES implementation.""" 5 | 6 | from .cryptomath import * 7 | from .tripledes import * 8 | 9 | if pycryptoLoaded: 10 | import Crypto.Cipher.DES3 11 | 12 | def new(key, mode, IV): 13 | return PyCrypto_TripleDES(key, mode, IV) 14 | 15 | class PyCrypto_TripleDES(TripleDES): 16 | 17 | def __init__(self, key, mode, IV): 18 | TripleDES.__init__(self, key, mode, IV, "pycrypto") 19 | key = bytes(key) 20 | IV = bytes(IV) 21 | self.context = Crypto.Cipher.DES3.new(key, mode, IV) 22 | 23 | def encrypt(self, plaintext): 24 | plaintext = bytes(plaintext) 25 | return bytearray(self.context.encrypt(plaintext)) 26 | 27 | def decrypt(self, ciphertext): 28 | ciphertext = bytes(ciphertext) 29 | return bytearray(self.context.decrypt(ciphertext)) -------------------------------------------------------------------------------- /tlslite/utils/python_aesccm.py: -------------------------------------------------------------------------------- 1 | # Author: Ivan Nikolchev 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """ Pure Python AES-CCM implementation.""" 5 | 6 | from tlslite.utils.aesccm import AESCCM 7 | 8 | def new(key, tagLength=16): 9 | return AESCCM(key, "python", bytearray(16), tagLength) 10 | -------------------------------------------------------------------------------- /tlslite/utils/python_aesgcm.py: -------------------------------------------------------------------------------- 1 | # Author: Google 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """Pure-Python AES-GCM implementation.""" 5 | 6 | from .aesgcm import AESGCM 7 | from .rijndael import Rijndael 8 | 9 | 10 | def new(key): 11 | return AESGCM(key, "python", Rijndael(key, 16).encrypt) 12 | -------------------------------------------------------------------------------- /tlslite/utils/python_chacha20_poly1305.py: -------------------------------------------------------------------------------- 1 | # Author: Hubert Kario (c) 2015 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | """Pure-Python ChaCha20/Poly1305 implementation.""" 6 | 7 | from .chacha20_poly1305 import CHACHA20_POLY1305 8 | 9 | def new(key): 10 | """Return an AEAD cipher implementation""" 11 | return CHACHA20_POLY1305(key, "python") 12 | -------------------------------------------------------------------------------- /tlslite/utils/python_ecdsakey.py: -------------------------------------------------------------------------------- 1 | # Author Hubert Kario, copyright 2019 2 | 3 | from .ecdsakey import ECDSAKey 4 | from ecdsa.curves import curves 5 | from ecdsa.util import sigencode_der, sigdecode_der 6 | from ecdsa.keys import VerifyingKey, SigningKey, BadSignatureError 7 | from ecdsa.ellipticcurve import Point 8 | from ecdsa.der import UnexpectedDER 9 | from . import tlshashlib 10 | from .cryptomath import numBits 11 | from .compat import compatHMAC 12 | 13 | class Python_ECDSAKey(ECDSAKey): 14 | """ 15 | Concrete implementation of ECDSA object backed by python-ecdsa. 16 | 17 | Object that uses the common, abstract API of asymmetric keys 18 | that uses the python-ecdsa library for the cryptographic operations. 19 | 20 | :vartype public_key: VerifyingKey 21 | :ivar public_key: python-ecdsa object for veryfying ECDSA signatures, if 22 | `private_key` is set, it should match it (should be able to verify 23 | signatures created by it) 24 | 25 | :vartype private_key: SigningKey 26 | :ivar private_key: python-ecdsa object for creating ECDSA signatures 27 | 28 | :vartype key_type: str 29 | :ivar key_type: type of assymetric algorithm used by the keys - for this 30 | objects it is always 'ecdsa' 31 | """ 32 | 33 | def __init__(self, x, y, curve_name, secret_multiplier=None): 34 | if not curve_name: 35 | raise ValueError("curve_name must be specified") 36 | self.curve_name = curve_name 37 | 38 | for c in curves: 39 | if c.name == curve_name or c.openssl_name == curve_name: 40 | curve = c 41 | break 42 | else: 43 | raise ValueError("Curve '{0}' not supported by python-ecdsa" 44 | .format(curve_name)) 45 | 46 | self.private_key = None 47 | self.public_key = None 48 | self.key_type = "ecdsa" 49 | 50 | if secret_multiplier: 51 | self.private_key = SigningKey.from_secret_exponent( 52 | secret_multiplier, curve) 53 | 54 | if x and y: 55 | point = Point(curve.curve, x, y) 56 | self.public_key = VerifyingKey.from_public_point(point, curve) 57 | 58 | if not self.public_key: 59 | self.public_key = self.private_key.get_verifying_key() 60 | 61 | def __len__(self): 62 | return numBits(self.public_key.curve.order) 63 | 64 | def hasPrivateKey(self): 65 | return bool(self.private_key) 66 | 67 | def acceptsPassword(self): 68 | return False 69 | 70 | @staticmethod 71 | def generate(bits): 72 | raise NotImplementedError() 73 | 74 | def _sign(self, data, hAlg): 75 | func = getattr(tlshashlib, hAlg) 76 | 77 | return self.private_key.\ 78 | sign_digest_deterministic(compatHMAC(data), 79 | hashfunc=func, 80 | sigencode=sigencode_der) 81 | 82 | def _hashAndSign(self, data, hAlg): 83 | return self.private_key.sign_deterministic(compatHMAC(data), 84 | hash=getattr(tlshashlib, 85 | hAlg), 86 | sigencode=sigencode_der) 87 | 88 | def _verify(self, signature, hash_bytes): 89 | try: 90 | return self.public_key.verify_digest(compatHMAC(signature), 91 | compatHMAC(hash_bytes), 92 | sigdecode_der) 93 | # https://github.com/warner/python-ecdsa/issues/114 94 | except (BadSignatureError, UnexpectedDER, IndexError, AssertionError): 95 | return False 96 | -------------------------------------------------------------------------------- /tlslite/utils/python_eddsakey.py: -------------------------------------------------------------------------------- 1 | # Author Hubert Kario, copyright 2021 2 | 3 | from .eddsakey import EdDSAKey 4 | from ecdsa.keys import BadSignatureError 5 | from ecdsa.der import UnexpectedDER 6 | from .cryptomath import numBits 7 | from .compat import compatHMAC 8 | 9 | 10 | class Python_EdDSAKey(EdDSAKey): 11 | """ 12 | Concrete implementation of EdDSA object backed by python-ecdsa. 13 | 14 | Object that uses the common, abstract API of asymmetric keys 15 | that uses the python-ecdsa library for the cryptographic operations. 16 | 17 | :vartype public_key: VerifyingKey 18 | :ivar public_key: python-ecdsa object for veryfying EdDSA signatures, if 19 | `private_key` is set, it should match it (should be able to verify 20 | signatures created by it) 21 | 22 | :vartype private_key: SigningKey 23 | :ivar private_key: python-ecdsa object for creating EdDSA signatures 24 | 25 | :vartype key_type: str 26 | :ivar key_type: type of assymetric algorithm used by the keys - for this 27 | objects it is either "Ed25519" or "Ed448" 28 | """ 29 | 30 | def __init__(self, public_key, private_key=None): 31 | if not public_key and not private_key: 32 | raise ValueError("at least one key must be provided") 33 | if not public_key: 34 | public_key = private_key.verifying_key 35 | 36 | self.curve_name = public_key.curve.name 37 | 38 | self.private_key = private_key 39 | self.public_key = public_key 40 | self.key_type = self.curve_name 41 | 42 | def __len__(self): 43 | return numBits(self.public_key.curve.order) 44 | 45 | def hasPrivateKey(self): 46 | return bool(self.private_key) 47 | 48 | def acceptsPassword(self): 49 | return False 50 | 51 | @staticmethod 52 | def generate(bits): 53 | raise NotImplementedError() 54 | 55 | def _hashAndSign(self, data): 56 | return self.private_key.sign_deterministic(compatHMAC(data)) 57 | 58 | def _hashAndVerify(self, signature, data): 59 | try: 60 | return self.public_key.verify(compatHMAC(signature), 61 | compatHMAC(data)) 62 | # https://github.com/warner/python-ecdsa/issues/114 63 | except (BadSignatureError, UnexpectedDER, IndexError, AssertionError): 64 | return False 65 | -------------------------------------------------------------------------------- /tlslite/utils/python_rc4.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """Pure-Python RC4 implementation.""" 5 | 6 | from .rc4 import RC4 7 | from .cryptomath import * 8 | 9 | def new(key): 10 | return Python_RC4(key) 11 | 12 | class Python_RC4(RC4): 13 | def __init__(self, keyBytes): 14 | RC4.__init__(self, keyBytes, "python") 15 | S = [i for i in range(256)] 16 | j = 0 17 | for i in range(256): 18 | j = (j + S[i] + keyBytes[i % len(keyBytes)]) % 256 19 | S[i], S[j] = S[j], S[i] 20 | 21 | self.S = S 22 | self.i = 0 23 | self.j = 0 24 | 25 | def encrypt(self, plaintextBytes): 26 | ciphertextBytes = plaintextBytes[:] 27 | S = self.S 28 | i = self.i 29 | j = self.j 30 | for x in range(len(ciphertextBytes)): 31 | i = (i + 1) % 256 32 | j = (j + S[i]) % 256 33 | S[i], S[j] = S[j], S[i] 34 | t = (S[i] + S[j]) % 256 35 | ciphertextBytes[x] ^= S[t] 36 | self.i = i 37 | self.j = j 38 | return ciphertextBytes 39 | 40 | def decrypt(self, ciphertext): 41 | return self.encrypt(ciphertext) 42 | -------------------------------------------------------------------------------- /tlslite/utils/rc4.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """Abstract class for RC4.""" 5 | 6 | 7 | class RC4(object): 8 | def __init__(self, keyBytes, implementation): 9 | if len(keyBytes) < 16 or len(keyBytes) > 256: 10 | raise ValueError() 11 | self.isBlockCipher = False 12 | self.isAEAD = False 13 | self.name = "rc4" 14 | self.implementation = implementation 15 | 16 | def encrypt(self, plaintext): 17 | raise NotImplementedError() 18 | 19 | def decrypt(self, ciphertext): 20 | raise NotImplementedError() 21 | -------------------------------------------------------------------------------- /tlslite/utils/tackwrapper.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | try: 5 | from tack.structures.Tack import Tack 6 | from tack.structures.TackExtension import TackExtension 7 | from tack.tls.TlsCertificate import TlsCertificate 8 | 9 | tackpyLoaded = True 10 | except ImportError: 11 | tackpyLoaded = False 12 | -------------------------------------------------------------------------------- /tlslite/utils/tlshashlib.py: -------------------------------------------------------------------------------- 1 | # Author: Hubert Kario (c) 2015 2 | # see LICENCE file for legal information regarding use of this file 3 | 4 | """hashlib that handles FIPS mode.""" 5 | 6 | # Because we are extending the hashlib module, we need to import all its 7 | # fields to suppport the same uses 8 | # pylint: disable=unused-wildcard-import, wildcard-import 9 | from hashlib import * 10 | # pylint: enable=unused-wildcard-import, wildcard-import 11 | import hashlib 12 | 13 | 14 | def _fipsFunction(func, *args, **kwargs): 15 | """Make hash function support FIPS mode.""" 16 | try: 17 | return func(*args, **kwargs) 18 | except ValueError: 19 | return func(*args, usedforsecurity=False, **kwargs) 20 | 21 | 22 | # redefining the function is exactly what we intend to do 23 | # pylint: disable=function-redefined 24 | def md5(*args, **kwargs): 25 | """MD5 constructor that works in FIPS mode.""" 26 | return _fipsFunction(hashlib.md5, *args, **kwargs) 27 | 28 | 29 | def new(*args, **kwargs): 30 | """General constructor that works in FIPS mode.""" 31 | return _fipsFunction(hashlib.new, *args, **kwargs) 32 | # pylint: enable=function-redefined 33 | -------------------------------------------------------------------------------- /tlslite/utils/tlshmac.py: -------------------------------------------------------------------------------- 1 | # Author: Hubert Kario (c) 2019 2 | # see LICENCE file for legal information regarding use of this file 3 | 4 | """ 5 | HMAC module that works in FIPS mode. 6 | 7 | Note that this makes this code FIPS non-compliant! 8 | """ 9 | 10 | # Because we are extending the hashlib module, we need to import all its 11 | # fields to suppport the same uses 12 | from . import tlshashlib 13 | from .compat import compatHMAC 14 | try: 15 | from hmac import compare_digest 16 | __all__ = ["new", "compare_digest", "HMAC"] 17 | except ImportError: 18 | __all__ = ["new", "HMAC"] 19 | 20 | try: 21 | from hmac import HMAC, new 22 | # if we can calculate HMAC on MD5, then use the built-in HMAC 23 | # implementation 24 | _val = HMAC(b'some key', b'msg', 'md5') 25 | _val.digest() 26 | del _val 27 | except Exception: 28 | # fallback only when MD5 doesn't work 29 | class HMAC(object): 30 | """Hacked version of HMAC that works in FIPS mode even with MD5.""" 31 | 32 | def __init__(self, key, msg=None, digestmod=None): 33 | """ 34 | Initialise the HMAC and hash first portion of data. 35 | 36 | msg: data to hash 37 | digestmod: name of hash or object that be used as a hash and be cloned 38 | """ 39 | self.key = key 40 | if digestmod is None: 41 | digestmod = 'md5' 42 | if callable(digestmod): 43 | digestmod = digestmod() 44 | if not hasattr(digestmod, 'digest_size'): 45 | digestmod = tlshashlib.new(digestmod) 46 | self.block_size = digestmod.block_size 47 | self.digest_size = digestmod.digest_size 48 | self.digestmod = digestmod 49 | if len(key) > self.block_size: 50 | k_hash = digestmod.copy() 51 | k_hash.update(compatHMAC(key)) 52 | key = k_hash.digest() 53 | if len(key) < self.block_size: 54 | key = key + b'\x00' * (self.block_size - len(key)) 55 | key = bytearray(key) 56 | ipad = bytearray(b'\x36' * self.block_size) 57 | opad = bytearray(b'\x5c' * self.block_size) 58 | i_key = bytearray(i ^ j for i, j in zip(key, ipad)) 59 | self._o_key = bytearray(i ^ j for i, j in zip(key, opad)) 60 | self._context = digestmod.copy() 61 | self._context.update(compatHMAC(i_key)) 62 | if msg: 63 | self._context.update(compatHMAC(msg)) 64 | 65 | def update(self, msg): 66 | self._context.update(compatHMAC(msg)) 67 | 68 | def digest(self): 69 | i_digest = self._context.digest() 70 | o_hash = self.digestmod.copy() 71 | o_hash.update(compatHMAC(self._o_key)) 72 | o_hash.update(compatHMAC(i_digest)) 73 | return o_hash.digest() 74 | 75 | def copy(self): 76 | new = HMAC.__new__(HMAC) 77 | new.key = self.key 78 | new.digestmod = self.digestmod 79 | new.block_size = self.block_size 80 | new.digest_size = self.digest_size 81 | new._o_key = self._o_key 82 | new._context = self._context.copy() 83 | return new 84 | 85 | 86 | def new(*args, **kwargs): 87 | """General constructor that works in FIPS mode.""" 88 | return HMAC(*args, **kwargs) 89 | -------------------------------------------------------------------------------- /tlslite/utils/tripledes.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """Abstract class for 3DES.""" 5 | 6 | class TripleDES(object): 7 | def __init__(self, key, mode, IV, implementation): 8 | if len(key) != 24: 9 | raise ValueError() 10 | if mode != 2: 11 | raise ValueError() 12 | if len(IV) != 8: 13 | raise ValueError() 14 | self.isBlockCipher = True 15 | self.isAEAD = False 16 | self.block_size = 8 17 | self.implementation = implementation 18 | self.name = "3des" 19 | 20 | #CBC-Mode encryption, returns ciphertext 21 | #WARNING: *MAY* modify the input as well 22 | def encrypt(self, plaintext): 23 | assert(len(plaintext) % 8 == 0) 24 | 25 | #CBC-Mode decryption, returns plaintext 26 | #WARNING: *MAY* modify the input as well 27 | def decrypt(self, ciphertext): 28 | assert(len(ciphertext) % 8 == 0) 29 | -------------------------------------------------------------------------------- /tlslite/utils/x25519.py: -------------------------------------------------------------------------------- 1 | # Authors: 2 | # Hubert Kario (2017) 3 | # 4 | # See the LICENSE file for legal information regarding use of this file. 5 | 6 | """Handling X25519 and X448 curve based key agreement protocol.""" 7 | 8 | from .cryptomath import bytesToNumber, numberToByteArray, divceil 9 | # the names of the variables come directly from RFC 7748 so changing them 10 | # would make the code harder to audit/compare 11 | # pylint: disable=invalid-name 12 | 13 | 14 | def decodeUCoordinate(u, bits): 15 | """Function to decode the public U coordinate of X25519-family curves.""" 16 | if bits not in (255, 448): 17 | raise ValueError("Invalid number of expected bits") 18 | if bits % 8: 19 | u[-1] &= (1 << (bits % 8)) - 1 20 | return bytesToNumber(u, endian="little") 21 | 22 | 23 | def decodeScalar22519(k): 24 | """Function to decode the private K parameter of the x25519 function.""" 25 | k[0] &= 248 26 | k[31] &= 127 27 | k[31] |= 64 28 | return bytesToNumber(k, endian="little") 29 | 30 | 31 | def decodeScalar448(k): 32 | """Function to decode the private K parameter of the X448 function.""" 33 | k[0] &= 252 34 | k[55] |= 128 35 | return bytesToNumber(k, endian="little") 36 | 37 | 38 | def cswap(swap, x_2, x_3): 39 | """Conditional swap function.""" 40 | if swap: 41 | return x_3, x_2 42 | else: 43 | return x_2, x_3 44 | 45 | 46 | X25519_G = numberToByteArray(9, 32, endian="little") 47 | 48 | 49 | X25519_ORDER_SIZE = 32 50 | 51 | 52 | def x25519(k, u): 53 | """ 54 | Perform point multiplication on X25519 curve. 55 | 56 | :type k: bytearray 57 | :param k: random secret value (multiplier), should be 32 byte long 58 | 59 | :type u: bytearray 60 | :param u: curve generator or the other party key share 61 | 62 | :rtype: bytearray 63 | """ 64 | bits = 255 65 | k = decodeScalar22519(k) 66 | u = decodeUCoordinate(u, bits) 67 | 68 | a24 = 121665 69 | p = 2**255 - 19 70 | 71 | return _x25519_generic(k, u, bits, a24, p) 72 | 73 | 74 | X448_G = numberToByteArray(5, 56, endian="little") 75 | 76 | 77 | X448_ORDER_SIZE = 56 78 | 79 | 80 | def x448(k, u): 81 | """ 82 | Perform point multiplication on X448 curve. 83 | 84 | :type k: bytearray 85 | :param k: random secret value (multiplier), should be 56 bytes long 86 | 87 | :type u: bytearray 88 | :param u: curve generator or the other party key share 89 | 90 | :rtype: bytearray 91 | """ 92 | bits = 448 93 | k = decodeScalar448(k) 94 | u = decodeUCoordinate(u, bits) 95 | 96 | a24 = 39081 97 | p = 2**448 - 2**224 - 1 98 | 99 | return _x25519_generic(k, u, bits, a24, p) 100 | 101 | 102 | def _x25519_generic(k, u, bits, a24, p): 103 | """Generic Montgomery ladder implementation of the x25519 algorithm.""" 104 | x_1 = u 105 | x_2 = 1 106 | z_2 = 0 107 | x_3 = u 108 | z_3 = 1 109 | swap = 0 110 | 111 | for t in range(bits-1, -1, -1): 112 | k_t = (k >> t) & 1 113 | swap ^= k_t 114 | x_2, x_3 = cswap(swap, x_2, x_3) 115 | z_2, z_3 = cswap(swap, z_2, z_3) 116 | swap = k_t 117 | 118 | A = (x_2 + z_2) % p 119 | AA = pow(A, 2, p) 120 | B = (x_2 - z_2) % p 121 | BB = pow(B, 2, p) 122 | E = (AA - BB) % p 123 | C = (x_3 + z_3) % p 124 | D = (x_3 - z_3) % p 125 | DA = (D * A) % p 126 | CB = (C * B) % p 127 | x_3 = pow(DA + CB, 2, p) 128 | z_3 = (x_1 * pow(DA - CB, 2, p)) % p 129 | x_2 = (AA * BB) % p 130 | z_2 = (E * (AA + a24 * E)) % p 131 | 132 | x_2, x_3 = cswap(swap, x_2, x_3) 133 | z_2, z_3 = cswap(swap, z_2, z_3) 134 | ret = (x_2 * pow(z_2, p - 2, p)) % p 135 | return numberToByteArray(ret, divceil(bits, 8), endian="little") 136 | # pylint: enable=invalid-name 137 | -------------------------------------------------------------------------------- /tlslite/x509certchain.py: -------------------------------------------------------------------------------- 1 | # Author: Trevor Perrin 2 | # See the LICENSE file for legal information regarding use of this file. 3 | 4 | """Class representing an X.509 certificate chain.""" 5 | 6 | from .utils import cryptomath 7 | from .utils.tackwrapper import * 8 | from .utils.pem import * 9 | from .x509 import X509 10 | 11 | class X509CertChain(object): 12 | """This class represents a chain of X.509 certificates. 13 | 14 | :vartype x509List: list 15 | :ivar x509List: A list of :py:class:`tlslite.x509.X509` instances, 16 | starting with the end-entity certificate and with every 17 | subsequent certificate certifying the previous. 18 | """ 19 | 20 | def __init__(self, x509List=None): 21 | """Create a new X509CertChain. 22 | 23 | :type x509List: list 24 | :param x509List: A list of :py:class:`tlslite.x509.X509` instances, 25 | starting with the end-entity certificate and with every 26 | subsequent certificate certifying the previous. 27 | """ 28 | if x509List: 29 | self.x509List = x509List 30 | else: 31 | self.x509List = [] 32 | 33 | def __hash__(self): 34 | """Return hash of the object.""" 35 | return hash(tuple(self.x509List)) 36 | 37 | def __eq__(self, other): 38 | """Compare objects with each-other.""" 39 | if not hasattr(other, "x509List"): 40 | return NotImplemented 41 | return self.x509List == other.x509List 42 | 43 | def __ne__(self, other): 44 | """Compare object for inequality.""" 45 | if not hasattr(other, "x509List"): 46 | return NotImplemented 47 | return self.x509List != other.x509List 48 | 49 | def parsePemList(self, s): 50 | """Parse a string containing a sequence of PEM certs. 51 | 52 | Raise a SyntaxError if input is malformed. 53 | """ 54 | x509List = [] 55 | bList = dePemList(s, "CERTIFICATE") 56 | for b in bList: 57 | x509 = X509() 58 | x509.parseBinary(b) 59 | x509List.append(x509) 60 | self.x509List = x509List 61 | 62 | def getNumCerts(self): 63 | """Get the number of certificates in this chain. 64 | 65 | :rtype: int 66 | """ 67 | return len(self.x509List) 68 | 69 | def getEndEntityPublicKey(self): 70 | """Get the public key from the end-entity certificate. 71 | 72 | :rtype: ~tlslite.utils.rsakey.RSAKey` 73 | """ 74 | if self.getNumCerts() == 0: 75 | raise AssertionError() 76 | return self.x509List[0].publicKey 77 | 78 | def getFingerprint(self): 79 | """Get the hex-encoded fingerprint of the end-entity certificate. 80 | 81 | :rtype: str 82 | :returns: A hex-encoded fingerprint. 83 | """ 84 | if self.getNumCerts() == 0: 85 | raise AssertionError() 86 | return self.x509List[0].getFingerprint() 87 | 88 | def checkTack(self, tack): 89 | if self.x509List: 90 | tlsCert = TlsCertificate(self.x509List[0].bytes) 91 | if tlsCert.matches(tack): 92 | return True 93 | return False 94 | 95 | def getTackExt(self): 96 | """Get the TACK and/or Break Sigs from a TACK Cert in the chain.""" 97 | tackExt = None 98 | # Search list in backwards order 99 | for x509 in self.x509List[::-1]: 100 | tlsCert = TlsCertificate(x509.bytes) 101 | if tlsCert.tackExt: 102 | if tackExt: 103 | raise SyntaxError("Multiple TACK Extensions") 104 | else: 105 | tackExt = tlsCert.tackExt 106 | return tackExt 107 | 108 | -------------------------------------------------------------------------------- /unit_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlsfuzzer/tlslite-ng/6805bcb8e6afb0d22b2f5b24e97ba21c525d4d69/unit_tests/__init__.py -------------------------------------------------------------------------------- /unit_tests/mocksock.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | import socket 6 | import errno 7 | class MockSocket(socket.socket): 8 | def __init__(self, buf, maxRet=None, maxWrite=None, blockEveryOther=False): 9 | # current position in read buffer (buf) 10 | self.index = 0 11 | # read buffer 12 | self.buf = buf 13 | # write buffer (data sent from application, to be asserted by test) 14 | self.sent = [] 15 | self.closed = False 16 | # maximum number of bytes that socket will read/return at a time 17 | self.maxRet = maxRet 18 | # maximum number of bytes that socket will write at a time 19 | self.maxWrite = maxWrite 20 | # make socket rise errno.EWOULDBLOCK every other read or write 21 | self.blockEveryOther = blockEveryOther 22 | # if next read will be blocked 23 | self.blockRead = False 24 | # if next write will be blocked 25 | self.blockWrite = False 26 | 27 | def __repr__(self): 28 | return "MockSocket(index={0}, buf={1!r}, sent={2!r})".format( 29 | self.index, self.buf, self.sent) 30 | 31 | def recv(self, size): 32 | if self.closed: 33 | raise ValueError("Read from closed socket") 34 | 35 | # simulate a socket with full buffers, make it rise "Would block" 36 | # every other call 37 | if self.blockEveryOther: 38 | if self.blockRead: 39 | self.blockRead = False 40 | raise socket.error(errno.EWOULDBLOCK) 41 | else: 42 | self.blockRead = True 43 | 44 | # return empty array if the caller asked for no data 45 | if size == 0: 46 | return bytearray(0) 47 | 48 | # limit returned data (if set) 49 | # this will cause the socket to return just maxRet bytes, even if it 50 | # has more in buf or was asked to return more in this call 51 | if self.maxRet is not None and self.maxRet < size: 52 | size = self.maxRet 53 | 54 | # don't allow reading past array end 55 | if len(self.buf[self.index:]) == 0: 56 | raise socket.error(errno.EWOULDBLOCK) 57 | # if asked for more than we have prepared, return just as much as we 58 | # have 59 | elif len(self.buf[self.index:]) < size: 60 | ret = self.buf[self.index:] 61 | self.index = len(self.buf) 62 | return ret 63 | # regular call, return as much as was asked for 64 | else: 65 | ret = self.buf[self.index:self.index+size] 66 | self.index+=size 67 | return ret 68 | 69 | def send(self, data): 70 | if self.closed: 71 | raise ValueError("Write to closed socket") 72 | 73 | # simulate a socket with full buffer, raise "Would Block" every other 74 | # call 75 | if self.blockEveryOther: 76 | if self.blockWrite: 77 | self.blockWrite = False 78 | raise socket.error(errno.EWOULDBLOCK) 79 | else: 80 | self.blockWrite = True 81 | 82 | # regular write, just append to list of performed writes 83 | if self.maxWrite is None or len(data) < self.maxWrite: 84 | self.sent.append(data) 85 | return len(data) 86 | 87 | # simulate a socket that won't write more data that it can 88 | # (e.g. because the simulated buffers are mostly full) 89 | self.sent.append(data[:self.maxWrite]) 90 | return self.maxWrite 91 | 92 | def close(self): 93 | self.closed = True 94 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_dh.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import unittest2 as unittest 4 | except ImportError: 5 | import unittest 6 | 7 | try: 8 | import mock 9 | from mock import call 10 | except ImportError: 11 | import unittest.mock as mock 12 | from unittest.mock import call 13 | 14 | from tlslite.dh import parse, parseBinary 15 | 16 | 17 | class TestParse(unittest.TestCase): 18 | def test_pem(self): 19 | data = ( 20 | "-----BEGIN DH PARAMETERS-----\n" 21 | "MIGHAoGBAIj4luOWCbrxyrPJOAhn4tG6jO8F1AaiiBBm1eAEEdQTKuhdV1uBBQDL\n" 22 | "ve3O/ZrR9x+ILs9PIUgZMSFP8X5ldBAFjEIoTmfneSB4TcKN27gpiRFZK0eFTi9F\n" 23 | "mofd/BgLWrNAHAOhBG7V6Gz7lZaFOxhxGTH+Lx6HxiTM7+RsLMSLAgEC\n" 24 | "-----END DH PARAMETERS-----\n") 25 | 26 | g, p = parse(data) 27 | 28 | self.assertEqual(p, int("88F896E39609BAF1CAB3C9380867E2D1BA8CEF05D406" 29 | "A2881066D5E00411D4132AE85D575B810500CBBDEDCEFD9AD1F71F882ECF4F21" 30 | "481931214FF17E657410058C42284E67E77920784DC28DDBB8298911592B4785" 31 | "4E2F459A87DDFC180B5AB3401C03A1046ED5E86CFB9596853B18711931FE2F1E" 32 | "87C624CCEFE46C2CC48B", 16)) 33 | self.assertEqual(g, 2) 34 | 35 | def test_der(self): 36 | data = bytearray( 37 | b"\x30\x81\x87\x02\x81\x81\x00\x88\xf8\x96\xe3\x96\x09\xba\xf1\xca" 38 | b"\xb3\xc9\x38\x08\x67\xe2\xd1\xba\x8c\xef\x05\xd4\x06\xa2\x88\x10" 39 | b"\x66\xd5\xe0\x04\x11\xd4\x13\x2a\xe8\x5d\x57\x5b\x81\x05\x00\xcb" 40 | b"\xbd\xed\xce\xfd\x9a\xd1\xf7\x1f\x88\x2e\xcf\x4f\x21\x48\x19\x31" 41 | b"\x21\x4f\xf1\x7e\x65\x74\x10\x05\x8c\x42\x28\x4e\x67\xe7\x79\x20" 42 | b"\x78\x4d\xc2\x8d\xdb\xb8\x29\x89\x11\x59\x2b\x47\x85\x4e\x2f\x45" 43 | b"\x9a\x87\xdd\xfc\x18\x0b\x5a\xb3\x40\x1c\x03\xa1\x04\x6e\xd5\xe8" 44 | b"\x6c\xfb\x95\x96\x85\x3b\x18\x71\x19\x31\xfe\x2f\x1e\x87\xc6\x24" 45 | b"\xcc\xef\xe4\x6c\x2c\xc4\x8b\x02\x01\x02") 46 | 47 | g, p = parse(data) 48 | 49 | self.assertEqual(p, int("88F896E39609BAF1CAB3C9380867E2D1BA8CEF05D406" 50 | "A2881066D5E00411D4132AE85D575B810500CBBDEDCEFD9AD1F71F882ECF4F21" 51 | "481931214FF17E657410058C42284E67E77920784DC28DDBB8298911592B4785" 52 | "4E2F459A87DDFC180B5AB3401C03A1046ED5E86CFB9596853B18711931FE2F1E" 53 | "87C624CCEFE46C2CC48B", 16)) 54 | self.assertEqual(g, 2) 55 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_handshakehashes.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | 12 | from tlslite.handshakehashes import HandshakeHashes 13 | 14 | class TestHandshakeHashes(unittest.TestCase): 15 | def test___init__(self): 16 | hh = HandshakeHashes() 17 | 18 | self.assertIsNotNone(hh) 19 | 20 | def test_update(self): 21 | hh = HandshakeHashes() 22 | hh.update(bytearray(10)) 23 | 24 | def test_update_with_str(self): 25 | hh = HandshakeHashes() 26 | hh.update(b'text') 27 | 28 | def test_digest_SSL3(self): 29 | hh = HandshakeHashes() 30 | 31 | self.assertEqual(bytearray( 32 | b'\xb5Q\x15\xa4\xcd\xff\xfdF\xa6\x9c\xe2\x0f\x83~\x948\xc3\xb5'\ 33 | b'\xc1\x8d\xb6|\x10n@a\x97\xccG\xfeI\xa8s T\\'), 34 | hh.digestSSL(bytearray(48), b'')) 35 | 36 | def test_digest_TLS1_0(self): 37 | hh = HandshakeHashes() 38 | 39 | self.assertEqual( 40 | b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~\xda'\ 41 | b'9\xa3\xee^kK\r2U\xbf\xef\x95`\x18\x90\xaf\xd8\x07\t', 42 | hh.digest()) 43 | 44 | def test_copy(self): 45 | hh = HandshakeHashes() 46 | hh.update(b'text') 47 | 48 | hh2 = hh.copy() 49 | 50 | self.assertEqual(hh2.digest(), hh.digest()) 51 | 52 | def test_digest_md5(self): 53 | hh = HandshakeHashes() 54 | 55 | self.assertEqual( 56 | b"\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~", 57 | hh.digest('md5')) 58 | 59 | def test_digest_sha1(self): 60 | hh = HandshakeHashes() 61 | 62 | self.assertEqual( 63 | b"\xda9\xa3\xee^kK\r2U\xbf\xef\x95`\x18\x90\xaf\xd8\x07\t", 64 | hh.digest('sha1')) 65 | 66 | def test_digest_sha256(self): 67 | hh = HandshakeHashes() 68 | 69 | self.assertEqual( 70 | b"\xe3\xb0\xc4B\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99o\xb9$'\xae"\ 71 | b"A\xe4d\x9b\x93L\xa4\x95\x99\x1bxR\xb8U", 72 | hh.digest('sha256')) 73 | 74 | def test_digest_sha224(self): 75 | hh = HandshakeHashes() 76 | 77 | self.assertEqual(( 78 | b'\xd1J\x02\x8c*:+\xc9Ga\x02\xbb(\x824\xc4\x15\xa2\xb0' 79 | b'\x1f\x82\x8e\xa6*\xc5\xb3\xe4/'), 80 | hh.digest('sha224')) 81 | 82 | def test_digest_sha512(self): 83 | hh = HandshakeHashes() 84 | 85 | self.assertEqual(( 86 | b'\xcf\x83\xe15~\xef\xb8\xbd\xf1T(P\xd6m\x80\x07\xd6 ' 87 | b'\xe4\x05\x0bW\x15\xdc\x83\xf4\xa9!\xd3l\xe9\xceG\xd0' 88 | b'\xd1<]\x85\xf2\xb0\xff\x83\x18\xd2\x87~\xec/c\xb91' 89 | b'\xbdGAz\x81\xa582z\xf9\'\xda>'), 90 | hh.digest('sha512')) 91 | 92 | def test_digest_with_partial_writes(self): 93 | hh = HandshakeHashes() 94 | hh.update(b'text') 95 | 96 | hh2 = HandshakeHashes() 97 | hh2.update(b'te') 98 | hh2.update(b'xt') 99 | 100 | self.assertEqual(hh.digest(), hh2.digest()) 101 | 102 | def test_digest_with_invalid_hash(self): 103 | hh = HandshakeHashes() 104 | 105 | with self.assertRaises(ValueError): 106 | hh.digest('md2') 107 | 108 | def test_digest_with_repeated_calls(self): 109 | hh = HandshakeHashes() 110 | hh.update(b'text') 111 | 112 | self.assertEqual(hh.digest(), hh.digest()) 113 | 114 | hh.update(b'ext') 115 | 116 | self.assertEqual(hh.digest('sha256'), hh.digest('sha256')) 117 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_session.py: -------------------------------------------------------------------------------- 1 | # compatibility with Python 2.6, for that we need unittest2 package, 2 | # which is not available on 3.3 or 3.4 3 | try: 4 | import unittest2 as unittest 5 | except ImportError: 6 | import unittest 7 | 8 | from tlslite.session import Session 9 | 10 | class TestSession(unittest.TestCase): 11 | 12 | def test___init__(self): 13 | session = Session() 14 | 15 | self.assertIsNotNone(session) 16 | self.assertFalse(session.resumable) 17 | self.assertFalse(session.encryptThenMAC) 18 | self.assertFalse(session.extendedMasterSecret) 19 | 20 | def test_create(self): 21 | session = Session() 22 | session.create(masterSecret=1, 23 | sessionID=2, 24 | cipherSuite=3, 25 | srpUsername=4, 26 | clientCertChain=5, 27 | serverCertChain=6, 28 | tackExt=7, 29 | tackInHelloExt=8, 30 | serverName=9) 31 | 32 | self.assertEqual(session.masterSecret, 1) 33 | self.assertEqual(session.sessionID, 2) 34 | self.assertEqual(session.cipherSuite, 3) 35 | self.assertEqual(session.srpUsername, 4) 36 | self.assertEqual(session.clientCertChain, 5) 37 | self.assertEqual(session.serverCertChain, 6) 38 | self.assertEqual(session.tackExt, 7) 39 | self.assertEqual(session.tackInHelloExt, 8) 40 | self.assertEqual(session.serverName, 9) 41 | 42 | self.assertTrue(session.resumable) 43 | self.assertFalse(session.encryptThenMAC) 44 | self.assertFalse(session.extendedMasterSecret) 45 | 46 | def test_create_with_new_additions(self): 47 | session = Session() 48 | session.create(1, 2, 3, 4, 5, 6, 7, 8, 9, 49 | encryptThenMAC=10, 50 | extendedMasterSecret=11) 51 | 52 | self.assertEqual(session.encryptThenMAC, 10) 53 | self.assertEqual(session.extendedMasterSecret, 11) 54 | 55 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_sessioncache.py: -------------------------------------------------------------------------------- 1 | # compatibility with Python 2.6, for that we need unittest2 package, 2 | # which is not available on 3.3 or 3.4 3 | try: 4 | import unittest2 as unittest 5 | except ImportError: 6 | import unittest 7 | 8 | from tlslite.sessioncache import SessionCache 9 | 10 | class TestGetAttributeAfterPurge(unittest.TestCase): 11 | """ 12 | This tests the following scenario 13 | 14 | Add an entry to the session cache 15 | wait until the cache should have expired 16 | fetch the entry for the session cache. 17 | 18 | """ 19 | 20 | def setUp(self): 21 | # set maxAge to 0 to have an immediate expire 22 | self.session_cache = SessionCache(maxAge=0) 23 | 24 | def test_fetch_after_expire(self): 25 | key = bytearray(b'hello world') 26 | self.session_cache[key] = "42" 27 | with self.assertRaises(KeyError): 28 | self.session_cache[key] 29 | 30 | class TestFillLinkedList(unittest.TestCase): 31 | """ check what happens if the linked list gets full 32 | """ 33 | 34 | def setUp(self): 35 | self.session_cache = SessionCache(maxEntries = 10) 36 | 37 | def test_fill_linked_list(self): 38 | """this test should not throw an exception""" 39 | for i in range(20): 40 | key = bytearray(b'prefill-') + bytearray(str(i), "ascii") 41 | self.session_cache[key] = "forty-two" 42 | 43 | 44 | if __name__ == '__main__': 45 | unittest.main() 46 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_signed.py: -------------------------------------------------------------------------------- 1 | # Author: Anna Khaitovich (c) 2018 2 | # see LICENCE file for legal information regarding use of this file 3 | 4 | # compatibility with Python 2.6, for that we need unittest2 package, 5 | # which is not available on 3.3 or 3.4 6 | try: 7 | import unittest2 as unittest 8 | except ImportError: 9 | import unittest 10 | 11 | from tlslite.signed import SignatureSettings, SignedObject, RSA_SIGNATURE_HASHES, RSA_SCHEMES 12 | 13 | 14 | class TestSignatureSettings(unittest.TestCase): 15 | def test_signature_settings_validate(self): 16 | settings = SignatureSettings() 17 | validated = settings.validate() 18 | self.assertEqual(validated.min_key_size, 1023) 19 | self.assertEqual(validated.max_key_size, 8193) 20 | self.assertEqual(validated.rsa_sig_hashes, RSA_SIGNATURE_HASHES) 21 | self.assertEqual(validated.rsa_schemes, RSA_SCHEMES) 22 | 23 | def test_signature_settings_min_key_size_small(self): 24 | settings = SignatureSettings(min_key_size=256) 25 | with self.assertRaises(ValueError) as ctx: 26 | settings.validate() 27 | self.assertIn("min_key_size too small", str(ctx.exception)) 28 | 29 | def test_signature_settings_min_key_size_large(self): 30 | settings = SignatureSettings(min_key_size=17000) 31 | with self.assertRaises(ValueError) as ctx: 32 | settings.validate() 33 | self.assertIn("min_key_size too large", str(ctx.exception)) 34 | 35 | def test_signature_settings_max_key_size_small(self): 36 | settings = SignatureSettings(max_key_size=256) 37 | with self.assertRaises(ValueError) as ctx: 38 | settings.validate() 39 | self.assertIn("max_key_size too small", str(ctx.exception)) 40 | 41 | def test_signature_settings_max_key_size_large(self): 42 | settings = SignatureSettings(max_key_size=17000) 43 | with self.assertRaises(ValueError) as ctx: 44 | settings.validate() 45 | self.assertIn("max_key_size too large", str(ctx.exception)) 46 | 47 | def test_signature_settings_min_key_bigger_max_key(self): 48 | settings = SignatureSettings(min_key_size=2048, max_key_size=1024) 49 | with self.assertRaises(ValueError) as ctx: 50 | settings.validate() 51 | self.assertIn("max_key_size smaller than min_key_size", str(ctx.exception)) 52 | 53 | def test_signature_settings_invalid_sig_alg(self): 54 | settings = SignatureSettings(rsa_sig_hashes=list(['sha1', 'sha128', 'sha129'])) 55 | with self.assertRaises(ValueError) as ctx: 56 | settings.validate() 57 | self.assertIn("Following signature algorithms are not allowed: sha128, sha129", 58 | str(ctx.exception)) 59 | # verify_signature method testing is happening in the test_tlslite_ocsp.py 60 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_aes_split.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, Alexander Sosedkin 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | 12 | import sys 13 | 14 | from hypothesis import given, assume, settings 15 | from hypothesis.strategies import binary, integers, tuples 16 | 17 | from tlslite.utils import cryptomath 18 | 19 | import tlslite.utils.python_aes 20 | py_aes = lambda key, iv: tlslite.utils.python_aes.new(key, 2, iv) 21 | 22 | 23 | HYP_SETTINGS = {'deadline': None} if sys.version_info > (2, 7) else {} 24 | 25 | 26 | class TestAES(unittest.TestCase): 27 | _given = given(binary(min_size=24, max_size=24), # key 28 | binary(min_size=16, max_size=16), # iv 29 | binary(min_size=13*16, max_size=13*16), # plaintext 30 | (tuples(integers(0, 13), integers(0, 13)) # split points 31 | .filter(lambda split_pts: split_pts[0] <= split_pts[1]) 32 | .map(lambda lengths: [i * 16 for i in lengths]))) 33 | 34 | def split_test(self, key, iv, plaintext, split_points, make_impl=py_aes): 35 | i, j = split_points 36 | 37 | ciphertext = make_impl(key, iv).encrypt(plaintext) 38 | self.assertEqual(make_impl(key, iv).decrypt(ciphertext), plaintext) 39 | 40 | impl = make_impl(key, iv) 41 | pl1, pl2, pl3 = plaintext[:i], plaintext[i:j], plaintext[j:] 42 | ci1, ci2, ci3 = impl.encrypt(pl1), impl.encrypt(pl2), impl.encrypt(pl3) 43 | self.assertEqual(ci1 + ci2 + ci3, ciphertext) 44 | 45 | impl = make_impl(key, iv) 46 | pl1, pl2, pl3 = impl.decrypt(ci1), impl.decrypt(ci2), impl.decrypt(ci3) 47 | self.assertEqual(pl1 + pl2 + pl3, plaintext) 48 | 49 | return ciphertext 50 | 51 | @_given 52 | @settings(**HYP_SETTINGS) 53 | def test_python(self, key, iv, plaintext, split_points): 54 | self.split_test(key, iv, plaintext, split_points) 55 | 56 | @unittest.skipIf(not cryptomath.m2cryptoLoaded, "requires M2Crypto") 57 | @_given 58 | @settings(**HYP_SETTINGS) 59 | def test_python_vs_mcrypto(self, key, iv, plaintext, split_points): 60 | import tlslite.utils.openssl_aes 61 | m2_aes = lambda k, iv: tlslite.utils.openssl_aes.new(k, 2, iv) 62 | 63 | py_res = self.split_test(key, iv, plaintext, split_points, py_aes) 64 | m2_res = self.split_test(key, iv, plaintext, split_points, m2_aes) 65 | self.assertEqual(py_res, m2_res) 66 | 67 | @unittest.skipIf(not cryptomath.pycryptoLoaded, "requires pycrypto") 68 | @_given 69 | @settings(**HYP_SETTINGS) 70 | def test_python_vs_pycrypto(self, key, iv, plaintext, split_points): 71 | import tlslite.utils.pycrypto_aes 72 | pc_aes = lambda k, iv: tlslite.utils.pycrypto_aes.new(k, 2, iv) 73 | 74 | py_res = self.split_test(key, iv, plaintext, split_points, py_aes) 75 | pc_res = self.split_test(key, iv, plaintext, split_points, pc_aes) 76 | self.assertEqual(py_res, pc_res) 77 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_asn1.py: -------------------------------------------------------------------------------- 1 | # Author: Anna Khaitovich (c) 2017 2 | # see LICENCE file for legal information regarding use of this file 3 | 4 | # compatibility with Python 2.6, for that we need unittest2 package, 5 | # which is not available on 3.3 or 3.4 6 | try: 7 | import unittest2 as unittest 8 | except ImportError: 9 | import unittest 10 | 11 | from tlslite.utils.compat import a2b_base64 12 | from tlslite.utils.asn1parser import ASN1Type, ASN1Parser 13 | 14 | class TestASN1Parser(unittest.TestCase): 15 | def test_integer(self): 16 | # universal, primitive, integer 17 | p = ASN1Parser(a2b_base64('AgEB')) 18 | self.assertEqual(0, p.type.tag_class) 19 | self.assertEqual(0, p.type.is_primitive) 20 | self.assertEqual(2, p.type.tag_id) 21 | self.assertEqual(bytearray(b'\x01'), p.value) 22 | 23 | def test_bitstring(self): 24 | # universal, primitive, bit string 25 | p = ASN1Parser(a2b_base64('AwUAQUJDRA==')) 26 | self.assertEqual(0, p.type.tag_class) 27 | self.assertEqual(0, p.type.is_primitive) 28 | self.assertEqual(3, p.type.tag_id) 29 | self.assertEqual(bytearray(b'\x00ABCD'), p.value) 30 | 31 | def test_utctime(self): 32 | # universal, primitive, utc time 33 | p = ASN1Parser(a2b_base64('FwsxODEyMzEyMzU5Wg==')) 34 | self.assertEqual(0, p.type.tag_class) 35 | self.assertEqual(0, p.type.is_primitive) 36 | self.assertEqual(23, p.type.tag_id) 37 | self.assertEqual(bytearray(b'1812312359Z'), p.value) 38 | 39 | def test_sequence(self): 40 | # universal, non-primitive, sequence 41 | p = ASN1Parser(a2b_base64('MAMBAf8=')) 42 | self.assertEqual(0, p.type.tag_class) 43 | self.assertEqual(1, p.type.is_primitive) 44 | self.assertEqual(16, p.type.tag_id) 45 | self.assertEqual(bytearray(b'\x01\x01\xff'), p.value) 46 | 47 | def test_explicit_string(self): 48 | # context-specific, non-primitive, explicit string 49 | p = ASN1Parser(a2b_base64('v5oFFAwSc29tZSByYW5kb20gc3RyaW5n')) 50 | self.assertEqual(2, p.type.tag_class) 51 | self.assertEqual(1, p.type.is_primitive) 52 | self.assertEqual(3333, p.type.tag_id) 53 | self.assertEqual(bytearray(b'\x0c\x12some random string'), p.value) 54 | 55 | if __name__ == '__main__': 56 | unittest.main() 57 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_compat.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | 12 | from tlslite.utils.compat import remove_whitespace 13 | 14 | class TestRemoveWhitespace(unittest.TestCase): 15 | def test_no_remove(self): 16 | text = "somestring" 17 | self.assertEqual(text, remove_whitespace(text)) 18 | 19 | def test_newline(self): 20 | text = """some 21 | thing""" 22 | self.assertEqual("something", remove_whitespace(text)) 23 | 24 | def test_remove_begginning(self): 25 | text = " some thing " 26 | self.assertEqual("something", remove_whitespace(text)) 27 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_compression.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, George Pantelakis 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | 12 | from tlslite.utils.compression import compression_algo_impls, \ 13 | choose_compression_send_algo 14 | from tlslite.errors import TLSDecodeError 15 | 16 | class TestCompression(unittest.TestCase): 17 | def setUp(self): 18 | class DummyExtension(): 19 | algorithms = None 20 | 21 | def change_algos(self, algos): 22 | self.algorithms = algos 23 | 24 | self.extension = DummyExtension() 25 | 26 | def test_compression_algo_impls(self): 27 | self.assertIsNotNone(compression_algo_impls) 28 | self.assertIn("brotli_compress", compression_algo_impls) 29 | self.assertIn("brotli_decompress", compression_algo_impls) 30 | self.assertIn("brotli_accepts_limit", compression_algo_impls) 31 | self.assertIn("zstd_compress", compression_algo_impls) 32 | self.assertIn("zstd_decompress", compression_algo_impls) 33 | self.assertIn("zstd_accepts_limit", compression_algo_impls) 34 | 35 | def test_choose_compression_send_algo_sanity(self): 36 | self.extension.change_algos([1]) 37 | algo = choose_compression_send_algo((3, 4), self.extension, ['zlib']) 38 | self.assertEqual(algo, 1) 39 | 40 | def test_choose_compression_send_algo_previous_tls_version(self): 41 | self.extension.change_algos([1]) 42 | algo = choose_compression_send_algo((3, 2), self.extension, ['zlib']) 43 | self.assertIsNone(algo) 44 | 45 | def test_choose_compression_send_algo_no_tls_version(self): 46 | self.extension.change_algos([1]) 47 | algo = choose_compression_send_algo(None, self.extension, ['zlib']) 48 | self.assertIsNone(algo) 49 | 50 | def test_choose_compression_send_algo_choose_first_common(self): 51 | self.extension.change_algos([1, 2]) 52 | algo = choose_compression_send_algo( 53 | (3, 4), self.extension, ['zlib', 'brotli']) 54 | self.assertEqual(algo, 1) 55 | 56 | def test_choose_compression_send_algo_empty_extension_algos(self): 57 | self.extension.change_algos([]) 58 | with self.assertRaises(TLSDecodeError): 59 | choose_compression_send_algo((3, 4), self.extension, ['zlib']) 60 | 61 | def test_choose_compression_send_algo_empty_accepted_algos(self): 62 | self.extension.change_algos([1]) 63 | algo = choose_compression_send_algo((3, 4), self.extension, []) 64 | self.assertIsNone(algo) 65 | 66 | def test_choose_compression_send_algo_none_extension_algos(self): 67 | self.extension.change_algos(None) 68 | with self.assertRaises(TLSDecodeError): 69 | choose_compression_send_algo((3, 4), self.extension, ['zlib']) 70 | 71 | def test_choose_compression_send_algo_no_common_algos(self): 72 | self.extension.change_algos([2]) 73 | algo = choose_compression_send_algo((3, 4), self.extension, ['zlib']) 74 | self.assertIsNone(algo) 75 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_cryptomath_m2crypto.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | try: 12 | import mock 13 | from mock import call 14 | except ImportError: 15 | import unittest.mock as mock 16 | from unittest.mock import call 17 | import sys 18 | try: 19 | # Python 2 20 | reload 21 | except NameError: 22 | try: 23 | # Python >= 3.4 24 | from importlib import reload 25 | except ImportError: 26 | # Python <= 3.3 27 | from imp import reload 28 | try: 29 | import __builtin__ as builtins 30 | except ImportError: 31 | import builtins 32 | 33 | real_open = builtins.open 34 | 35 | class magic_open(object): 36 | def __init__(self, *args, **kwargs): 37 | self.args = args 38 | self.kwargs = kwargs 39 | 40 | def __enter__(self): 41 | if self.args[0] == '/proc/sys/crypto/fips_enabled': 42 | m = mock.MagicMock() 43 | m.read.return_value = '1' 44 | self.f = m 45 | return m 46 | else: 47 | self.f = real_open(*self.args, **self.kwargs) 48 | return self.f 49 | 50 | def __exit__(self, exc_type, exc_value, exc_traceback): 51 | self.f.close() 52 | 53 | class magic_open_error(object): 54 | def __init__(self, *args, **kwargs): 55 | self.args = args 56 | self.kwargs = kwargs 57 | 58 | def __enter__(self): 59 | if self.args[0] == '/proc/sys/crypto/fips_enabled': 60 | m = mock.MagicMock() 61 | self.f = m 62 | raise IOError(12) 63 | else: 64 | self.f = real_open(*self.args, **self.kwargs) 65 | return self.f 66 | 67 | def __exit__(self, exc_type, exc_value, exc_traceback): 68 | self.f.close() 69 | 70 | 71 | class TestM2CryptoLoaded(unittest.TestCase): 72 | def test_import_without_m2crypto(self): 73 | with mock.patch.dict('sys.modules', {'M2Crypto': None}): 74 | import tlslite.utils.cryptomath 75 | reload(tlslite.utils.cryptomath) 76 | from tlslite.utils.cryptomath import m2cryptoLoaded 77 | self.assertFalse(m2cryptoLoaded) 78 | 79 | def test_import_with_m2crypto(self): 80 | fake_m2 = mock.MagicMock() 81 | 82 | with mock.patch.dict('sys.modules', {'M2Crypto': fake_m2}): 83 | import tlslite.utils.cryptomath 84 | reload(tlslite.utils.cryptomath) 85 | from tlslite.utils.cryptomath import m2cryptoLoaded 86 | self.assertTrue(m2cryptoLoaded) 87 | 88 | def test_import_with_m2crypto_in_fips_mode(self): 89 | fake_m2 = mock.MagicMock() 90 | 91 | with mock.patch.dict('sys.modules', {'M2Crypto': fake_m2}): 92 | with mock.patch.object(builtins, 'open', magic_open): 93 | import tlslite.utils.cryptomath 94 | reload(tlslite.utils.cryptomath) 95 | from tlslite.utils.cryptomath import m2cryptoLoaded 96 | self.assertFalse(m2cryptoLoaded) 97 | 98 | def test_import_with_m2crypto_in_container(self): 99 | fake_m2 = mock.MagicMock() 100 | 101 | with mock.patch.dict('sys.modules', {'M2Crypto': fake_m2}): 102 | with mock.patch.object(builtins, 'open', magic_open_error): 103 | import tlslite.utils.cryptomath 104 | reload(tlslite.utils.cryptomath) 105 | from tlslite.utils.cryptomath import m2cryptoLoaded 106 | self.assertTrue(m2cryptoLoaded) 107 | 108 | @classmethod 109 | def tearDownClass(cls): 110 | import tlslite.utils.cryptomath 111 | reload(tlslite.utils.cryptomath) 112 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_dns_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | from tlslite.utils.dns_utils import is_valid_hostname 12 | 13 | class TestIsValidHostname(unittest.TestCase): 14 | def test_example(self): 15 | self.assertTrue(is_valid_hostname(b'example.com')) 16 | 17 | def test_ip(self): 18 | self.assertFalse(is_valid_hostname(b'192.168.0.1')) 19 | 20 | def test_ip_dot(self): 21 | self.assertFalse(is_valid_hostname(b'192.168.0.1.')) 22 | 23 | def test_ip_lookalike_hostname(self): 24 | self.assertTrue(is_valid_hostname(b'192.168.example.com')) 25 | 26 | def test_with_tld_dot(self): 27 | self.assertTrue(is_valid_hostname(b'example.com.')) 28 | 29 | def test_hostname_alone(self): 30 | self.assertTrue(is_valid_hostname(b'localhost')) 31 | 32 | def test_very_long_hostname(self): 33 | self.assertFalse(is_valid_hostname(b'a' * 250 + b'.example.com')) 34 | 35 | def test_very_long_host(self): 36 | self.assertFalse(is_valid_hostname(b'a' * 70 + b'.example.com')) 37 | 38 | def test_long_hostname(self): 39 | self.assertTrue(is_valid_hostname(b'a' * 60 + b'.example.com')) 40 | 41 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_ecc.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2014, Hubert Kario 3 | # 4 | # See the LICENSE file for legal information regarding use of this file. 5 | 6 | # compatibility with Python 2.6, for that we need unittest2 package, 7 | # which is not available on 3.3 or 3.4 8 | try: 9 | import unittest2 as unittest 10 | except ImportError: 11 | import unittest 12 | 13 | from tlslite.utils.ecc import getCurveByName,getPointByteSize 14 | import ecdsa 15 | 16 | class TestCurveLookup(unittest.TestCase): 17 | def test_with_correct_name(self): 18 | curve = getCurveByName('secp256r1') 19 | self.assertIs(curve, ecdsa.NIST256p) 20 | 21 | def test_with_invalid_name(self): 22 | with self.assertRaises(ValueError): 23 | getCurveByName('NIST256p') 24 | 25 | class TestGetPointByteSize(unittest.TestCase): 26 | def test_with_curve(self): 27 | self.assertEqual(getPointByteSize(ecdsa.NIST256p), 32) 28 | 29 | def test_with_point(self): 30 | self.assertEqual(getPointByteSize(ecdsa.NIST384p.generator * 10), 48) 31 | 32 | def test_with_invalid_argument(self): 33 | with self.assertRaises(ValueError): 34 | getPointByteSize("P-256") 35 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_ecdsakey.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | 12 | from tlslite.utils.ecdsakey import ECDSAKey 13 | 14 | 15 | class MockECDSAKey(ECDSAKey): 16 | def __init__(self, public_key, private_key): 17 | pass 18 | 19 | 20 | class TestECDSAKey(unittest.TestCase): 21 | 22 | @classmethod 23 | def setUpClass(cls): 24 | cls.k = MockECDSAKey(None, None) 25 | 26 | def test___init___not_implemented(self): 27 | with self.assertRaises(NotImplementedError): 28 | ECDSAKey(None, None) 29 | 30 | def test___len__(self): 31 | with self.assertRaises(NotImplementedError): 32 | len(self.k) 33 | 34 | def test_hasPrivateKey(self): 35 | with self.assertRaises(NotImplementedError): 36 | self.k.hasPrivateKey() 37 | 38 | def test__sign(self): 39 | with self.assertRaises(NotImplementedError): 40 | self.k._sign(None, None) 41 | 42 | def test__hashAndSign(self): 43 | with self.assertRaises(NotImplementedError): 44 | self.k._hashAndSign(None, None) 45 | 46 | def test__verify(self): 47 | with self.assertRaises(NotImplementedError): 48 | self.k._verify(None, None) 49 | 50 | def test_hashAndSign(self): 51 | with self.assertRaises(NotImplementedError): 52 | self.k.hashAndSign(bytearray(b'text')) 53 | 54 | def test_hashAndVerify(self): 55 | with self.assertRaises(NotImplementedError): 56 | self.k.hashAndVerify(bytearray(b'sig'), bytearray(b'text')) 57 | 58 | def test_sign(self): 59 | with self.assertRaises(NotImplementedError): 60 | self.k.sign(bytearray(b'hash value')) 61 | 62 | def test_verify(self): 63 | with self.assertRaises(NotImplementedError): 64 | self.k.verify(bytearray(b'sig'), bytearray(b'hash value')) 65 | 66 | def test_acceptsPassword(self): 67 | with self.assertRaises(NotImplementedError): 68 | self.k.acceptsPassword() 69 | 70 | def test_write(self): 71 | with self.assertRaises(NotImplementedError): 72 | self.k.write() 73 | 74 | def test_generate(self): 75 | with self.assertRaises(NotImplementedError): 76 | ECDSAKey.generate('NIST256p') 77 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_lists.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | 12 | from tlslite.utils.lists import getFirstMatching, to_str_delimiter 13 | 14 | class TestGetFirstMatching(unittest.TestCase): 15 | def test_empty_list(self): 16 | self.assertIsNone(getFirstMatching([], [1, 2, 3])) 17 | 18 | def test_first_matching(self): 19 | self.assertEqual(getFirstMatching([1, 7, 8, 9], [1, 2, 3]), 1) 20 | 21 | def test_last_matching(self): 22 | self.assertEqual(getFirstMatching([7, 8, 9, 1], [1, 2, 3]), 1) 23 | 24 | def test_no_matching(self): 25 | self.assertIsNone(getFirstMatching([7, 8, 9], [1, 2, 3])) 26 | 27 | def test_no_list(self): 28 | self.assertIsNone(getFirstMatching(None, [1, 2, 3])) 29 | 30 | def test_empty_matches(self): 31 | self.assertIsNone(getFirstMatching([1, 2, 3], [])) 32 | 33 | def test_no_matches(self): 34 | with self.assertRaises(AssertionError): 35 | getFirstMatching([1, 2, 3], None) 36 | 37 | 38 | class TestToStrDelimiter(unittest.TestCase): 39 | def test_empty_list(self): 40 | self.assertEqual("", to_str_delimiter([])) 41 | 42 | def test_one_element(self): 43 | self.assertEqual("12", to_str_delimiter([12])) 44 | 45 | def test_two_elements(self): 46 | self.assertEqual("12 or 13", to_str_delimiter([12, 13])) 47 | 48 | def test_three_elements(self): 49 | self.assertEqual("12, 13 or 14", to_str_delimiter([12, 13, 14])) 50 | 51 | def test_with_strings(self): 52 | self.assertEqual("abc, def or ghi", 53 | to_str_delimiter(['abc', 'def', 'ghi'])) 54 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_tlshashlib.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, Hubert Kario 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | try: 12 | import mock 13 | from mock import call 14 | except ImportError: 15 | import unittest.mock as mock 16 | from unittest.mock import call 17 | 18 | class TestTLSHashlib(unittest.TestCase): 19 | 20 | def test_in_fips_mode(self): 21 | def m(*args, **kwargs): 22 | if 'usedforsecurity' not in kwargs: 23 | raise ValueError("MD5 disabled in FIPS mode") 24 | 25 | with mock.patch('hashlib.md5', m): 26 | from tlslite.utils.tlshashlib import md5 27 | md5() 28 | -------------------------------------------------------------------------------- /unit_tests/test_tlslite_utils_tripledes_split.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, Alexander Sosedkin 2 | # 3 | # See the LICENSE file for legal information regarding use of this file. 4 | 5 | # compatibility with Python 2.6, for that we need unittest2 package, 6 | # which is not available on 3.3 or 3.4 7 | try: 8 | import unittest2 as unittest 9 | except ImportError: 10 | import unittest 11 | 12 | import sys 13 | 14 | from hypothesis import given, assume, settings 15 | from hypothesis.strategies import binary, integers, tuples 16 | 17 | from tlslite.utils import cryptomath 18 | 19 | import tlslite.utils.python_tripledes 20 | py_3des = tlslite.utils.python_tripledes.new 21 | 22 | 23 | HYP_SETTINGS = {'deadline': None} if sys.version_info > (2, 7) else {} 24 | 25 | 26 | class TestTripleDES(unittest.TestCase): 27 | _given = given(binary(min_size=24, max_size=24), # key 28 | binary(min_size=8, max_size=8), # iv 29 | binary(min_size=13*8, max_size=13*8), # plaintext 30 | (tuples(integers(0, 13), integers(0, 13)) # split points 31 | .filter(lambda split_pts: split_pts[0] <= split_pts[1]) 32 | .map(lambda lengths: [i * 8 for i in lengths]))) 33 | 34 | def split_test(self, key, iv, plaintext, split_points, make_impl=py_3des): 35 | i, j = split_points 36 | 37 | ciphertext = make_impl(key, iv).encrypt(plaintext) 38 | self.assertEqual(make_impl(key, iv).decrypt(ciphertext), plaintext) 39 | 40 | impl = make_impl(key, iv) 41 | pl1, pl2, pl3 = plaintext[:i], plaintext[i:j], plaintext[j:] 42 | ci1, ci2, ci3 = impl.encrypt(pl1), impl.encrypt(pl2), impl.encrypt(pl3) 43 | self.assertEqual(ci1 + ci2 + ci3, ciphertext) 44 | 45 | impl = make_impl(key, iv) 46 | pl1, pl2, pl3 = impl.decrypt(ci1), impl.decrypt(ci2), impl.decrypt(ci3) 47 | self.assertEqual(pl1 + pl2 + pl3, plaintext) 48 | 49 | return ciphertext 50 | 51 | @_given 52 | @settings(**HYP_SETTINGS) 53 | def test_python(self, key, iv, plaintext, split_points): 54 | self.split_test(key, iv, plaintext, split_points) 55 | 56 | @unittest.skipIf(not cryptomath.m2cryptoLoaded, "requires M2Crypto") 57 | @_given 58 | @settings(**HYP_SETTINGS) 59 | def test_python_vs_mcrypto(self, key, iv, plaintext, split_points): 60 | import tlslite.utils.openssl_tripledes 61 | m2_3des = lambda k, iv: tlslite.utils.openssl_tripledes.new(k, 2, iv) 62 | 63 | py_res = self.split_test(key, iv, plaintext, split_points, py_3des) 64 | m2_res = self.split_test(key, iv, plaintext, split_points, m2_3des) 65 | self.assertEqual(py_res, m2_res) 66 | 67 | @unittest.skipIf(not cryptomath.pycryptoLoaded, "requires pycrypto") 68 | @_given 69 | @settings(**HYP_SETTINGS) 70 | def test_python_vs_pycrypto(self, key, iv, plaintext, split_points): 71 | import tlslite.utils.pycrypto_tripledes 72 | pc_3des = lambda k, iv: tlslite.utils.pycrypto_tripledes.new(k, 2, iv) 73 | 74 | try: 75 | py_res = self.split_test(key, iv, plaintext, split_points, py_3des) 76 | pc_res = self.split_test(key, iv, plaintext, split_points, pc_3des) 77 | self.assertEqual(py_res, pc_res) 78 | except ValueError as e: 79 | # pycrypto deliberately rejects weak 3DES keys, skip such keys 80 | assume(e.args != ('Triple DES key degenerates to single DES',)) 81 | raise 82 | --------------------------------------------------------------------------------