PizzaProgram 9 Posted April 4, 2023 Hi, 😉  How to get SSL CERTIFICATE expiring date using OpenSSL3 ? SslHttpCli := TSslHttpCli.Create(nil); SslContext := TSslContext.Create(nil); SslContext.SslCertLines.Text := cer1; // cer1 is an ansiString ' --- BEGIN CER... ' endOfLife := // ?  Share this post Link to post
Angus Robertson 574 Posted April 4, 2023 SslContext.SslCertX509,ValidNotAfter returns certificate expiry as TDateTime  Angus 1 Share this post Link to post
PizzaProgram 9 Posted April 4, 2023 hmmm.... I was happy too soon.  These are the results:  ValidNotAfter = -657434  ValidNotBefore = 2958466  isCertLoaded = False  Don't I need to call a procedure for "digesting", before getting these values? Share this post Link to post
Angus Robertson 574 Posted April 4, 2023 The SslCertX509 property is type TX509Base and has methods to load, save and examine the content of the certificate and private key, IsCertLoaded, IsPKeyLoaded and IsInterLoaded say what has been loaded, so in your case nothing because you have not yet called InitContext, only created it in your code snippet.    If you just want to examine a certificate text, load it into a TX509Base object instead with the LoadFromTextEx method which will return any errors.  Angus Share this post Link to post
PizzaProgram 9 Posted April 5, 2023 Thank you very much for the detailed answer! Â The final code is: uses OverbyteIcsWSocket, OverbyteIcsSSLEAY; ... function get_certificate_expire_date(cerText: string):TDateTime; var X509 : TX509Base ; err : string; begin Result := 0; OverbyteIcsSSLEAY.GSSL_DLL_DIR := SS3_path; // if you store the OpenSSL DLL-s somewhere elsewhere X509 := TX509Base.Create(nil); X509.LoadFromTextEx( cerText, croNo, croTry, '', err ); if err = '' then Result := X509.ValidNotAfter // TDateTime else myLOG( 'Error during getting CER expire:' + CRLF + err ); X509.Free; end; Â Share this post Link to post
Angus Robertson 574 Posted April 5, 2023 TX509Base has dozens of methods for loading, saving, and examining certificates, but was never properly documented.  However, virtually all these properties and methods are used in the OverbyteIcsPemtool,dpr sample, also the TSslCertTools derivative that allows creation and signing of certificates.  Angus  1 Share this post Link to post