Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Load Particular CA Certs into a Java KeyStoreOpens a PEM file containing many CA root certificates, and creates a Java keystore containing a subset of the certificates.
IncludeFile "CkTrustedRoots.pb" IncludeFile "CkCert.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJavaKeyStore.pb" Procedure ChilkatExample() ; This requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. jks.i = CkJavaKeyStore::ckCreate() If jks.i = 0 Debug "Failed to create object." ProcedureReturn EndIf troots.i = CkTrustedRoots::ckCreate() If troots.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Load certificates from a file. success.i = CkTrustedRoots::ckLoadCaCertsPem(troots,"qa_data/curl_cacert.pem") If success <> 1 Debug CkTrustedRoots::ckLastErrorText(troots) CkJavaKeyStore::ckDispose(jks) CkTrustedRoots::ckDispose(troots) ProcedureReturn EndIf sbDn.i = CkStringBuilder::ckCreate() If sbDn.i = 0 Debug "Failed to create object." ProcedureReturn EndIf sbAlias.i = CkStringBuilder::ckCreate() If sbAlias.i = 0 Debug "Failed to create object." ProcedureReturn EndIf caseSensitive.i = 0 i.i = 0 numCerts.i = CkTrustedRoots::ckNumCerts(troots) numAdded.i = 0 While (i < numCerts) cacert.i = CkTrustedRoots::ckGetCert(troots,i) CkStringBuilder::ckClear(sbDn) CkStringBuilder::ckAppend(sbDn,CkCert::ckSubjectDN(cacert)) If CkStringBuilder::ckContains(sbDn,"Entrust.net",caseSensitive) = 1 Debug CkCert::ckSubjectDN(cacert) ; The alias is an arbitrary unique string for each cert in the JKS. CkStringBuilder::ckClear(sbAlias) CkStringBuilder::ckAppend(sbAlias,"cacert_") CkStringBuilder::ckAppendInt(sbAlias,i + 1) CkJavaKeyStore::ckAddTrustedCert(jks,cacert,CkStringBuilder::ckGetAsString(sbAlias)) numAdded = numAdded + 1 EndIf CkCert::ckDispose(cacert) i = i + 1 Wend ; Verify the number of certs in the JKS equals the number we added. numJksCerts.i = CkJavaKeyStore::ckNumTrustedCerts(jks) Debug "NumTrustedCerts = " + Str(numJksCerts) If numJksCerts <> numAdded Debug "Something is amiss!" CkJavaKeyStore::ckDispose(jks) CkTrustedRoots::ckDispose(troots) CkStringBuilder::ckDispose(sbDn) CkStringBuilder::ckDispose(sbAlias) ProcedureReturn EndIf ; Save the JKS. success = CkJavaKeyStore::ckToFile(jks,"myPassword","qa_data/jks/entrust_caCerts.jks") If success <> 1 Debug CkJavaKeyStore::ckLastErrorText(jks) CkJavaKeyStore::ckDispose(jks) CkTrustedRoots::ckDispose(troots) CkStringBuilder::ckDispose(sbDn) CkStringBuilder::ckDispose(sbAlias) ProcedureReturn EndIf Debug "Success." ; The output of this program when tested was: ; 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 ; 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) ; C=US, O="Entrust, Inc.", OU=www.entrust.net/CPS is incorporated by reference, OU="(c) 2006 Entrust, Inc.", CN=Entrust Root Certification Authority ; NumTrustedCerts = 3 ; Success. CkJavaKeyStore::ckDispose(jks) CkTrustedRoots::ckDispose(troots) CkStringBuilder::ckDispose(sbDn) CkStringBuilder::ckDispose(sbAlias) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.