mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 12:44:42 +00:00
Parse S/MIME subject for email addresses
This commit is contained in:
parent
d1554a30b9
commit
44eca2de75
1 changed files with 26 additions and 0 deletions
|
@ -84,6 +84,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.security.Principal;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
|
@ -1101,6 +1102,31 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
|
||||
String fingerprint = EntityCertificate.getFingerprint(cert);
|
||||
List<String> emails = EntityCertificate.getAltSubjectName(cert);
|
||||
if (emails.size() == 0) {
|
||||
Principal principal = cert.getSubjectDN();
|
||||
if (principal != null) {
|
||||
String subject = principal.getName();
|
||||
if (subject != null) {
|
||||
Log.i("Parsing subject=" + subject);
|
||||
for (String p : subject.split(",")) {
|
||||
String[] kv = p.split("=");
|
||||
if (kv.length == 2) {
|
||||
String key = kv[0].trim();
|
||||
String value = kv[1].trim().toLowerCase();
|
||||
if (Helper.EMAIL_ADDRESS.matcher(value).matches() &&
|
||||
("CN".equalsIgnoreCase(key) ||
|
||||
"emailAddress".equalsIgnoreCase(key))) {
|
||||
if (!emails.contains(value))
|
||||
emails.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (emails.size() == 0)
|
||||
throw new IllegalArgumentException("No email address found in key");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
for (String email : emails) {
|
||||
|
|
Loading…
Reference in a new issue