mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 23:12:55 +00:00
Quick setup: use similar host name from certificate
This commit is contained in:
parent
1403f4f520
commit
762edcd740
2 changed files with 36 additions and 2 deletions
|
@ -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)) {
|
||||
|
|
|
@ -309,7 +309,11 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
null, null);
|
||||
} catch (EmailService.UntrustedException ex) {
|
||||
imap_certificate = ex.getCertificate();
|
||||
imap_fingerprint = EntityCertificate.getKeyFingerprint(imap_certificate);
|
||||
String similar = EntityCertificate.getSimilarDnsName(imap_certificate, provider.imap.host);
|
||||
if (similar == null)
|
||||
imap_fingerprint = EntityCertificate.getKeyFingerprint(imap_certificate);
|
||||
else
|
||||
provider.imap.host = similar;
|
||||
iservice.connect(
|
||||
provider.imap.host, provider.imap.port,
|
||||
AUTH_TYPE_PASSWORD, null,
|
||||
|
@ -373,7 +377,11 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
null, null);
|
||||
} catch (EmailService.UntrustedException ex) {
|
||||
smtp_certificate = ex.getCertificate();
|
||||
smtp_fingerprint = EntityCertificate.getKeyFingerprint(smtp_certificate);
|
||||
String similar = EntityCertificate.getSimilarDnsName(smtp_certificate, provider.smtp.host);
|
||||
if (similar == null)
|
||||
smtp_fingerprint = EntityCertificate.getKeyFingerprint(smtp_certificate);
|
||||
else
|
||||
provider.smtp.host = similar;
|
||||
iservice.connect(
|
||||
provider.smtp.host, provider.smtp.port,
|
||||
AUTH_TYPE_PASSWORD, null,
|
||||
|
|
Loading…
Reference in a new issue