Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get the S/MIME Signer's Certificate
See more MIME Examples
Demonstrates the Chilkat Mime.LastSignerCert method, which loads the signer certificate at a zero-based index from the most recent successful verification (or security-unwrapping) into a Cert. The first argument is the signer index and the second is the receiving Cert.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: Verifying tells you the signature is mathematically valid, but you usually also need to know who signed — the subject, the issuer, the validity dates — to decide whether to trust it. This retrieves each signer's certificate after verification so your code can inspect and apply its own trust rules. A message can have multiple signers, so iterate from
0 to NumSignerCerts - 1.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Cert,
Chilkat.Mime;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mime: TMime;
n: Integer;
cert: TCert;
i: Integer;
begin
success := False;
mime := TMime.Create;
success := mime.LoadMimeFile('qa_data/signed.eml');
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// After a successful verification, load each signer's certificate to inspect it. The 1st argument
// is the zero-based signer index and the 2nd is a Cert object that receives the certificate.
success := mime.Verify();
if (success <> True) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
n := mime.NumSignerCerts;
cert := TCert.Create;
for i := 0 to n - 1 do
begin
success := mime.LastSignerCert(i,cert);
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn('Signer ' + i + ': ' + cert.SubjectCN + ' (issued by ' + cert.IssuerCN + ')');
end;
mime.Free;
cert.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.