From 36d2ecfcfa9351809655731f57b1249c96f9f91c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 13 May 2020 09:38:30 +0200 Subject: [PATCH] always use private key for TLS connection when one is configured --- .../eu/siacs/conversations/ui/ManageAccountActivity.java | 6 +++--- .../conversations/services/XmppConnectionService.java | 3 +-- .../java/eu/siacs/conversations/xmpp/XmppConnection.java | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java index f694e5dba..53841a301 100644 --- a/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -408,15 +408,15 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda } @Override - public void alias(String alias) { + public void alias(final String alias) { if (alias != null) { xmppConnectionService.createAccountFromKey(alias, this); } } @Override - public void onAccountCreated(Account account) { - Intent intent = new Intent(this, EditAccountActivity.class); + public void onAccountCreated(final Account account) { + final Intent intent = new Intent(this, EditAccountActivity.class); intent.putExtra("jid", account.getJid().asBareJid().toString()); intent.putExtra("init", true); startActivity(intent); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 4b1c5c2ff..fc7fb5b37 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2196,7 +2196,7 @@ public class XmppConnectionService extends Service { return; } if (findAccountByJid(info.first) == null) { - Account account = new Account(info.first, ""); + final Account account = new Account(info.first, ""); account.setPrivateKeyAlias(alias); account.setOption(Account.OPTION_DISABLED, true); account.setDisplayName(info.second); @@ -2213,7 +2213,6 @@ public class XmppConnectionService extends Service { callback.informUser(R.string.account_already_exists); } } catch (Exception e) { - e.printStackTrace(); callback.informUser(R.string.unable_to_parse_certificate); } }).start(); diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index d9a4ee9b5..8641935af 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -428,14 +428,14 @@ public class XmppConnection implements Runnable { private TlsFactoryVerifier getTlsFactoryVerifier() throws NoSuchAlgorithmException, KeyManagementException, IOException { final SSLContext sc = SSLSocketHelper.getSSLContext(); - MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager(); - KeyManager[] keyManager; - if (account.getPrivateKeyAlias() != null && account.getPassword().isEmpty()) { + final MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager(); + final KeyManager[] keyManager; + if (account.getPrivateKeyAlias() != null) { keyManager = new KeyManager[]{new MyKeyManager()}; } else { keyManager = null; } - String domain = account.getJid().getDomain(); + final String domain = account.getJid().getDomain(); sc.init(keyManager, new X509TrustManager[]{mInteractive ? trustManager.getInteractive(domain) : trustManager.getNonInteractive(domain)}, mXmppConnectionService.getRNG()); final SSLSocketFactory factory = sc.getSocketFactory(); final DomainHostnameVerifier verifier = trustManager.wrapHostnameVerifier(new XmppDomainVerifier(), mInteractive);