Created
June 22, 2022 00:11
-
-
Save rueian/5f568007cdb5ee3b3fe42ad42192bc97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| import ssl | |
| import json | |
| import socket | |
| import asyncio | |
| import util | |
| async def proxy(node_id): | |
| dir = os.path.join(os.getcwd(), '.ray-delegate') | |
| cfg = json.load(open(os.path.join(dir, node_id))) | |
| server_crt = util.tempwrite(cfg['server_crt'].encode('ascii')) | |
| client_crt = util.tempwrite(cfg['client_crt'].encode('ascii')) | |
| client_key = util.tempwrite(cfg['client_key'].encode('ascii')) | |
| context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=server_crt.name) | |
| context.load_cert_chain(certfile=client_crt.name, keyfile=client_key.name) | |
| reader, writer = await asyncio.open_connection(cfg['ip'], cfg['port'], ssl=context) | |
| loop = asyncio.get_event_loop() | |
| loop.connect_read_pipe() | |
| connect_read_pipe() | |
| with socket.create_connection((cfg['ip'], cfg['port'])) as sock: | |
| with context.wrap_socket(sock, server_hostname=cfg['sni']) as ssock: | |
| sys.stdout = ssock.makefile('w') | |
| while True: | |
| b = sys.stdin.buffer.read() | |
| if not b: | |
| return | |
| ssock.write(b) | |
| if __name__ == '__main__': | |
| asyncio.run(proxy('aaa')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment