Example #1
0
def run_case(context, port):
    print(f'Protocol: {utils.tls_protocol(context.minimum_version).value.name}')

    with Client(context) as _client1:
        _client1.connect(port=port)
        _session = _client1.get_session()
    with Client(context=_client1.context, session=_session) as _client2:
        _client2.connect(port=port)

        if not _client2.is_session_resumed():
            raise RuntimeWarning('Session is not resumed')
        else:
            print('Session was resumed')
Example #2
0
def run_case(protocol, cipher_suite):
    _context = utils.create_context(min_protocol=protocol,
                                    max_protocol=protocol,
                                    cipher_suites=(cipher_suite, ))
    _c_thread = ClientThread(Client(context=_context), _port)
    _c_thread.start()
    return _c_thread
def run_case(protocol, cipher_suite):
    print(f'Protocol: {protocol}\nCipher suite: {cipher_suite}')
    with ServerThread(Server()) as _s_thread:
        _s_thread.start()

        _port = _s_thread.server.get_port()

        _context = utils.create_context(min_protocol=protocol,
                                        max_protocol=protocol,
                                        cipher_suites=(cipher_suite, ))
        with Client(context=_context) as _client:
            _client.connect(port=_port)
Example #4
0
# -*- coding: utf-8 -*-
"""A simple demo on server name indication.
"""

import ssl
import time

from pyssldemo.client import Client
from pyssldemo.server import Server, ServerThread

if __name__ == '__main__':
    print(ssl.OPENSSL_VERSION)

    server_name = 'localhost'

    with ServerThread(Server()) as _s_thread:
        _s_thread.start()

        time.sleep(1)  # Wait for server accepting (?)

        _port = _s_thread.server.get_port()

        with Client() as _client:
            _client.server_name = server_name
            _client.connect(port=_port)
            if server_name != _s_thread.server.server_name:
                raise RuntimeWarning(
                    f'Unexpected server name: {_s_thread.server.server_name}')
# -*- coding: utf-8 -*-
"""A simple demo on client authentication.
"""

import ssl
from pyssldemo.server import Server, ServerThread
from pyssldemo.client import Client

if __name__ == '__main__':
    print(ssl.OPENSSL_VERSION)

    _server = Server()
    _server.set_peer_auth(True)

    with ServerThread(_server) as _s_thread:
        _s_thread.start()

        _port = _server.get_port()

        _client = Client()
        _client.connect(port=_port)