Recent

Author Topic: How to check my own certificate for validity (expiration)?  (Read 363 times)

Vodnik

  • Full Member
  • ***
  • Posts: 223
How to check my own certificate for validity (expiration)?
« on: July 21, 2026, 01:18:49 pm »
I'm working on primitive web-server application that uses Synapse (ssl_openssl3) for networking. It uses certificate to establish TLS connection. Web-server waits for webhooks, then save data to DB. Currently works under Windows, have plans to port to Linux, too. I want to check the certificate that I use (my server side) for expiration and start to log a warning few days before. I can not find appropriate functions in Synapse for that. Please advise the way how this can be done.

Thaddy

  • Hero Member
  • *****
  • Posts: 19625
  • Glad to be alive.
Re: How to check my own certificate for validity (expiration)?
« Reply #1 on: July 21, 2026, 01:27:09 pm »
Not synapse, but:
Code: Pascal  [Select][+][-]
  1. uses
  2.   fphttpclient, opensslsockets; // opensslsockets is crucial for HTTPS
  3.  
  4. procedure TYourClass.HandleVerifyCertificate(Sender: TObject;
  5.   AHandler: TSSLSocketHandler; var aAllow: Boolean);
  6. begin
  7.   // Here you can access AHandler.CertificateData
  8.   // to check the validity period and decide if aAllow should be True or False.
  9.   WriteLn('Checking certificate...');
  10.   // Add your logic to read the expiration date
  11.   aAllow := True; // Set to False to reject the certificate
  12. end;
  13.  
  14. // ... in your method where you use TFPHTTPClient
  15. var
  16.   Client: TFPHTTPClient;
  17. begin
  18.   Client := TFPHTTPClient.Create(nil);
  19.   try
  20.     Client.OnVerifyCertificate := @HandleVerifyCertificate;
  21.     // The verification event will fire when you make the request
  22.     Client.Get('https://your-website.com');
  23.   finally
  24.     Client.Free;
  25.   end;
  26. end;
Not mine, found it. Synapse would be similar. Source is DeepSeek and not nonsense.
« Last Edit: July 21, 2026, 01:28:57 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

Vodnik

  • Full Member
  • ***
  • Posts: 223
Re: How to check my own certificate for validity (expiration)?
« Reply #2 on: July 21, 2026, 03:06:48 pm »
Seems this will check partner's certificate, not my own.

Чебурашка

  • Hero Member
  • *****
  • Posts: 602
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: How to check my own certificate for validity (expiration)?
« Reply #3 on: July 21, 2026, 03:14:12 pm »
Perhaps checking server certificate could be done using server OS tools, not by application. Btw checking a server certificate is not even related to application being ran. This is why examples seem to focus on intercepting client calls and suggesting to implement on-call client cert validation.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

PierceNg

  • Sr. Member
  • ****
  • Posts: 443
    • SamadhiWeb
Re: How to check my own certificate for validity (expiration)?
« Reply #4 on: July 21, 2026, 03:15:56 pm »
Use the OpenSSL CLI

Code: Text  [Select][+][-]
  1. % openssl x509 -text -noout -in www.samadhiweb.com.crt
  2. Certificate:
  3.     Data:
  4.         Version: 3 (0x2)
  5.         Serial Number:
  6.             05:2b:61:f6:33:83:14:8d:e8:51:90:69:b5:7e:2a:4a:52:85
  7.         Signature Algorithm: ecdsa-with-SHA384
  8.         Issuer: C = US, O = Let's Encrypt, CN = YE2
  9.         Validity
  10.             Not Before: Jul 11 05:18:57 2026 GMT
  11.             Not After : Oct  9 05:18:56 2026 GMT
  12.         Subject: CN = www.samadhiweb.com
  13.         Subject Public Key Info:
  14.         ...
  15.  


Thaddy

  • Hero Member
  • *****
  • Posts: 19625
  • Glad to be alive.
Re: How to check my own certificate for validity (expiration)?
« Reply #6 on: July 21, 2026, 04:44:37 pm »
Seems this will check partner's certificate, not my own.
Both parties need to have the public certificates in there certificate chain, the server needs to hold the private certificate.
Any "programmer" that knows only one programming language is not a programmer

LeP

  • Guest
Re: How to check my own certificate for validity (expiration)?
« Reply #7 on: July 21, 2026, 05:04:49 pm »
@Vodnik
It's simple, but I use Indy (with TaurusTLS)... I try to explain.

You must "create" a x509 certificate from runtime IOHandler of your server.
I use SNI, so I have a collection of certificate .. but it is the same if you have only one.

Use something like this:

(NOTE: the variable OpenSSL1 must be istantiated from you server, of course)

Code: Pascal  [Select][+][-]
  1.   var certi: TTaurusTlsx509;                     //Class to manage the certificate ... Synapse should exposed one similar
  2.       OpenSSL1: TTaurusTLSServerIOHandler;      //Class SSL IoHandler ... like before
  3.   begin
  4.     //Certificates[0] is the first cerificate loaded in the SSL IOHandler (I have ten of those).
  5.     //You should use the "default" with Synapse I think.
  6.     certi := TTaurusTlsx509.Create(OpenSSL1.Certificates[0].x509);
  7.     writeln(certi.notAfter.ToString);
  8.   end;
  9.  

output:
Quote
22/09/2026 21:49:51
« Last Edit: July 21, 2026, 05:17:23 pm by LeP »

 

TinyPortal © 2005-2018