Use subject CN as DNS name

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

@ -218,23 +218,39 @@ public class EntityCertificate {
List<String> result = new ArrayList<>();
Collection<List<?>> altNames = certificate.getSubjectAlternativeNames();
if (altNames == null)
return result;
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(1) instanceof String)
if (altNames != null)
for (List altName : altNames)
try {
if (altName.get(0).equals(GeneralName.dNSName))
result.add((String) altName.get(1));
else {
Object val = altName.get(1);
Log.e("GeneralName.iPAddress type=" + (val == null ? null : val.getClass()));
else if (altName.get(0).equals(GeneralName.iPAddress))
if (altName.get(1) instanceof String)
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) {
Log.e(ex);
}
} catch (Throwable ex) {
Log.e(ex);
}
return result;
}

Loading…
Cancel
Save