Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Indy HTTPServer + SSL in SVN Version kaputt (https://www.delphipraxis.net/150429-indy-httpserver-ssl-svn-version-kaputt.html)

paresy 16. Apr 2010 11:04


Indy HTTPServer + SSL in SVN Version kaputt
 
r4177, Delphi 2007

Beim starten des HTTPServers wirft dieser eine Exception:
Code:
Exception class EIdOSSLLoadingRootCertError with message 'Could not load root certificate.
error:0B064071:x509 certificate routines:ADD_CERT_DIR:invalid directory'.
Das liegt an folgender Funktion:
Delphi-Quellcode:
function IndySSL_CTX_load_verify_locations(ctx: PSSL_CTX;
  const ACAFile, ACAPath: String): TIdC_INT;
begin
  Result := SSL_CTX_load_verify_locations(ctx, PAnsiChar(ACAFile),
    PAnsiChar(ACAPath));
end;
Woraround:
Delphi-Quellcode:
function IndySSL_CTX_load_verify_locations(ctx: PSSL_CTX;
  const ACAFile, ACAPath: String): TIdC_INT;
begin
  Result := SSL_CTX_load_verify_locations(ctx, PAnsiChar(ACAFile),
    nil);
end;
Wenn der ACAPath leer ist (was er immer ist), dann wird durch die PAnsiChar Konvertierung ein #0 zurückgegeben, was nicht NULL ist und dadurch überprüft OpenSSL den Pfad, der dann ungültig ist und in der o.g. Exception resultiert. Ein hardcoded NIL hilft. Ist aber nicht wirklich schön ;). Besser wäre eine Erkennung von Indy ob der User eine Datei oder einen Pfad angegeben hat und dann den jeweils richtigen Parameter ausfüllt und den anderen per NIL deaktiviert.

Doku: http://www.openssl.org/docs/ssl/SSL_...locations.html

paresy

Assertor 18. Apr 2010 23:28

Re: Indy HTTPServer + SSL in SVN Version kaputt
 
Hallo paresy,

Zitat:

Zitat von paresy
Beim starten des HTTPServers wirft dieser eine Exception:
Code:
Exception class EIdOSSLLoadingRootCertError with message 'Could not load root certificate.
error:0B064071:x509 certificate routines:ADD_CERT_DIR:invalid directory'.
[...]

Wenn der ACAPath leer ist (was er immer ist), dann wird durch die PAnsiChar Konvertierung ein #0 zurückgegeben, was nicht NULL ist und dadurch überprüft OpenSSL den Pfad, der dann ungültig ist und in der o.g. Exception resultiert. Ein hardcoded NIL hilft. Ist aber nicht wirklich schön ;). Besser wäre eine Erkennung von Indy ob der User eine Datei oder einen Pfad angegeben hat und dann den jeweils richtigen Parameter ausfüllt und den anderen per NIL deaktiviert.

Gefixt in Rev #4183, Danke fürs reporten :thumb:

Allgemeine Lösung ist ein Casten auf Pointer und dann auf PAnsiChar, wie z.B. jetzt hier:

Delphi-Quellcode:
function IndyX509_STORE_load_locations(ctx: PX509_STORE;
  const AFileName, APathName: String): TIdC_INT;
{$IFDEF USE_INLINE} inline; {$ENDIF}
begin
  // RLebeau 4/18/2010: X509_STORE_load_locations() expects nil pointers
  // for unused values, but casting a string directly to a PAnsiChar
  // always produces a non-nil pointer, which causes X509_STORE_load_locations()
  // to fail. Need to cast the string to an intermediate Pointer so the
  // PAnsiChar cast is applied to the raw data and thus can be nil...
  //
  Result := X509_STORE_load_locations(ctx,
    PAnsiChar(Pointer(UTF8String(AFileName))),
    PAnsiChar(Pointer(UTF8String(APathName))));
end;
Gruß,
Assertor


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:54 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