Sample code for 30+ languages & platforms
PowerBuilder

Get the Server Certificate from a TLS Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetServerCert, which copies the certificate presented by the remote TLS server into a Cert object for inspection.

Background. The method returns false when the socket is not connected, is not using TLS, or no server certificate is available. Inspecting the certificate lets an application validate the server's identity.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
integer li_BTls
integer li_MaxWaitMs
oleobject loo_Cert

li_Success = 0

loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
    destroy loo_Socket
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Connect to the server using TLS.
li_BTls = 1
li_MaxWaitMs = 5000
li_Success = loo_Socket.Connect("example.com",5000,li_BTls,li_MaxWaitMs)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

//  Copy the certificate presented by the remote TLS server, then inspect it.  This can be used to
//  validate the server's identity.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_Socket.GetServerCert(loo_Cert)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    destroy loo_Cert
    return
end if

Write-Debug "Server certificate subject: " + loo_Cert.SubjectCN
Write-Debug "Issued by: " + loo_Cert.IssuerCN


destroy loo_Socket
destroy loo_Cert