diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-08-13 23:05:39 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-08-13 23:05:39 +0200 |
commit | 0069f0cc9b319fcccaac3e4329290853730b7eee (patch) | |
tree | 655e04d961e453a1f7861b631778a7537fc8f343 | |
parent | 0025cf65dd70f215ad10007bde8302ea7f17e735 (diff) |
parse jid from CN in client certs if nothing else is available
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/CryptoHelper.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java index da34200bf..f9abe8c90 100644 --- a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java +++ b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java @@ -160,15 +160,23 @@ public final class CryptoHelper { } } 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())); } - 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) { return new Pair<>(Jid.fromString(emails.get(0)), name); - } else { - return null; + } 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; } public static Bundle extractCertificateInformation(X509Certificate certificate) { |