Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Indy HTTP Proxy Server + SSL = Read Timeout (https://www.delphipraxis.net/162903-indy-http-proxy-server-ssl-%3D-read-timeout.html)

Zacherl 9. Sep 2011 08:02


Indy HTTP Proxy Server + SSL = Read Timeout
 
Hey,

ich versuche seit geraumer Zeit den Indy HTTP Proxy mit OpenSSL zum laufen zu bringen. Allerdings wirft die Indy Komponente jedes Mal, wenn ich eine Verbindung tunneln will, eine Exception mit dem Inhalt "Read Timeout".

Das komische an der Sache ist aber, wenn ich eine IdHTTP Komponente erstelle, dieser einen IdSSLIOHandlerSocketOpenSSL Handler mit selben Einstellungen zuweise und dann manuell die angeforderte SSL Seite aufrufe, dann funktioniert dies tadellos. Am Server / Certifikat / was weiß ich, kanns also nicht liegen.

Momentan habe ich folgenden Code:
Delphi-Quellcode:
procedure TForm4.IdHTTPProxyServer1HTTPBeforeCommand(
  AContext: TIdHTTPProxyServerContext);
var
  SSLClient: TIdSSLIOHandlerSocketOpenSSL;
begin
  if (TIdTCPClient(AContext.OutboundClient).Port = 443) then
  begin
    if not (AContext.OutboundClient.IOHandler is TIdSSLIOHandlerSocketOpenSSL) then
    begin
      if Assigned(AContext.OutboundClient.IOHandler) then
      begin
        AContext.OutboundClient.IOHandler.Free;
      end;
      AContext.OutboundClient.IOHandler :=
        TIdSSLIOHandlerSocketOpenSSL.Create(AContext.OutboundClient);
    end;
    SSLClient :=
      TIdSSLIOHandlerSocketOpenSSL(AContext.OutboundClient.IOHandler);
    SSLClient.SSLOptions.Method := sslvSSLv23;
    SSLClient.SSLOptions.Mode := sslmClient;
    SSLClient.SSLOptions.VerifyMode := [];
    SSLClient.PassThrough := false;
  end else if AContext.OutboundClient.IOHandler is TIdSSLIOHandlerSocketOpenSSL then
  begin
    TIdSSLIOHandlerSocketOpenSSL(AContext.OutboundClient.IOHandler).PassThrough := true;
  end;
end;
Wenn ich die Statusnachrichten vom SSL IOHandler ausgeben lasse, erkenne ich ebenfalls nichts Verdächtiges:
Code:
SSL-Status: "before/connect initialization"
SSL-Status: "before/connect initialization"
SSL-Status: "SSLv2/v3 write client hello A"
SSL-Status: "SSLv3 read server hello A"
SSL-Status: "SSLv3 read server certificate A"
SSL-Status: "SSLv3 read server key exchange A"
SSL-Status: "SSLv3 read server done A"
SSL-Status: "SSLv3 write client key exchange A"
SSL-Status: "SSLv3 write change cipher spec A"
SSL-Status: "SSLv3 write finished A"
SSL-Status: "SSLv3 flush data"
SSL-Status: "SSLv3 read finished A"
SSL-Status: "SSL negotiation finished successfully"
SSL-Status: "SSL negotiation finished successfully"
Cipher: name = DHE-RSA-AES256-SHA; description = DHE-RSA-AES256-SHA     SSLv3 Kx=DH      Au=RSA Enc=AES(256) Mac=SHA1
; bits = 256; version = TLSv1/SSLv3;
SSL-Status: "SSL negotiation finished successfully"
--> an dieser Stelle bricht die Verbindung ab
Hat jemand eine Idee, woher mein Problem kommen könnte?

Viele Grüße
Zacherl

Zacherl 9. Sep 2011 16:05

AW: Indy HTTP Proxy Server + SSL = Read Timeout
 
Habe das jetzt nochmal weitergehend debuggt. Die Exception wird in der IdHTTPProxyServer.pas in der Funkion CommandCONNECT in Zeile 418 geworfen.
Delphi-Quellcode:
if not LContext.FOutboundClient.IOHandler.InputBufferIsEmpty then
begin
  LContext.FOutboundClient.IOHandler.ReadStream(LServerToClientStream, -1, True);
end;
Vielleicht ist noch wichtig zu erwähnen, dass die proxifizierte Anwendung ein Java Programm ist, wobei ich den SSL Proxy auch im Firefox mit selbem "Erfolg" getestet habe.

Zacherl 11. Sep 2011 04:05

AW: Indy HTTP Proxy Server + SSL = Read Timeout
 
push :duck:

Assertor 12. Sep 2011 11:34

AW: Indy HTTP Proxy Server + SSL = Read Timeout
 
Hi Zacherl,

so, zurück von den Delphi Tagen antworte ich mal.

Ich weiß nicht, was Du machen möchtest und wo Du den obigen Code herhast...

Möchtest Du
1. den Weg zum Proxy per SSL/TLS schützen
oder
2. SSL über den Proxy nutzen?

Letzteres geht mit einer halbwegs aktuellen Indy Version (10.5.x) ohne Probleme - das andere ist nicht implementiert (wäre auch sehr unüblich).

Rohdaten werden Binär über den Proxy getunnelt, d.h. der Endpunkt (z.B. Browser) ist für die SSL Negotiation mit dem Endpunkt hinter dem Proxy verantwortlich:
http://tools.ietf.org/id/draft-luoto...nneling-03.txt

Sonst wärst Du ja der Man-in-the-Middle, was bei SSL doch eher ein Reizwort ist.

Ich habe gerade mal im frischen XE2 den IdHTTPProxyServer auf eine neue VCL Formanwendung gezogen, aktiv gesetzt und gestartet. Beim IE als Proxy für alle Protokolle den localhost:8080 und siehe da: Es geht sofort, auch per SSL (z.B. auf https://www.google.com).

Viele Grüße,
Assertor

Zacherl 12. Sep 2011 19:31

AW: Indy HTTP Proxy Server + SSL = Read Timeout
 
Vielen Dank für deine Antwort, jetzt wird mir einiges schon klarer :? Oh wei, ich wollte tatsächlich sowas wie man in the middle realisieren, obwohl das für meine Zwecke gar nicht mal nötig ist.

Intention war es lediglich über den Proxy einen Seitenaufruf auf einen anderen (lokalen) Server umzulenken.

Habe es nun nochmal ohne irgendwelche "Tricks" im OnBeforeHTTPCommand() Handler probiert, erhalte allerdings bei Delphi XE nach wie vor die Read Timeout Meldung. Mit Delphi XE2 funktioniert es tadellos :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:59 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz