Dart Requires Chilkat v11.0.0+
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
// We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
final sslCert = CkCert();
try {
http.getServerCert('apple.com', 443, sslCert);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final certChain = CkCertChain();
try {
sslCert.buildCertChain(certChain);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final cert = CkCert();
var i = 0;
final numCerts = certChain.numCerts;
while (i < numCerts) {
certChain.certAt(i, cert);
print('SubjectDN $i: ${cert.subjectDN}');
print('IssuerDN $i: ${cert.issuerDN}');
i++;
}
// If the certificate chain reaches the root CA cert, then the last cert in the chain
// is the root CA cert.
if (certChain.reachesRoot) {
final caCert = CkCert();
certChain.certAt(numCerts - 1, caCert);
print('CA Root Cert: ${caCert.subjectDN}');
}
}