PowerBuilder
PowerBuilder
Load Certs from Java KeyStore into Trusted CA Roots
See more Java KeyStore (JKS) Examples
Demonstrates how to load a Java KeyStore containing CA root certificates that are to be trusted by the application. This can be done once at the beginning of an application, and then the trusted roots can be activated so that only these root CA certs are trusted by the application for any TLS connections.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Jks
string ls_Password
oleobject loo_Troots
integer i
integer li_NumCerts
oleobject loo_Cacert
li_Success = 0
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Jks = create oleobject
li_rc = loo_Jks.ConnectToNewObject("Chilkat.JavaKeyStore")
if li_rc < 0 then
destroy loo_Jks
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Jks.VerboseLogging = 1
ls_Password = "myPassword"
li_Success = loo_Jks.LoadFile(ls_Password,"qa_data/jks/entrust_caCerts.jks")
if li_Success <> 1 then
Write-Debug loo_Jks.LastErrorText
destroy loo_Jks
return
end if
loo_Troots = create oleobject
li_rc = loo_Troots.ConnectToNewObject("Chilkat.TrustedRoots")
loo_Troots.VerboseLogging = 1
li_Success = loo_Troots.AddJavaKeyStore(loo_Jks)
if li_Success <> 1 then
Write-Debug loo_Troots.LastErrorText
destroy loo_Jks
destroy loo_Troots
return
end if
i = 0
li_NumCerts = loo_Troots.NumCerts
do while (i < li_NumCerts)
loo_Cacert = loo_Troots.GetCert(i)
Write-Debug string(i) + ": " + loo_Cacert.SubjectDN
destroy loo_Cacert
i = i + 1
loop
// Activate this specific set of trusted roots.
li_Success = loo_Troots.Activate()
if li_Success <> 1 then
Write-Debug loo_Troots.LastErrorText
destroy loo_Jks
destroy loo_Troots
return
end if
// Output:
// 0: C=US, O=Entrust.net, OU=www.entrust.net/CPS incorp. by ref. (limits liab.), OU=(c) 1999 Entrust.net Limited, CN=Entrust.net Secure Server Certification Authority
// 1: O=Entrust.net, OU=www.entrust.net/CPS_2048 incorp. by ref. (limits liab.), OU=(c) 1999 Entrust.net Limited, CN=Entrust.net Certification Authority (2048)
// 2: C=US, O="Entrust, Inc.", OU=www.entrust.net/CPS is incorporated by reference, OU="(c) 2006 Entrust, Inc.", CN=Entrust Root Certification Authority
destroy loo_Jks
destroy loo_Troots