Esempio n. 1
0
    def test_twisted_server_tls_client_auth(self):
        server = ServerRunner('../examples/servertls_clientauth.py', 5500)
        server.run()

        client = RpcClient('localhost', 5500)

        try:
            client.enable_tls('../examples/certs/rootCA.crt', False)
            client.enable_client_auth('../examples/certs/client.crt',
                                      '../examples/certs/client.key')

            result = client.rpc_call('echo', 'Hello Server')

            self.assertEqual(result, "Hello Server")
        finally:
            client.close_connection()
            server.stop()
Esempio n. 2
0
    def test_twisted_server_tls_client_auth(self):
        server = ServerRunner('../examples/servertls_clientauth.py', 5500)
        server.run()

        client = RpcClient('localhost', 5500)

        try:
            client.enable_tls('../examples/certs/rootCA.crt', False)
            client.enable_client_auth('../examples/certs/client.crt',
                    '../examples/certs/client.key')

            result = client.rpc_call('echo', 'Hello Server')

            self.assertEqual(result, "Hello Server")
        finally:
            client.close_connection()
            server.stop()
Esempio n. 3
0
    def test_twisted_server_tls_client_auth_wrong_client_cert(self):
        server = ServerRunner('../examples/servertls_clientauth.py', 5500)
        server.run()

        client = RpcClient('localhost', 5500)

        try:
            client.enable_tls('../examples/certs/rootCA.crt', False)
            client.enable_client_auth('../examples/certs/wrong-client.crt',
                    '../examples/certs/wrong-client.key')

            with self.assertRaises(NetworkError) as cm:
                result = client.rpc_call('echo', 'Hello Server')

            self.assertTrue('alert decrypt error' in str(cm.exception.real_exception))
        finally:
            client.close_connection()
            server.stop()
Esempio n. 4
0
    def test_twisted_server_tls_client_auth_username(self):
        server = ServerRunner('../examples/servertls_clientauth.py', 5500)
        server.run()

        client = RpcClient('localhost', 5500)

        try:
            client.enable_tls('../examples/certs/rootCA.crt', False)
            client.enable_client_auth('../examples/certs/client.crt',
                                      '../examples/certs/client.key')

            authenticated = client.rpc_call('is_authenticated')
            username = client.rpc_call('get_username')

            self.assertEqual(authenticated, True)
            self.assertEqual(username, 'example-username')
        finally:
            client.close_connection()
            server.stop()
Esempio n. 5
0
    def test_twisted_server_tls_client_auth_wrong_client_cert(self):
        server = ServerRunner('../examples/servertls_clientauth.py', 5500)
        server.run()

        client = RpcClient('localhost', 5500)

        try:
            client.enable_tls('../examples/certs/rootCA.crt', False)
            client.enable_client_auth('../examples/certs/wrong-client.crt',
                                      '../examples/certs/wrong-client.key')

            with self.assertRaises(NetworkError) as cm:
                result = client.rpc_call('echo', 'Hello Server')

            self.assertTrue(
                'alert decrypt error' in str(cm.exception.real_exception))
        finally:
            client.close_connection()
            server.stop()
Esempio n. 6
0
    def test_twisted_server_tls_client_auth_username(self):
        server = ServerRunner('../examples/servertls_clientauth.py', 5500)
        server.run()

        client = RpcClient('localhost', 5500)

        try:
            client.enable_tls('../examples/certs/rootCA.crt', False)
            client.enable_client_auth('../examples/certs/client.crt',
                    '../examples/certs/client.key')

            authenticated = client.rpc_call('is_authenticated')
            username = client.rpc_call('get_username')

            self.assertEqual(authenticated, True)
            self.assertEqual(username, 'example-username')
        finally:
            client.close_connection()
            server.stop()