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
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);

View file

@ -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();

View file

@ -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);