码农的笔记

Delphi虽好,但已不流行; 博客真好,可以做笔记

博客园 首页 新随笔 联系 订阅 管理

开发环境Delphi XE11.3

仅仅是测试

 

 

Unit

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdSSLOpenSSL, IdHTTP, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    procedure CheckCertificateValidity;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := '';
  CheckCertificateValidity;
end;

procedure TForm1.CheckCertificateValidity;
var
  HTTP: TIdHTTP;
  SSL: TIdSSLIOHandlerSocketOpenSSL;
  CertValidStart, CertValidExpire: TDateTime;
begin
  HTTP := TIdHTTP.Create(nil);
  SSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  try
    SSL.SSLOptions.SSLVersions := [sslvSSLv2, sslvSSLv23, sslvSSLv3, sslvTLSv1,sslvTLSv1_1,sslvTLSv1_2];
    HTTP.IOHandler := SSL;
    HTTP.AllowCookies := True;
    HTTP.HandleRedirects := True;
    HTTP.Request.ContentType := 'application/x-www-form-urlencoded';
    HTTP.Request.Charset := 'UTF-8';
    HTTP.ConnectTimeout := 3000;
    HTTP.Get(Edit1.Text);
    CertValidStart := SSL.SSLSocket.PeerCert.notBefore;
    CertValidExpire := SSL.SSLSocket.PeerCert.notAfter;
    Label1.Caption := '证书有效期:' + FormatDateTime('yyyy-mm-dd hh:nn:ss', SSL.SSLSocket.PeerCert.notBefore)+ '到' +FormatDateTime('yyyy-mm-dd hh:nn:ss', SSL.SSLSocket.PeerCert.notAfter)
  finally
    SSL.Free;
    HTTP.Free;
  end;
end;

end.

 

Form

object Form1: TForm1
  Left = 0
  Top = 0
  BorderIcons = [biSystemMenu]
  Caption = #35777#20070#26377#25928#24615#26816#27979
  ClientHeight = 157
  ClientWidth = 558
  Color = clBtnFace
  Constraints.MaxHeight = 195
  Constraints.MaxWidth = 570
  Constraints.MinHeight = 195
  Constraints.MinWidth = 570
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'Segoe UI'
  Font.Style = []
  Position = poScreenCenter
  TextHeight = 15
  object Label1: TLabel
    Left = 24
    Top = 112
    Width = 513
    Height = 15
    Alignment = taCenter
    AutoSize = False
  end
  object Button1: TButton
    Left = 240
    Top = 64
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 8
    Top = 24
    Width = 542
    Height = 23
    TabOrder = 1
    Text = 'https://test.123456.com/'
  end
end

  

  

posted on 2024-09-10 11:15  码农的笔记  阅读(25)  评论(0编辑  收藏  举报