socksv5_future

Crates.iosocksv5_future
lib.rssocksv5_future
version0.2.5
sourcesrc
created_at2018-02-17 11:29:32.632605
updated_at2018-03-04 13:32:14.899447
descriptionSocks v5 futures for Server and Client
homepagehttps://github.com/gin66/socksv5_future
repositoryhttps://github.com/gin66/socksv5_future
max_upload_size
id51580
size26,231
(gin66)

documentation

README

socksv5_future

The socks5 protocol consists of a handshake in these steps:

  1. Client establish TCP connection to a socks5 server
  2. Client sends authentication request with list of supported authentication methods.
  3. Server selects an appropriate authentication method and sends this back to client.
  4. Client sends socks5 request, which primarily contains destination address and port
  5. Server establishes connection to destination and answers client's request

This is the implementation of two Futures:

  • SocksHandshake
  • SocksConnectHandshake

As per RFC 1928, this is not a compliant socks5 implementation, because GSSAPI authentication method is not supported.

SocksHandshake

This is the server side implementation. It implements the step 2 to 4. Step 5 is not performed by this future. Instead the socks5 request is part of the future result.

SocksConnectHandshake

This is the client side implementation. It performs step 2-5.

Use case socks5 forwarder

The socks5 request from the client is used unchanged and sent to the forwarded socks proxy. Here short code segment to show the principal idea (this code will not compile):

    let mut lp = Core::new().unwrap();
    let handle = lp.handle();
    let addr = "127.0.0.1:8888".parse::<SocketAddr>().unwrap();
    let listener = TcpListener::bind(&addr, &handle2).unwrap();
    let server = listener.incoming().for_each(move |(socket, _addr)| {
        handle.spawn(
            socks_handshake(socket)
                .and_then(move |(source,request)| {
                    let proxy = "xx.xx.xx.xx:8888".parse::<SocketAddr>().unwrap();
                    let connect = TcpStream::connect(&proxy,&handle);
                    connect.and_then(move |dest|{
                        socks_connect_handshake(dest,request)
                    })
                    .and_then(|(stream,req_answer)|{
                        write_all(source,req_answer)
                    })
                    .and_then(|(stream,buf)|{
                        // perform transfer source<->stream
                    });
                })
        );
        Ok(())
    });
    handle.spawn(server)

Build Status

Commit count: 27

cargo fmt