Delphi DLL
Delphi DLL
Get the Configured Server-Side TLS Certificate
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetMyServerCert, which copies the TLS server certificate configured by InitSslServer into a Cert object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. This is intended for a socket acting as a TLS server and returns false when no server certificate has been configured.
Chilkat Delphi DLL Downloads
var
success: Boolean;
socket: HCkSocket;
pfxPassword: PWideChar;
cert: HCkCert;
myCert: HCkCert;
begin
success := False;
socket := CkSocket_Create();
// The file path is relative to the application's current working directory. An absolute path
// may also be used. Supply the path appropriate to your own environment.
// The PFX password should come from a secure source rather than being hard-coded.
pfxPassword := 'myPfxPassword';
cert := CkCert_Create();
success := CkCert_LoadPfxFile(cert,'qa_data/server.pfx',pfxPassword);
if (success = False) then
begin
Memo1.Lines.Add(CkCert__lastErrorText(cert));
Exit;
end;
success := CkSocket_InitSslServer(socket,cert);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(socket));
Exit;
end;
// Copy the TLS server certificate configured by InitSslServer, then inspect it.
myCert := CkCert_Create();
success := CkSocket_GetMyServerCert(socket,myCert);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(socket));
Exit;
end;
Memo1.Lines.Add('Server certificate subject: ' + CkCert__subjectCN(myCert));
CkSocket_Dispose(socket);
CkCert_Dispose(cert);
CkCert_Dispose(myCert);