always use private key for TLS connection when one is configured

This commit is contained in:
Daniel Gultsch 2020-05-13 09:38:30 +02:00
parent 7c4566e561
commit 36d2ecfcfa
3 changed files with 8 additions and 9 deletions

View File

@ -408,15 +408,15 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
} }
@Override @Override
public void alias(String alias) { public void alias(final String alias) {
if (alias != null) { if (alias != null) {
xmppConnectionService.createAccountFromKey(alias, this); xmppConnectionService.createAccountFromKey(alias, this);
} }
} }
@Override @Override
public void onAccountCreated(Account account) { public void onAccountCreated(final Account account) {
Intent intent = new Intent(this, EditAccountActivity.class); final Intent intent = new Intent(this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().asBareJid().toString()); intent.putExtra("jid", account.getJid().asBareJid().toString());
intent.putExtra("init", true); intent.putExtra("init", true);
startActivity(intent); startActivity(intent);

View File

@ -2196,7 +2196,7 @@ public class XmppConnectionService extends Service {
return; return;
} }
if (findAccountByJid(info.first) == null) { if (findAccountByJid(info.first) == null) {
Account account = new Account(info.first, ""); final Account account = new Account(info.first, "");
account.setPrivateKeyAlias(alias); account.setPrivateKeyAlias(alias);
account.setOption(Account.OPTION_DISABLED, true); account.setOption(Account.OPTION_DISABLED, true);
account.setDisplayName(info.second); account.setDisplayName(info.second);
@ -2213,7 +2213,6 @@ public class XmppConnectionService extends Service {
callback.informUser(R.string.account_already_exists); callback.informUser(R.string.account_already_exists);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
callback.informUser(R.string.unable_to_parse_certificate); callback.informUser(R.string.unable_to_parse_certificate);
} }
}).start(); }).start();

View File

@ -428,14 +428,14 @@ public class XmppConnection implements Runnable {
private TlsFactoryVerifier getTlsFactoryVerifier() throws NoSuchAlgorithmException, KeyManagementException, IOException { private TlsFactoryVerifier getTlsFactoryVerifier() throws NoSuchAlgorithmException, KeyManagementException, IOException {
final SSLContext sc = SSLSocketHelper.getSSLContext(); final SSLContext sc = SSLSocketHelper.getSSLContext();
MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager(); final MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager();
KeyManager[] keyManager; final KeyManager[] keyManager;
if (account.getPrivateKeyAlias() != null && account.getPassword().isEmpty()) { if (account.getPrivateKeyAlias() != null) {
keyManager = new KeyManager[]{new MyKeyManager()}; keyManager = new KeyManager[]{new MyKeyManager()};
} else { } else {
keyManager = null; 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()); sc.init(keyManager, new X509TrustManager[]{mInteractive ? trustManager.getInteractive(domain) : trustManager.getNonInteractive(domain)}, mXmppConnectionService.getRNG());
final SSLSocketFactory factory = sc.getSocketFactory(); final SSLSocketFactory factory = sc.getSocketFactory();
final DomainHostnameVerifier verifier = trustManager.wrapHostnameVerifier(new XmppDomainVerifier(), mInteractive); final DomainHostnameVerifier verifier = trustManager.wrapHostnameVerifier(new XmppDomainVerifier(), mInteractive);