use of eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession in project Conversations by siacs.
the class Account method getFingerprints.
private List<XmppUri.Fingerprint> getFingerprints() {
ArrayList<XmppUri.Fingerprint> fingerprints = new ArrayList<>();
final String otr = this.getOtrFingerprint();
if (otr != null) {
fingerprints.add(new XmppUri.Fingerprint(XmppUri.FingerprintType.OTR, otr));
}
if (axolotlService == null) {
return fingerprints;
}
fingerprints.add(new XmppUri.Fingerprint(XmppUri.FingerprintType.OMEMO, axolotlService.getOwnFingerprint().substring(2), axolotlService.getOwnDeviceId()));
for (XmppAxolotlSession session : axolotlService.findOwnSessions()) {
if (session.getTrust().isVerified() && session.getTrust().isActive()) {
fingerprints.add(new XmppUri.Fingerprint(XmppUri.FingerprintType.OMEMO, session.getFingerprint().substring(2).replaceAll("\\s", ""), session.getRemoteAddress().getDeviceId()));
}
}
return fingerprints;
}
use of eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession in project Conversations by siacs.
the class ContactDetailsActivity method populateView.
private void populateView() {
if (contact == null) {
return;
}
invalidateOptionsMenu();
setTitle(contact.getDisplayName());
if (contact.showInRoster()) {
send.setVisibility(View.VISIBLE);
receive.setVisibility(View.VISIBLE);
addContactButton.setVisibility(View.GONE);
send.setOnCheckedChangeListener(null);
receive.setOnCheckedChangeListener(null);
List<String> statusMessages = contact.getPresences().getStatusMessages();
if (statusMessages.size() == 0) {
statusMessage.setVisibility(View.GONE);
} else {
StringBuilder builder = new StringBuilder();
statusMessage.setVisibility(View.VISIBLE);
int s = statusMessages.size();
for (int i = 0; i < s; ++i) {
if (s > 1) {
builder.append("• ");
}
builder.append(statusMessages.get(i));
if (i < s - 1) {
builder.append("\n");
}
}
statusMessage.setText(builder);
}
if (contact.getOption(Contact.Options.FROM)) {
send.setText(R.string.send_presence_updates);
send.setChecked(true);
} else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
send.setChecked(false);
send.setText(R.string.send_presence_updates);
} else {
send.setText(R.string.preemptively_grant);
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
send.setChecked(true);
} else {
send.setChecked(false);
}
}
if (contact.getOption(Contact.Options.TO)) {
receive.setText(R.string.receive_presence_updates);
receive.setChecked(true);
} else {
receive.setText(R.string.ask_for_presence_updates);
if (contact.getOption(Contact.Options.ASKING)) {
receive.setChecked(true);
} else {
receive.setChecked(false);
}
}
if (contact.getAccount().isOnlineAndConnected()) {
receive.setEnabled(true);
send.setEnabled(true);
} else {
receive.setEnabled(false);
send.setEnabled(false);
}
send.setOnCheckedChangeListener(this.mOnSendCheckedChange);
receive.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
} else {
addContactButton.setVisibility(View.VISIBLE);
send.setVisibility(View.GONE);
receive.setVisibility(View.GONE);
statusMessage.setVisibility(View.GONE);
}
if (contact.isBlocked() && !this.showDynamicTags) {
lastseen.setVisibility(View.VISIBLE);
lastseen.setText(R.string.contact_blocked);
} else {
if (showLastSeen && contact.getLastseen() > 0) {
lastseen.setVisibility(View.VISIBLE);
lastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen()));
} else {
lastseen.setVisibility(View.GONE);
}
}
if (contact.getPresences().size() > 1) {
contactJidTv.setText(contact.getDisplayJid() + " (" + contact.getPresences().size() + ")");
} else {
contactJidTv.setText(contact.getDisplayJid());
}
String account;
if (Config.DOMAIN_LOCK != null) {
account = contact.getAccount().getJid().getLocalpart();
} else {
account = contact.getAccount().getJid().toBareJid().toString();
}
accountJidTv.setText(getString(R.string.using_account, account));
badge.setImageBitmap(avatarService().get(contact, getPixel(72)));
badge.setOnClickListener(this.onBadgeClick);
keys.removeAllViews();
boolean hasKeys = false;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (Config.supportOtr()) {
for (final String otrFingerprint : contact.getOtrFingerprints()) {
hasKeys = true;
View view = inflater.inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type);
ImageButton removeButton = (ImageButton) view.findViewById(R.id.button_remove);
removeButton.setVisibility(View.VISIBLE);
key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
if (otrFingerprint != null && otrFingerprint.equals(messageFingerprint)) {
keyType.setText(R.string.otr_fingerprint_selected_message);
keyType.setTextColor(getResources().getColor(R.color.accent));
} else {
keyType.setText(R.string.otr_fingerprint);
}
keys.addView(view);
removeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
confirmToDeleteFingerprint(otrFingerprint);
}
});
}
}
if (Config.supportOmemo()) {
boolean skippedInactive = false;
boolean showsInactive = false;
for (final XmppAxolotlSession session : contact.getAccount().getAxolotlService().findSessionsForContact(contact)) {
final FingerprintStatus trust = session.getTrust();
hasKeys |= !trust.isCompromised();
if (!trust.isActive()) {
if (showInactiveOmemo) {
showsInactive = true;
} else {
skippedInactive = true;
continue;
}
}
if (!trust.isCompromised()) {
boolean highlight = session.getFingerprint().equals(messageFingerprint);
addFingerprintRow(keys, session, highlight);
}
}
if (showsInactive || skippedInactive) {
mShowInactiveDevicesButton.setText(showsInactive ? R.string.hide_inactive_devices : R.string.show_inactive_devices);
mShowInactiveDevicesButton.setVisibility(View.VISIBLE);
} else {
mShowInactiveDevicesButton.setVisibility(View.GONE);
}
} else {
mShowInactiveDevicesButton.setVisibility(View.GONE);
}
if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {
hasKeys = true;
View view = inflater.inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type);
keyType.setText(R.string.openpgp_key_id);
if ("pgp".equals(messageFingerprint)) {
keyType.setTextColor(getResources().getColor(R.color.accent));
}
key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PgpEngine pgp = ContactDetailsActivity.this.xmppConnectionService.getPgpEngine();
if (pgp != null) {
PendingIntent intent = pgp.getIntentForKey(contact);
if (intent != null) {
try {
startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
} catch (SendIntentException e) {
}
}
}
}
});
keys.addView(view);
}
keysWrapper.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
List<ListItem.Tag> tagList = contact.getTags(this);
if (tagList.size() == 0 || !this.showDynamicTags) {
tags.setVisibility(View.GONE);
} else {
tags.setVisibility(View.VISIBLE);
tags.removeAllViewsInLayout();
for (final ListItem.Tag tag : tagList) {
final TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag, tags, false);
tv.setText(tag.getName());
tv.setBackgroundColor(tag.getColor());
tags.addView(tv);
}
}
}
use of eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession in project Conversations by siacs.
the class EditAccountActivity method updateAccountInformation.
private void updateAccountInformation(boolean init) {
if (init) {
this.mAccountJid.getEditableText().clear();
if (mUsernameMode) {
this.mAccountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
} else {
this.mAccountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
}
this.mPassword.setText(this.mAccount.getPassword());
this.mHostname.setText("");
this.mHostname.getEditableText().append(this.mAccount.getHostname());
this.mPort.setText("");
this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort()));
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
}
if (!mInitMode) {
this.mAvatar.setVisibility(View.VISIBLE);
this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
} else {
this.mAvatar.setVisibility(View.GONE);
}
if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
this.mRegisterNew.setVisibility(View.VISIBLE);
this.mRegisterNew.setChecked(true);
this.mPasswordConfirm.setText(this.mAccount.getPassword());
} else {
this.mRegisterNew.setVisibility(View.GONE);
this.mRegisterNew.setChecked(false);
}
if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
Features features = this.mAccount.getXmppConnection().getFeatures();
this.mStats.setVisibility(View.VISIBLE);
boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().availableAndUseful(mAccount) && isOptimizingBattery();
boolean showDataSaverWarning = isAffectedByDataSaver();
showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning);
this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection().getLastSessionEstablished()));
if (features.rosterVersioning()) {
this.mServerInfoRosterVersion.setText(R.string.server_info_available);
} else {
this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable);
}
if (features.carbons()) {
this.mServerInfoCarbons.setText(R.string.server_info_available);
} else {
this.mServerInfoCarbons.setText(R.string.server_info_unavailable);
}
if (features.mam()) {
this.mServerInfoMam.setText(R.string.server_info_available);
} else {
this.mServerInfoMam.setText(R.string.server_info_unavailable);
}
if (features.csi()) {
this.mServerInfoCSI.setText(R.string.server_info_available);
} else {
this.mServerInfoCSI.setText(R.string.server_info_unavailable);
}
if (features.blocking()) {
this.mServerInfoBlocking.setText(R.string.server_info_available);
} else {
this.mServerInfoBlocking.setText(R.string.server_info_unavailable);
}
if (features.sm()) {
this.mServerInfoSm.setText(R.string.server_info_available);
} else {
this.mServerInfoSm.setText(R.string.server_info_unavailable);
}
if (features.pep()) {
AxolotlService axolotlService = this.mAccount.getAxolotlService();
if (axolotlService != null && axolotlService.isPepBroken()) {
this.mServerInfoPep.setText(R.string.server_info_broken);
} else {
this.mServerInfoPep.setText(R.string.server_info_available);
}
} else {
this.mServerInfoPep.setText(R.string.server_info_unavailable);
}
if (features.httpUpload(0)) {
this.mServerInfoHttpUpload.setText(R.string.server_info_available);
} else {
this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
}
this.mPushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
if (xmppConnectionService.getPushManagementService().available(mAccount)) {
this.mServerInfoPush.setText(R.string.server_info_available);
} else {
this.mServerInfoPush.setText(R.string.server_info_unavailable);
}
final String otrFingerprint = this.mAccount.getOtrFingerprint();
if (otrFingerprint != null && Config.supportOtr()) {
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
this.mOtrFingerprintToClipboardButton.setVisibility(View.VISIBLE);
this.mOtrFingerprintToClipboardButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(otrFingerprint), R.string.otr_fingerprint)) {
Toast.makeText(EditAccountActivity.this, R.string.toast_message_otr_fingerprint, Toast.LENGTH_SHORT).show();
}
}
});
} else {
this.mOtrFingerprintBox.setVisibility(View.GONE);
}
final String ownAxolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
if (ownAxolotlFingerprint != null && Config.supportOmemo()) {
this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
if (ownAxolotlFingerprint.equals(messageFingerprint)) {
this.mOwnFingerprintDesc.setTextColor(getResources().getColor(R.color.accent));
} else {
this.mOwnFingerprintDesc.setTextColor(getSecondaryTextColor());
}
this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2)));
this.mAxolotlFingerprintToClipboardButton.setVisibility(View.VISIBLE);
this.mAxolotlFingerprintToClipboardButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
copyOmemoFingerprint(ownAxolotlFingerprint);
}
});
} else {
this.mAxolotlFingerprintBox.setVisibility(View.GONE);
}
boolean hasKeys = false;
keys.removeAllViews();
for (XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
if (!session.getTrust().isCompromised()) {
boolean highlight = session.getFingerprint().equals(messageFingerprint);
addFingerprintRow(keys, session, highlight);
hasKeys = true;
}
}
if (hasKeys && Config.supportOmemo()) {
keysCard.setVisibility(View.VISIBLE);
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
if (otherDevices == null || otherDevices.isEmpty()) {
mClearDevicesButton.setVisibility(View.GONE);
} else {
mClearDevicesButton.setVisibility(View.VISIBLE);
}
} else {
keysCard.setVisibility(View.GONE);
}
} else {
if (this.mAccount.errorStatus()) {
final EditText errorTextField;
if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
errorTextField = this.mPassword;
} else if (mShowOptions && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND && this.mHostname.getText().length() > 0) {
errorTextField = this.mHostname;
} else {
errorTextField = this.mAccountJid;
}
errorTextField.setError(getString(this.mAccount.getStatus().getReadableId()));
if (init || !accountInfoEdited()) {
errorTextField.requestFocus();
}
} else {
this.mAccountJid.setError(null);
this.mPassword.setError(null);
this.mHostname.setError(null);
}
this.mStats.setVisibility(View.GONE);
}
}
Aggregations