use of de.pixart.messenger.services.MemorizingTrustManager in project Pix-Art-Messenger by kriztan.
the class SettingsActivity method onStart.
@Override
public void onStart() {
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
multiAccountPreference = mSettingsFragment.findPreference("enable_multi_accounts");
if (multiAccountPreference != null) {
isMultiAccountChecked = ((CheckBoxPreference) multiAccountPreference).isChecked();
}
if (Config.FORCE_ORBOT) {
PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
if (connectionOptions != null) {
expert.removePreference(connectionOptions);
}
}
PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen");
// this feature is only available on Huawei Android 6.
PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
if (huaweiPreferenceScreen != null) {
Intent intent = huaweiPreferenceScreen.getIntent();
// remove when Api version is above M (Version 6.0) or if the intent is not callable
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general");
generalCategory.removePreference(huaweiPreferenceScreen);
if (generalCategory.getPreferenceCount() == 0) {
if (mainPreferenceScreen != null) {
mainPreferenceScreen.removePreference(generalCategory);
}
}
}
}
ListPreference automaticMessageDeletionList = (ListPreference) mSettingsFragment.findPreference(AUTOMATIC_MESSAGE_DELETION);
if (automaticMessageDeletionList != null) {
final int[] choices = getResources().getIntArray(R.array.automatic_message_deletion_values);
CharSequence[] entries = new CharSequence[choices.length];
CharSequence[] entryValues = new CharSequence[choices.length];
for (int i = 0; i < choices.length; ++i) {
Log.d(Config.LOGTAG, "resolving choice " + choices[i]);
entryValues[i] = String.valueOf(choices[i]);
if (choices[i] == 0) {
entries[i] = getString(R.string.never);
} else {
entries[i] = TimeframeUtils.resolve(this, 1000L * choices[i]);
}
}
automaticMessageDeletionList.setEntries(entries);
automaticMessageDeletionList.setEntryValues(entryValues);
}
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
if (removeCertsPreference != null) {
removeCertsPreference.setOnPreferenceClickListener(preference -> {
final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
if (aliases.size() == 0) {
displayToast(getString(R.string.toast_no_trusted_certs));
return true;
}
final ArrayList selectedItems = new ArrayList<>();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null, (dialog, indexSelected, isChecked) -> {
if (isChecked) {
selectedItems.add(indexSelected);
} else if (selectedItems.contains(indexSelected)) {
selectedItems.remove(Integer.valueOf(indexSelected));
}
if (selectedItems.size() > 0)
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
else {
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
}
});
dialogBuilder.setPositiveButton(getResources().getString(R.string.dialog_manage_certs_positivebutton), (dialog, which) -> {
int count = selectedItems.size();
if (count > 0) {
for (int i = 0; i < count; i++) {
try {
Integer item = Integer.valueOf(selectedItems.get(i).toString());
String alias = aliases.get(item);
mtm.deleteCertificate(alias);
} catch (KeyStoreException e) {
e.printStackTrace();
displayToast("Error: " + e.getLocalizedMessage());
}
}
if (xmppConnectionServiceBound) {
reconnectAccounts();
}
displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
}
});
dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
AlertDialog removeCertsDialog = dialogBuilder.create();
removeCertsDialog.show();
removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
return true;
});
}
final Preference exportLogsPreference = mSettingsFragment.findPreference("export_logs");
if (exportLogsPreference != null) {
exportLogsPreference.setOnPreferenceClickListener(preference -> {
if (hasStoragePermission(REQUEST_WRITE_LOGS)) {
startExport();
}
return true;
});
}
if (Config.ONLY_INTERNAL_STORAGE) {
final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
if (cleanCachePreference != null) {
cleanCachePreference.setOnPreferenceClickListener(preference -> cleanCache());
}
final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage");
if (cleanPrivateStoragePreference != null) {
cleanPrivateStoragePreference.setOnPreferenceClickListener(preference -> cleanPrivateStorage());
}
}
final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
if (deleteOmemoPreference != null) {
deleteOmemoPreference.setOnPreferenceClickListener(preference -> deleteOmemoIdentities());
}
final Preference enableMultiAccountsPreference = mSettingsFragment.findPreference("enable_multi_accounts");
if (enableMultiAccountsPreference != null) {
Log.d(Config.LOGTAG, "Multi account checkbox checked: " + isMultiAccountChecked);
if (isMultiAccountChecked) {
enableMultiAccountsPreference.setEnabled(false);
/*
if (xmppConnectionServiceBound) { // todo doesn't work --> it seems the service is never bound
final List<Account> accounts = xmppConnectionService.getAccounts();
Log.d(Config.LOGTAG, "Disabled multi account: Number of accounts " + accounts.size());
if (accounts.size() > 1) {
Log.d(Config.LOGTAG, "Disabled multi account not possible because you have more than one account");
enableMultiAccountsPreference.setEnabled(false);
} else {
Log.d(Config.LOGTAG, "Disabled multi account possible because you have one account");
enableMultiAccountsPreference.setEnabled(true);
}
} else {
enableMultiAccountsPreference.setEnabled(false);
}
*/
} else {
enableMultiAccountsPreference.setEnabled(true);
enableMultiAccountsPreference.setOnPreferenceClickListener(preference -> {
enableMultiAccounts();
return true;
});
}
}
}
use of de.pixart.messenger.services.MemorizingTrustManager in project Pix-Art-Messenger by kriztan.
the class XmppConnection method getTlsFactoryVerifier.
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()) {
keyManager = new KeyManager[] { new MyKeyManager() };
} else {
keyManager = null;
}
String domain = account.getJid().getDomainpart();
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);
return new TlsFactoryVerifier(factory, verifier);
}
Aggregations