Added type checks

pull/217/head
M66B 9 months ago
parent ed00428cb3
commit 763240bd65

@ -192,25 +192,27 @@ public class EntityCertificate {
Collection<List<?>> altNames = certificate.getSubjectAlternativeNames(); Collection<List<?>> altNames = certificate.getSubjectAlternativeNames();
if (altNames != null) if (altNames != null)
for (List altName : altNames) for (List altName : altNames)
if (altName.get(0).equals(GeneralName.rfc822Name)) if (altName.get(0).equals(GeneralName.rfc822Name)) {
result.add((String) altName.get(1)); if (altName.get(1) instanceof String)
else if (altName.get(0).equals(GeneralName.otherName) && altName.get(1) instanceof byte[]) result.add((String) altName.get(1));
try { } else if (altName.get(0).equals(GeneralName.otherName)) {
ASN1InputStream decoder = new ASN1InputStream((byte[]) altName.get(1)); if (altName.get(1) instanceof byte[])
DLTaggedObject encoded = (DLTaggedObject) decoder.readObject(); try {
String otherName = DERUTF8String.getInstance( ASN1InputStream decoder = new ASN1InputStream((byte[]) altName.get(1));
((DLTaggedObject) ((DLSequence) encoded.getBaseObject()) DLTaggedObject encoded = (DLTaggedObject) decoder.readObject();
.getObjectAt(1)).getBaseObject()).getString(); String otherName = DERUTF8String.getInstance(
int at = otherName.indexOf('@'); ((DLTaggedObject) ((DLSequence) encoded.getBaseObject())
int dot = otherName.lastIndexOf('.'); .getObjectAt(1)).getBaseObject()).getString();
if (at >= 0 && dot > at) // UTF-8 accepted, so basic test only int at = otherName.indexOf('@');
result.add(otherName); int dot = otherName.lastIndexOf('.');
else if (at >= 0 && dot > at) // UTF-8 accepted, so basic test only
Log.w("Ignoring otherName=" + otherName); result.add(otherName);
} catch (Throwable ex) { else
Log.w(ex); Log.w("Ignoring otherName=" + otherName);
} } catch (Throwable ex) {
else Log.w(ex);
}
} else
Log.i("Alt type=" + altName.get(0) + " data=" + altName.get(1)); Log.i("Alt type=" + altName.get(0) + " data=" + altName.get(1));
} catch (CertificateParsingException ex) { } catch (CertificateParsingException ex) {
Log.e(ex); Log.e(ex);
@ -252,9 +254,10 @@ public class EntityCertificate {
for (List altName : altNames) for (List altName : altNames)
try { try {
if (altName.get(0).equals(GeneralName.dNSName)) if (altName.get(0).equals(GeneralName.dNSName)) {
result.add((String) altName.get(1)); if (altName.get(1) instanceof String)
else if (altName.get(0).equals(GeneralName.iPAddress)) result.add((String) altName.get(1));
} else if (altName.get(0).equals(GeneralName.iPAddress))
if (altName.get(1) instanceof String) if (altName.get(1) instanceof String)
result.add((String) altName.get(1)); result.add((String) altName.get(1));
else { else {

Loading…
Cancel
Save