Skip to content

Instantly share code, notes, and snippets.

@rueian
Created June 22, 2022 00:11
Show Gist options
  • Save rueian/5f568007cdb5ee3b3fe42ad42192bc97 to your computer and use it in GitHub Desktop.
Save rueian/5f568007cdb5ee3b3fe42ad42192bc97 to your computer and use it in GitHub Desktop.
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