Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

Verify SSL Server Certificate

See more Socket/SSL/TLS Examples

Demonstrates how to connect to an SSL server and verify its SSL certificate.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final socket = CkSocket();

  final ssl = true;
  final maxWaitMillisec = 20000;

  // The SSL server hostname may be an IP address, a domain name,
  // or "localhost". 
  final sslServerHost = 'www.paypal.com';
  final sslServerPort = 443;

  // Connect to the SSL server:
  try {
    socket.connect(sslServerHost, sslServerPort, ssl, maxWaitMillisec);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final cert = CkCert();

  var bExpired = false;
  var bRevoked = false;
  var bSignatureVerified = false;
  var bTrustedRoot = false;

  try {
    socket.getServerCert(cert);

    print('Server Certificate:');
    print('Distinguished Name: ${cert.subjectDN}');
    print('Common Name: ${cert.subjectCN}');
    print('Issuer Distinguished Name: ${cert.issuerDN}');
    print('Issuer Common Name: ${cert.issuerCN}');

    bExpired = cert.expired;
    bRevoked = cert.revoked;
    bSignatureVerified = cert.signatureVerified;
    bTrustedRoot = cert.trustedRoot;

    print('Expired: $bExpired');
    print('Revoked: $bRevoked');
    print('Signature Verified: $bSignatureVerified');
    print('Trusted Root: $bTrustedRoot');
  } on ChilkatException {
    // socket.getServerCert() failed; continue anyway.
  }

  // Close the connection with the server
  // Wait a max of 20 seconds (20000 millsec)
  socket.close(20000);
}