1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-23 17:34:17 +03:00
openuds/tunnel-server/samples/echo_client_ssl.py

40 lines
845 B
Python
Raw Normal View History

2022-12-07 23:40:17 +03:00
#!/usr/bin/env python3
# -*- coding=utf-8 -*-
import ssl
import asyncio
import typing
import certifi # In order to get valid ca certificates
if typing.TYPE_CHECKING:
2023-03-28 23:57:55 +03:00
pass
2022-12-07 23:40:17 +03:00
async def tcp_echo_client():
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_verify_locations(certifi.where())
reader, writer = await asyncio.open_connection('fake.udsenterprise.com', 7777, ssl=context)
writer.write(b'\x5AMGB\xA5\x01\x00')
await writer.drain()
writer.write(b'OPEN' + b'1'*63 + b'\xA0')
await writer.drain()
writer.write(b'GET / HTTP/1.0\r\n\r\n')
while True:
data = await reader.read(1024)
if not data:
break
print(f'Received: {data!r}')
print('Close the connection')
writer.close()
await writer.wait_closed()
asyncio.run(tcp_echo_client())