From 0069f0cc9b319fcccaac3e4329290853730b7eee Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 13 Aug 2017 23:05:39 +0200 Subject: parse jid from CN in client certs if nothing else is available --- .../java/de/pixart/messenger/utils/CryptoHelper.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main/java') 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) { -- cgit v1.2.3