9

I'm getting a general Indy error when using the IdHTTP client component in conjunction with a SOCKS5 proxy server and using SSL.

  • If I use the IdHTTP component with my SOCKS5 proxy (and a non https URL), everything works without problems.
  • If I use the IdHTTP component with an SSL URL (and no SOCKS5 proxy), everything works without problems.
  • If I use the IdHTTP component with an SSL URL and a SOCKS5 proxy i get following error:

Line 405 of the error output idSocks.pas (raise EIdSocksServerGeneralError.Create(RSSocksServerGeneralError);

Here is my code

var
  HTTP            : TIdHTTP;
  Cookie          : TIdCookieManager;
  SSL             : TIdSSLIOHandlerSocketOpenSSL;
  Params          : TStringList;
  HTMLSource      : String;
  CurrentProxy    : String;
  ProxyPort       : Integer;
  ProxyHost       : String;
  ProxyUsername   : String;
  ProxyPW         : String;
begin
  Synchronize(AddItem);
  HTTP                          := TIdHTTP.Create(NIL);
  Cookie                        := TIdCookieManager.Create(HTTP);
  SSL                           := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP);
  HTTP.CookieManager            := Cookie;
  HTTP.IOHandler                := SSL;
  HTTP.HandleRedirects          := True;
  Params                        := TStringList.Create;
  HTTP.Request.UserAgent        := Task^.Useragent;
  try
    while True do begin
      if terminated then Exit;
      Params.Clear;
      Cookie.CookieCollection.Clear;
      if Task^.Proxytype >= 0 then begin      // if proxy enabled
        CurrentProxy            := Task^.Form.GetProxyFromPool;
        ProxyHost               := ParsingW(':', CurrentProxy, 1);
        ProxyPort               := strtoint(ParsingW(':', CurrentProxy, 2));
        HTTP.ConnectTimeout     := (Task^.Proxytimeout * 1000);
        if Task^.ProxyAuth then begin
          ProxyUsername         := ParsingW(':', CurrentProxy, 3);
          ProxyPW               := ParsingW(':', CurrentProxy, 4);
        end;
      end;
      if Task^.Proxytype = 0 then begin //HTTP(s)
        HTTP.ProxyParams.ProxyServer      := ProxyHost;
        HTTP.ProxyParams.ProxyPort        := ProxyPort;
        if Task^.ProxyAuth then begin
          HTTP.ProxyParams.ProxyUsername  := ProxyUsername;
          HTTP.ProxyParams.ProxyPassword  := ProxyPW;
        end;
      end;
      if (Task^.Proxytype = 1) or (Task^.Proxytype = 2) then begin   // Socks 4 or 5
        SSL.TransparentProxy := TIdSocksInfo.Create(HTTP);
        (SSL.TransparentProxy as TIdSocksInfo).Port             := ProxyPort;
        (SSL.TransparentProxy as TIdSocksInfo).Host             := ProxyHost;
        if Task^.ProxyAuth then begin
          (SSL.TransparentProxy as TIdSocksInfo).Username       := ProxyUsername;
          (SSL.TransparentProxy as TIdSocksInfo).Password       := ProxyPW;
          (SSL.TransparentProxy as TIdSocksInfo).Authentication := saUsernamePassword;
        end else begin
          (SSL.TransparentProxy as TIdSocksInfo).Authentication := saNoAuthentication;
        end;
        if (Task^.Proxytype = 1) then  (SSL.TransparentProxy as TIdSocksInfo).Version := svSocks4;
        if (Task^.Proxytype = 2) then  (SSL.TransparentProxy as TIdSocksInfo).Version := svSocks5;
      end;

Did I miss something or is it not possible to connect to a a SSL site with a Socks5 Proxy?

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
user2791785
  • 93
  • 1
  • 5

1 Answers1

6

The fact that you are getting an EIdSocksServerGeneralError raised means that TIdHTTP is successfully communicating with the SOCKS proxy and it is validating your request to access it with no authentication, but it is then failing to establish a connection with the target server that you specified in your HTTPS url. The proxy is replying with error code 1 (general failure). Make sure that the url is accurate. Either the proxy cannot resolve the hostname to an IP (try specifying an IP instead of a hostname in the url and see if it makes a difference), or the proxy does not have a valid route to reach that IP, or some other error is occurring on the proxy end. If you have access to the proxy, try looking at its logs to see what actually went wrong.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 2
    Could you please write an example for ssl + socks5 ? I gave you the bounty :) – Hidden Oct 10 '13 at 12:04
  • 1
    The code you showed should work fine for SSL through a SOCKS proxy, provided the proxy is able to establish a connection to the target server. The problem you are experiencing is that your proxy is not able to establish that connection, which has nothing to do with Indy or SSL. The problem is on the proxy side, not in your app. Try sending HTTP/HTTPS requests to other domains to verify whether the proxy is working correctly. – Remy Lebeau Oct 10 '13 at 15:21