PHP Requires Chilkat v11.0.0+
Chilkat2 PHP
Use a Custom Set of Trusted Root Certificates
See more Certificates Examples
Demonstrates how to build a set of trusted root certificates to be used globally by all Chilkat classes.Chilkat PHP Downloads
<?php
use Chilkat2\Cert;
use Chilkat2\TrustedRoots;
use Chilkat2\Zip;
use Chilkat2\ZipEntry;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$trustedRoots = new TrustedRoots();
// Indicate that we will NOT trust any pre-installed certificates on the system.
$trustedRoots->TrustSystemCaRoots = false;
// Thawte is a certificate authority that provides a .zip download of their
// root CA certificates: https://www.thawte.com/roots/index.html
// The direct download link is: https://www.verisign.com/support/thawte-roots.zip
// Note: The above URLs are valid at the time of writing this example (29-May-2015).
// Assuming the .zip has already been downloaded, open it and load each .pem file into
// our trusted roots object.
$zip = new Zip();
// Open a .zip containing PEM files, among other things..
try {
$zip->OpenZip('qa_data/certs/thawte-roots.zip');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$entry = new ZipEntry();
$pemStr = '';
$cert = new Cert();
$pattern = '*.pem';
try {
$zip->EntryMatching($pattern, $entry);
$bHasMoreEntries = true;
} catch (\Chilkat2\Exception $e) {
$bHasMoreEntries = false;
}
while ($bHasMoreEntries) {
echo 'Entry: ', $entry->FileName, "\n";
// Get the PEM of the CA cert:
$pemStr = $entry->UnzipToString(0, 'utf-8');
// Load it into a certificate object:
try {
$cert->LoadPem($pemStr);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
}
// Add it to the trusted roots.
$trustedRoots->AddCert($cert);
$bHasMoreEntries = $entry->GetNextMatch($pattern);
}
// Activate the trusted roots globally for all Chilkat objects.
// This call really shouldn't fail, so we're not checking the return value.
$trustedRoots->Activate();