mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-22 07:42:52 +00:00
Added type checks
This commit is contained in:
parent
ed00428cb3
commit
763240bd65
1 changed files with 25 additions and 22 deletions
|
@ -192,25 +192,27 @@ public class EntityCertificate {
|
|||
Collection<List<?>> altNames = certificate.getSubjectAlternativeNames();
|
||||
if (altNames != null)
|
||||
for (List altName : altNames)
|
||||
if (altName.get(0).equals(GeneralName.rfc822Name))
|
||||
result.add((String) altName.get(1));
|
||||
else if (altName.get(0).equals(GeneralName.otherName) && altName.get(1) instanceof byte[])
|
||||
try {
|
||||
ASN1InputStream decoder = new ASN1InputStream((byte[]) altName.get(1));
|
||||
DLTaggedObject encoded = (DLTaggedObject) decoder.readObject();
|
||||
String otherName = DERUTF8String.getInstance(
|
||||
((DLTaggedObject) ((DLSequence) encoded.getBaseObject())
|
||||
.getObjectAt(1)).getBaseObject()).getString();
|
||||
int at = otherName.indexOf('@');
|
||||
int dot = otherName.lastIndexOf('.');
|
||||
if (at >= 0 && dot > at) // UTF-8 accepted, so basic test only
|
||||
result.add(otherName);
|
||||
else
|
||||
Log.w("Ignoring otherName=" + otherName);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
else
|
||||
if (altName.get(0).equals(GeneralName.rfc822Name)) {
|
||||
if (altName.get(1) instanceof String)
|
||||
result.add((String) altName.get(1));
|
||||
} else if (altName.get(0).equals(GeneralName.otherName)) {
|
||||
if (altName.get(1) instanceof byte[])
|
||||
try {
|
||||
ASN1InputStream decoder = new ASN1InputStream((byte[]) altName.get(1));
|
||||
DLTaggedObject encoded = (DLTaggedObject) decoder.readObject();
|
||||
String otherName = DERUTF8String.getInstance(
|
||||
((DLTaggedObject) ((DLSequence) encoded.getBaseObject())
|
||||
.getObjectAt(1)).getBaseObject()).getString();
|
||||
int at = otherName.indexOf('@');
|
||||
int dot = otherName.lastIndexOf('.');
|
||||
if (at >= 0 && dot > at) // UTF-8 accepted, so basic test only
|
||||
result.add(otherName);
|
||||
else
|
||||
Log.w("Ignoring otherName=" + otherName);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
} else
|
||||
Log.i("Alt type=" + altName.get(0) + " data=" + altName.get(1));
|
||||
} catch (CertificateParsingException ex) {
|
||||
Log.e(ex);
|
||||
|
@ -252,9 +254,10 @@ public class EntityCertificate {
|
|||
|
||||
for (List altName : altNames)
|
||||
try {
|
||||
if (altName.get(0).equals(GeneralName.dNSName))
|
||||
result.add((String) altName.get(1));
|
||||
else if (altName.get(0).equals(GeneralName.iPAddress))
|
||||
if (altName.get(0).equals(GeneralName.dNSName)) {
|
||||
if (altName.get(1) instanceof String)
|
||||
result.add((String) altName.get(1));
|
||||
} else if (altName.get(0).equals(GeneralName.iPAddress))
|
||||
if (altName.get(1) instanceof String)
|
||||
result.add((String) altName.get(1));
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue