Für Indy .p12 zu .pem wandeln
Posted by wnf on Wednesday, 20 June 2018Literatur
Zur Beachtung Unter Delphi 2009 funktioniert die unten angegebene Funktion testCert zwar, aber der Zugriff auf einen anderen Server lieferte nur 403 Forbidden. Unter Delphi 10 Tokyo funktioniert der Zugriff immer.
- Delphi 2009: Indy version: 10.2.5
- Delphi 10.2: Indy version: 10.6.2.5366
Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM
openssl pkcs12 -in zugang.p12 -out zugang.pem -nodes
in Delphi
- me ist vom Typ TMemo
uses SysUtils, Classes, Forms, IdHTTP, IdSSLOpenSSL, idGlobal, Controls, ComCtrls, ToolWin, StdCtrls; function TForm1.testCert: boolean; var IdHTTP1 : TIdHTTP; Id_HandlerSocket : TIdSSLIOHandlerSocketOpenSSL; cert:string; s : string; begin try me.Clear; IdHTTP1 := TIdHTTP.Create( self ); IdHTTP1.Request.BasicAuthentication := False; IdHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0'; Id_HandlerSocket := TIdSSLIOHandlerSocketOpenSSL.Create( IdHTTP1 ); cert := 'zugang.pem'; Id_HandlerSocket.SSLOptions.CertFile := cert; (* PEM contain both CERT and Key *) Id_HandlerSocket.SSLOptions.KeyFile := cert; Id_HandlerSocket.SSLOptions.Mode := sslmClient; Id_HandlerSocket.SSLOptions.Method := sslvSSLv23; IdHTTP1.IOHandler := Id_HandlerSocket; me.Add( Id_HandlerSocket.SSLOptions.CertFile ); s := IdHTTP1.Get( 'https://www.scriptjunkie.us/auth/verifycert' ); me.Add( s ); Result:=True; finally Id_HandlerSocket.Free; IdHTTP1.Free; end; end;