Hello.

Sorry to take this over, 'only reading -user via gmane, and
occasionally.

Wietse Venema via Postfix-users wrote in
 <[email protected]>:
 |Gerald Galster via Postfix-users:
 |> 3) SOCKS5 (uncommon)
 |> 
 |> This approach requires tools like socksify or proxychains which use \
 |> LD_PRELOAD
 |> to intercept system calls to make apps SOCKS5 compatible. On the \
 |> VPS side you'd
 |> need a SOCKS5 server such as Dante or just use sshd's SOCKS5 proxy \
 |> (ssh -D),
 |> which also encrypts the otherwise plaintext SOCKS5 traffic.
 |
 |I was thinking of adding libsocks library calls for inbound or
 |outbound remote SMTP connections.  If I'm not mistaken, socksify
 |etc. want to intercept not only TCP but also DNS. Would that work
 |with DNSSEC?

You do not need an external library for SOCKS5, it is a pretty
easy protocol (a small RFC) that can be wrapped.

  boole
  mx_socket_open(struct mx_socket *sop, struct mx_url *urlp){
     char const *cp;
     boole rv;
     NYD_IN;

     rv = FAL0;

     /* We may have a proxy configured */
     if((cp = xok_vlook(socks_proxy, urlp, OXM_ALL)) == NULL)
        rv = a_netso_open(sop, urlp);

^ plain open without intermediate proxy.

     else{
        u8 pbuf[4 + 1 + 255 + 2];
        uz i;
        char const *emsg;
        struct mx_url url2;

        if(!mx_url_parse(&url2, CPROTO_SOCKS, cp)){
           n_err(_("Failed to parse *socks-proxy*: %s\n"), cp);
           goto jleave;
        }
        if(urlp->url_host.l > 255){
           n_err(_("*socks-proxy*: hostname too long: %s\n"),
              urlp->url_input);
           goto jleave;
        }

        if(n_poption & n_PO_D_V)
           n_err(_("Connecting to *socks-proxy*=%s\n"), cp);
        if(!a_netso_open(sop, &url2)){
           n_err(_("Failed to connect to *socks-proxy*: %s\n"), cp);
           goto jleave;
        }

        /* RFC 1928: version identifier/method selection message */
        pbuf[0] = 0x05; /* VER: protocol version: X'05' */
        pbuf[1] = 0x01; /* NMETHODS: 1 */
        pbuf[2] = 0x00; /* METHOD: X'00' NO AUTHENTICATION REQUIRED */
        if(write(sop->s_fd, pbuf, 3) != 3){
  jerrsocks:
           n_perr("*socks-proxy*", su_err_by_errno());
  jesocks:
           mx_socket_close(sop);
           goto jleave;
        }

        /* Receive greeting */
        if(read(sop->s_fd, pbuf, 2) != 2)
           goto jerrsocks;
        if(pbuf[0] != 0x05 || pbuf[1] != 0x00){
  jesocksreply:
           emsg = N_("unexpected reply\n");
  jesocksreplymsg:
           /* I18N: error message and failing URL */
           n_err(_("*socks-proxy*: %s: %s\n"), V_(emsg), cp);
           goto jesocks;
        }

        /* RFC 1928: CONNECT request */
        if(n_poption & n_PO_D_V)
           n_err(_("Through *socks-proxy*, connecting to %s:%s ...\n"),
              urlp->url_host.s,
              (urlp->url_port != NULL ? urlp->url_port : urlp->url_proto));
        pbuf[0] = 0x05; /* VER: protocol version: X'05' */
        pbuf[1] = 0x01; /* CMD: CONNECT X'01' */
        pbuf[2] = 0x00; /* RESERVED */
        pbuf[3] = 0x03; /* ATYP: domain name */
        pbuf[4] = (u8)urlp->url_host.l;
        su_mem_copy(&pbuf[i = 5], urlp->url_host.s, urlp->url_host.l);

^ If you pass the host name, DNS lookup is to be performed by
proxy, you are totally off; that is, if you have a fixed IP
address for your proxy, you do no DNS at all (well, for SMTP).

        /* C99 */{
           u16 x;

           x = htons(urlp->url_portno);
           su_mem_copy(&pbuf[i += urlp->url_host.l], (u8*)&x, sizeof x);
           i += sizeof x;
        }
        if(write(sop->s_fd, pbuf, i) != (sz)i)
           goto jerrsocks;

        /* Connect result */
        if((i = read(sop->s_fd, pbuf, 4)) != 4)
           goto jerrsocks;
        /* Version 5, reserved must be 0 */
        if(pbuf[0] != 0x05 || pbuf[2] != 0x00)
           goto jesocksreply;
        /* Result */
        switch(pbuf[1]){
        case 0x00: emsg = NULL; break;
        case 0x01: emsg = N_("SOCKS server failure"); break;
        case 0x02: emsg = N_("connection not allowed by ruleset"); break;
        case 0x03: emsg = N_("network unreachable"); break;
        case 0x04: emsg = N_("host unreachable"); break;
        case 0x05: emsg = N_("connection refused"); break;
        case 0x06: emsg = N_("TTL expired"); break;
        case 0x07: emsg = N_("command not supported"); break;
        case 0x08: emsg = N_("address type not supported"); break;
        default: emsg = N_("unknown SOCKS error code"); break;
        }
        if(emsg != NULL)
           goto jesocksreplymsg;

        /* Address type variable; read the BND.PORT with it.
         * This is actually false since RFC 1928 says that the BND.ADDR reply to
         * CONNECT contains the IP address, so only 0x01 and 0x04 are allowed */
        switch(pbuf[3]){
        case 0x01: i = 4; break;
        case 0x03: i = 1; break;
        case 0x04: i = 16; break;
        default: goto jesocksreply;
        }
        i += sizeof(u16);
        if(read(sop->s_fd, pbuf, i) != (sz)i)
           goto jerrsocks;
        if(i == 1 + sizeof(u16)){
           i = pbuf[0];
           if(read(sop->s_fd, pbuf, i) != (sz)i)
              goto jerrsocks;
        }

        /* SSL/TLS upgrade? */
#ifdef mx_HAVE_TLS
        if(urlp->url_flags & mx_URL_TLS_MASK)
           rv = (a_netso_open_tls_maybe(sop, urlp) >= 0);
        else
#endif
           rv = TRU1;
     }

  jleave:
     a_netso_test_sig();
     NYD_OU;
     return rv;
  }

That is it for my MUA (and the lynx browser).

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
_______________________________________________
Postfix-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to