Use subject CN as DNS name

pull/208/head
M66B 3 years ago
parent 984bf86441
commit 0d9f00f366

@ -218,23 +218,39 @@ public class EntityCertificate {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
Collection<List<?>> altNames = certificate.getSubjectAlternativeNames(); Collection<List<?>> altNames = certificate.getSubjectAlternativeNames();
if (altNames == null) if (altNames != null)
return result; for (List altName : altNames)
try {
for (List altName : altNames) if (altName.get(0).equals(GeneralName.dNSName))
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(1) instanceof String)
result.add((String) altName.get(1)); result.add((String) altName.get(1));
else { else if (altName.get(0).equals(GeneralName.iPAddress))
Object val = altName.get(1); if (altName.get(1) instanceof String)
Log.e("GeneralName.iPAddress type=" + (val == null ? null : val.getClass())); result.add((String) altName.get(1));
else {
Object val = altName.get(1);
Log.e("GeneralName.iPAddress type=" + (val == null ? null : val.getClass()));
}
} catch (Throwable ex) {
Log.e(ex);
}
try {
X500Name name = new JcaX509CertificateHolder(certificate).getSubject();
if (name != null)
for (RDN rdn : name.getRDNs(BCStyle.CN))
for (AttributeTypeAndValue tv : rdn.getTypesAndValues()) {
ASN1Encodable enc = tv.getValue();
if (enc == null)
continue;
String cn = enc.toString();
if (TextUtils.isEmpty(cn))
continue;
if (!result.contains(cn))
result.add(cn);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
} }
return result; return result;
} }

Loading…
Cancel
Save