I want to verify the hostname of a given certificate (X509Certificate object). That is, to check whether the hostname matches any of the hostnames listed in the certificate's "Subject Alternative Name" or "Common Name" field.
I read online that you can import javax.net.ssl.HostnameVerifier
and then use HttpsURLConnection.getDefaultHostnameVerifier().verify(...)
to do that. However, the verify
function takes an SSLSession object so it won't work with an X509Certificate object.
I would appreciate your help. Thanks.