Rust Requires Chilkat v11.0.0+
Rust
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 Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let trusted_roots = chilkat::TrustedRoots::new();
// Indicate that we will NOT trust any pre-installed certificates on the system.
trusted_roots.set_trust_system_ca_roots(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.
let zip = chilkat::Zip::new();
// Open a .zip containing PEM files, among other things..
if zip.open_zip("qa_data/certs/thawte-roots.zip").is_err() {
println!("{}", zip.last_error_text());
return;
}
let entry = chilkat::ZipEntry::new();
let mut pem_str = String::new();
let cert = chilkat::Cert::new();
let pattern = "*.pem".to_string();
let mut b_has_more_entries = zip.entry_matching(&pattern, &entry).is_ok();
while b_has_more_entries {
println!("Entry: {}", entry.file_name());
// Get the PEM of the CA cert:
pem_str = entry.unzip_to_string(0, "utf-8").unwrap_or_default();
// Load it into a certificate object:
if cert.load_pem(&pem_str).is_err() {
println!("{}", cert.last_error_text());
}
// Add it to the trusted roots.
let _ = trusted_roots.add_cert(&cert);
b_has_more_entries = entry.get_next_match(&pattern).is_ok();
}
// Activate the trusted roots globally for all Chilkat objects.
// This call really shouldn't fail, so we're not checking the return value.
let _ = trusted_roots.activate().is_ok();