parse jid from CN in client certs if nothing else is available

This commit is contained in:
Daniel Gultsch 2017-08-07 16:02:48 +02:00
parent 4a43df8c97
commit cce5a7b39f
1 changed files with 12 additions and 4 deletions

View File

@ -161,16 +161,24 @@ public final class CryptoHelper {
} }
} }
X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject(); X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
if (emails.size() == 0) { if (emails.size() == 0 && x500name.getRDNs(BCStyle.EmailAddress).length > 0) {
emails.add(IETFUtils.valueToString(x500name.getRDNs(BCStyle.EmailAddress)[0].getFirst().getValue())); emails.add(IETFUtils.valueToString(x500name.getRDNs(BCStyle.EmailAddress)[0].getFirst().getValue()));
} }
String name = IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue()); String name = x500name.getRDNs(BCStyle.CN).length > 0 ? IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue()) : null;
if (emails.size() >= 1) { if (emails.size() >= 1) {
return new Pair<>(Jid.fromString(emails.get(0)), name); return new Pair<>(Jid.fromString(emails.get(0)), name);
} else { } else if (name != null){
try {
Jid jid = Jid.fromString(name);
if (jid.isBareJid() && !jid.isDomainJid()) {
return new Pair<>(jid,null);
}
} catch (InvalidJidException e) {
return null; return null;
} }
} }
return null;
}
public static Bundle extractCertificateInformation(X509Certificate certificate) { public static Bundle extractCertificateInformation(X509Certificate certificate) {
Bundle information = new Bundle(); Bundle information = new Bundle();