getSSLDetails function

Future<SSLDetails?> getSSLDetails(
  1. Uri url
)

Fetches SSL details for a given URL.

This function uses HttpClient to make a connection to the specified url, and extracts SSL certificate details (subject and issuer) if available.

Parameters:

  • url (Uri): The URL to retrieve SSL details from.

Returns:

  • Future<SSLDetails?>: A future that completes with an SSLDetails object containing the SSL certificate information or null if unavailable.

Implementation

Future<SSLDetails?> getSSLDetails(Uri url) async {
  var client = HttpClient(context: SecurityContext.defaultContext);
  var request = await client.getUrl(url);
  var response = await request.close();
  final sslDetails = SSLDetails(subject: 'No Data', issuer: 'No Data');
  response.listen((_) {}, onDone: () {
    var certificate = response.certificate;
    if (certificate != null) {
      sslDetails.subject = certificate.subject;
      sslDetails.issuer = certificate.issuer;
    }
  });
  return sslDetails;
}