Rust Requires Chilkat v11.0.0+
Rust
Get the Server Certificate, Certificate Chain, and Root CA Certificate
See more HTTP Examples
Demonstrates how to get the HTTP server certificate, its certificate chain, and the root CA certificate.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
let ssl_cert = chilkat::Cert::new();
if http.get_server_cert("apple.com", 443, &ssl_cert).is_err() {
println!("{}", http.last_error_text());
return;
}
let cert_chain = chilkat::CertChain::new();
if ssl_cert.build_cert_chain(&cert_chain).is_err() {
println!("{}", ssl_cert.last_error_text());
return;
}
let cert = chilkat::Cert::new();
let mut i = 0;
let num_certs = cert_chain.num_certs();
while i < num_certs {
let _ = cert_chain.cert_at(i, &cert);
println!("SubjectDN {}: {}", i, cert.subject_dn());
println!("IssuerDN {}: {}", i, cert.issuer_dn());
i = i + 1;
}
// If the certificate chain reaches the root CA cert, then the last cert in the chain
// is the root CA cert.
if cert_chain.reaches_root() {
let ca_cert = chilkat::Cert::new();
let _ = cert_chain.cert_at(num_certs - 1, &ca_cert);
println!("CA Root Cert: {}", ca_cert.subject_dn());
}