validateCertificate method

  1. @override
bool validateCertificate(
  1. X509Certificate? cert,
  2. String host,
  3. int port,
  4. Map<String, bool> fingerprints,
)
override

Implementation

@override
bool validateCertificate(
  X509Certificate? cert,
  String host,
  int port,
  Map<String, bool> fingerprints,
) {
  // Check that the cert fingerprint matches the one we expect.
  if (cert == null) {
    return false;
  }
  // Validate it any way you want.
  final fingerprint = sha256.convert(cert.der).toString();
  if (fingerprint.isEmpty) {
    return false;
  }

  // Validate
  final hasMatches = customValidator.validate(cert, host, port);

  return (fingerprints[fingerprint] == true) && hasMatches;
}