Exemplo n.º 1
0
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)
Exemplo n.º 2
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}')
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
"""A simple demo on checking ALPN.
"""

import ssl

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

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

    _server = Server()
    _server.set_app_protocols('http/1.1', 'http/2')

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

        _port = _server.get_port()

        with Client() as _client:
            _client.set_app_protocols('http/2')
            _client.connect(port=_port)
            _negotiated_app_protocol = _client.get_app_protocol()

            if _negotiated_app_protocol != 'http/2':
                raise RuntimeWarning(
                    f'Unexpected app protocol: {_client.get_app_protocol()}')
Exemplo n.º 4
0
# -*- 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)