Example #1
0
def server(auth: typing.Tuple[str, str]):
    parser = yield from iofree.get_parser()
    handshake = yield from socks5.Handshake.get_value()
    addr = socks5.Addr(1, "0.0.0.0", 0)
    if auth:
        if socks5.AuthMethod.user_auth not in handshake.methods:
            parser.respond(
                data=socks5.Reply(..., socks5.Rep.not_allowed, ...,
                                  addr).binary,
                close=True,
                exc=ProtocolError("auth method not allowed"),
            )
            return
        parser.respond(data=socks5.ServerSelection(
            ..., socks5.AuthMethod.user_auth).binary)
        user_auth = yield from socks5.UsernameAuth.get_value()
        if (user_auth.username.encode(), user_auth.password.encode()) != auth:
            parser.respond(
                data=socks5.Reply(..., socks5.Rep.not_allowed, ...,
                                  addr).binary,
                close=True,
                exc=ProtocolError("auth failed"),
            )
            return
        parser.respond(data=socks5.UsernameAuthReply(..., ...).binary)
    else:
        parser.respond(
            data=socks5.ServerSelection(..., socks5.AuthMethod.no_auth).binary)
    request = yield from socks5.ClientRequest.get_value()
    assert (request.cmd is socks5.Cmd.connect
            ), f"only support connect command now, got {socks5.Cmd.connect!r}"
    parser.respond(result=request)
    rep = yield from iofree.wait_event()
    parser.respond(data=socks5.Reply(..., socks5.Rep(rep), ..., addr).binary)
Example #2
0
def test_reply():
    reply = socks5.Reply(5, socks5.Rep.succeeded, 0,
                         socks5.Addr(4, "::1", 8080))
    check_schema(reply)
Example #3
0
def resp():
    addr = socks5.Addr(3, "0.0.0.0", 0)
    return socks5.Reply(..., socks5.Rep.succeeded, ..., addr).binary