getSSLDetails function
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 anSSLDetails
object containing the SSL certificate information ornull
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;
}