mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-31 14:17:03 +02:00
Quick setup: use similar host name from certificate
This commit is contained in:
@@ -41,6 +41,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.CertificateException;
|
||||
@@ -216,6 +217,31 @@ public class EntityCertificate {
|
||||
return result;
|
||||
}
|
||||
|
||||
static String getSimilarDnsName(X509Certificate certificate, @NonNull String host) {
|
||||
if (certificate == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
InetAddress haddr = InetAddress.getByName(host);
|
||||
List<String> names = getDnsNames(certificate);
|
||||
for (String _name : names)
|
||||
try {
|
||||
String name = (_name.startsWith("*.") ? _name.substring(2) : _name);
|
||||
InetAddress naddr = InetAddress.getByName(name);
|
||||
Log.i("host=" + host + " name=" + _name + "" +
|
||||
" haddr=" + haddr + " naddr=" + naddr);
|
||||
if (haddr.equals(naddr))
|
||||
return name;
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static boolean matches(String server, List<String> names) {
|
||||
for (String name : names)
|
||||
if (matches(server, name)) {
|
||||
|
||||
Reference in New Issue
Block a user