use of de.pixart.messenger.crypto.axolotl.FingerprintStatus in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method verifyFingerprints.
public boolean verifyFingerprints(Account account, List<XmppUri.Fingerprint> fingerprints) {
final AxolotlService axolotlService = account.getAxolotlService();
boolean verifiedSomething = false;
for (XmppUri.Fingerprint fp : fingerprints) {
if (fp.type == XmppUri.FingerprintType.OMEMO) {
String fingerprint = "05" + fp.fingerprint.replaceAll("\\s", "");
Log.d(Config.LOGTAG, "trying to verify own fp=" + fingerprint);
FingerprintStatus fingerprintStatus = axolotlService.getFingerprintTrust(fingerprint);
if (fingerprintStatus != null) {
if (!fingerprintStatus.isVerified()) {
axolotlService.setFingerprintTrust(fingerprint, fingerprintStatus.toVerified());
verifiedSomething = true;
}
} else {
axolotlService.preVerifyFingerprint(account, fingerprint);
verifiedSomething = true;
}
}
}
return verifiedSomething;
}
use of de.pixart.messenger.crypto.axolotl.FingerprintStatus in project Pix-Art-Messenger by kriztan.
the class MessageAdapter method displayStatus.
private void displayStatus(ViewHolder viewHolder, final Message message, int type, boolean darkBackground) {
String filesize = null;
String info = null;
boolean error = false;
if (viewHolder.indicatorReceived != null) {
viewHolder.indicatorReceived.setVisibility(View.GONE);
viewHolder.indicatorRead.setVisibility(View.GONE);
}
if (viewHolder.edit_indicator != null) {
if (message.edited()) {
viewHolder.edit_indicator.setVisibility(View.VISIBLE);
viewHolder.edit_indicator.setAlpha(0.7f);
} else {
viewHolder.edit_indicator.setVisibility(View.GONE);
}
}
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI && message.getMergedStatus() <= Message.STATUS_RECEIVED;
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
FileParams params = message.getFileParams();
if (params.size > (1 * 1024 * 1024)) {
filesize = Math.round(params.size * 1f / (1024 * 1024)) + " MiB";
} else if (params.size >= (1 * 1024)) {
filesize = Math.round(params.size * 1f / 1024) + " KiB";
} else if (params.size > 0) {
filesize = params.size + " B";
}
if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) {
error = true;
}
}
switch(message.getMergedStatus()) {
case Message.STATUS_WAITING:
info = getContext().getString(R.string.waiting);
break;
case Message.STATUS_UNSEND:
Transferable d = message.getTransferable();
if (d != null) {
info = getContext().getString(R.string.sending_file, d.getProgress());
} else {
info = getContext().getString(R.string.sending);
}
break;
case Message.STATUS_OFFERED:
info = getContext().getString(R.string.offering);
break;
case Message.STATUS_SEND_RECEIVED:
if (mIndicateReceived) {
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
}
break;
case Message.STATUS_SEND_DISPLAYED:
if (mIndicateReceived) {
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
viewHolder.indicatorRead.setVisibility(View.VISIBLE);
}
break;
case Message.STATUS_SEND_FAILED:
if (isResendable) {
info = getContext().getString(R.string.send_failed_resend);
} else {
info = getContext().getString(R.string.send_failed);
}
error = true;
break;
default:
if (multiReceived) {
info = UIHelper.getMessageDisplayName(message);
}
break;
}
if (error && type == SENT) {
viewHolder.time.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Caption_Waring);
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
if (file.exists()) {
if (activity.xmppConnectionService.mHttpConnectionManager.getAutoAcceptFileSize() >= message.getFileParams().size) {
isResendable = true;
viewHolder.resend_button.setVisibility(View.GONE);
} else {
isResendable = false;
viewHolder.resend_button.setVisibility(View.VISIBLE);
}
}
viewHolder.resend_button.setText(R.string.send_again);
viewHolder.resend_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_resend_grey600_48dp, 0, 0, 0);
viewHolder.resend_button.setOnClickListener(new OnClickListener() {
final Message mMessage = message;
@Override
public void onClick(View v) {
mConversationFragment.resendMessage(mMessage);
}
});
} else if (!error && type == SENT) {
viewHolder.resend_button.setVisibility(View.GONE);
viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground, false));
} else {
if (darkBackground) {
viewHolder.time.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Caption_OnDark);
} else {
viewHolder.time.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Caption);
}
viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground, false));
}
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
viewHolder.indicator.setVisibility(View.GONE);
} else {
boolean verified = false;
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
final FingerprintStatus status = message.getConversation().getAccount().getAxolotlService().getFingerprintTrust(message.getFingerprint());
if (status != null && status.isVerified()) {
verified = true;
}
}
if (verified) {
viewHolder.indicator.setImageResource(R.drawable.ic_verified_user_blue_18dp);
} else {
viewHolder.indicator.setImageResource(R.drawable.ic_lock_blue_18dp);
}
viewHolder.indicator.setAlpha(0.7f);
viewHolder.indicator.setVisibility(View.VISIBLE);
}
String formatedTime = UIHelper.readableTimeDifferenceFull(getContext(), message.getMergedTimeSent());
if (message.getStatus() <= Message.STATUS_RECEIVED) {
if ((filesize != null) && (info != null)) {
viewHolder.time.setText(formatedTime + " \u00B7 " + filesize + " \u00B7 " + info);
} else if ((filesize == null) && (info != null)) {
viewHolder.time.setText(formatedTime + " \u00B7 " + info);
} else if ((filesize != null) && (info == null)) {
viewHolder.time.setText(formatedTime + " \u00B7 " + filesize);
} else {
viewHolder.time.setText(formatedTime);
}
} else {
if ((filesize != null) && (info != null)) {
viewHolder.time.setText(filesize + " \u00B7 " + info);
} else if ((filesize == null) && (info != null)) {
if (error) {
viewHolder.time.setText(info + " \u00B7 " + formatedTime);
} else {
viewHolder.time.setText(info);
}
} else if ((filesize != null) && (info == null)) {
viewHolder.time.setText(filesize + " \u00B7 " + formatedTime);
} else {
viewHolder.time.setText(formatedTime);
}
}
}
use of de.pixart.messenger.crypto.axolotl.FingerprintStatus in project Pix-Art-Messenger by kriztan.
the class ContactDetailsActivity method populateView.
private void populateView() {
if (contact == null) {
return;
}
long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
if (mutedTill == Long.MAX_VALUE) {
mNotifyStatusText.setText(R.string.notify_never);
mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
} else if (System.currentTimeMillis() < mutedTill) {
mNotifyStatusText.setText(R.string.notify_paused);
mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
} else {
mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp);
mNotifyStatusText.setText(R.string.notify_on_all_messages);
}
if (getSupportActionBar() != null) {
final ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setCustomView(R.layout.ab_title);
ab.setDisplayShowCustomEnabled(true);
TextView abtitle = findViewById(android.R.id.text1);
TextView absubtitle = findViewById(android.R.id.text2);
abtitle.setText(contact.getDisplayName());
abtitle.setSelected(true);
abtitle.setClickable(false);
absubtitle.setVisibility(View.GONE);
absubtitle.setClickable(false);
}
}
invalidateOptionsMenu();
setTitle(contact.getDisplayName());
if (contact.getServer().toString().toLowerCase().equals(accountJid.getDomainpart().toLowerCase())) {
binding.contactDisplayName.setText(contact.getDisplayName());
} else {
binding.contactDisplayName.setText(contact.getDisplayJid());
}
if (contact.showInRoster()) {
binding.detailsSendPresence.setVisibility(View.VISIBLE);
binding.detailsReceivePresence.setVisibility(View.VISIBLE);
binding.addContactButton.setVisibility(View.VISIBLE);
binding.addContactButton.setText(getString(R.string.action_delete_contact));
binding.addContactButton.getBackground().setColorFilter(getWarningButtonColor(), PorterDuff.Mode.MULTIPLY);
binding.detailsSendPresence.setOnCheckedChangeListener(null);
binding.detailsReceivePresence.setOnCheckedChangeListener(null);
final AlertDialog.Builder deleteFromRosterDialog = new AlertDialog.Builder(ContactDetailsActivity.this);
binding.addContactButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
deleteFromRosterDialog.setNegativeButton(getString(R.string.cancel), null);
deleteFromRosterDialog.setTitle(getString(R.string.action_delete_contact)).setMessage(getString(R.string.remove_contact_text, contact.getDisplayJid())).setPositiveButton(getString(R.string.delete), removeFromRoster).create().show();
}
});
binding.detailsSendPresence.setOnCheckedChangeListener(null);
binding.detailsReceivePresence.setOnCheckedChangeListener(null);
List<String> statusMessages = contact.getPresences().getStatusMessages();
if (statusMessages.size() == 0) {
binding.statusMessage.setVisibility(View.GONE);
} else {
StringBuilder builder = new StringBuilder();
binding.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");
}
}
binding.statusMessage.setText(builder);
}
String resources = contact.getPresences().getMostAvailableResource();
if (resources.length() == 0) {
binding.resource.setVisibility(View.GONE);
} else {
binding.resource.setVisibility(View.VISIBLE);
binding.resource.setText(resources);
}
if (contact.getOption(Contact.Options.FROM)) {
binding.detailsSendPresence.setText(R.string.send_presence_updates);
binding.detailsSendPresence.setChecked(true);
} else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
binding.detailsSendPresence.setChecked(false);
binding.detailsSendPresence.setText(R.string.send_presence_updates);
} else {
binding.detailsSendPresence.setText(R.string.preemptively_grant);
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
binding.detailsSendPresence.setChecked(true);
} else {
binding.detailsSendPresence.setChecked(false);
}
}
if (contact.getOption(Contact.Options.TO)) {
binding.detailsReceivePresence.setText(R.string.receive_presence_updates);
binding.detailsReceivePresence.setChecked(true);
} else {
binding.detailsReceivePresence.setText(R.string.ask_for_presence_updates);
if (contact.getOption(Contact.Options.ASKING)) {
binding.detailsReceivePresence.setChecked(true);
} else {
binding.detailsReceivePresence.setChecked(false);
}
}
if (contact.getAccount().isOnlineAndConnected()) {
binding.detailsReceivePresence.setEnabled(true);
binding.detailsSendPresence.setEnabled(true);
} else {
binding.detailsReceivePresence.setEnabled(false);
binding.detailsSendPresence.setEnabled(false);
}
binding.detailsSendPresence.setOnCheckedChangeListener(this.mOnSendCheckedChange);
binding.detailsReceivePresence.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
} else {
binding.addContactButton.setVisibility(View.VISIBLE);
binding.addContactButton.setText(getString(R.string.add_contact));
binding.addContactButton.getBackground().clearColorFilter();
binding.addContactButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
showAddToRosterDialog(contact);
}
});
binding.detailsSendPresence.setVisibility(View.GONE);
binding.detailsReceivePresence.setVisibility(View.GONE);
binding.statusMessage.setVisibility(View.GONE);
}
if (contact.isBlocked() && !this.showDynamicTags) {
binding.detailsLastseen.setVisibility(View.VISIBLE);
binding.detailsLastseen.setText(R.string.contact_blocked);
} else {
if (showLastSeen && contact.getLastseen() > 0 && contact.getPresences().allOrNonSupport(Namespace.IDLE)) {
binding.detailsLastseen.setVisibility(View.VISIBLE);
binding.detailsLastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen()));
} else {
binding.detailsLastseen.setVisibility(View.GONE);
}
}
if (contact.getPresences().size() > 1) {
binding.detailsContactjid.setText(contact.getDisplayJid() + " (" + contact.getPresences().size() + ")");
} else {
binding.detailsContactjid.setText(contact.getDisplayJid());
}
String account;
if (Config.DOMAIN_LOCK != null) {
account = contact.getAccount().getJid().getLocalpart();
} else {
account = contact.getAccount().getJid().toBareJid().toString();
}
binding.detailsAccount.setText(getString(R.string.using_account, account));
binding.detailsContactBadge.setImageBitmap(avatarService().get(contact, getPixel(Config.AVATAR_SIZE)));
binding.detailsContactBadge.setOnClickListener(this.onBadgeClick);
if (xmppConnectionService.multipleAccounts()) {
binding.detailsAccount.setVisibility(View.VISIBLE);
} else {
binding.detailsAccount.setVisibility(View.GONE);
}
binding.detailsContactKeys.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, binding.detailsContactKeys, false);
TextView key = view.findViewById(R.id.key);
TextView keyType = view.findViewById(R.id.key_type);
ImageButton removeButton = view.findViewById(R.id.button_remove);
removeButton.setVisibility(View.VISIBLE);
key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
if (otrFingerprint != null && otrFingerprint.equalsIgnoreCase(messageFingerprint)) {
keyType.setText(R.string.otr_fingerprint_selected_message);
keyType.setTextColor(ContextCompat.getColor(this, R.color.accent));
} else {
keyType.setText(R.string.otr_fingerprint);
}
binding.detailsContactKeys.addView(view);
removeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
confirmToDeleteFingerprint(otrFingerprint);
}
});
}
}
final AxolotlService axolotlService = contact.getAccount().getAxolotlService();
if (Config.supportOmemo() && axolotlService != null) {
boolean skippedInactive = false;
boolean showsInactive = false;
for (final XmppAxolotlSession session : axolotlService.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(binding.detailsContactKeys, session, highlight);
}
}
if (showsInactive || skippedInactive) {
binding.showInactiveDevices.setText(showsInactive ? R.string.hide_inactive_devices : R.string.show_inactive_devices);
binding.showInactiveDevices.setVisibility(View.VISIBLE);
} else {
binding.showInactiveDevices.setVisibility(View.GONE);
}
} else {
binding.showInactiveDevices.setVisibility(View.GONE);
}
binding.scanButton.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
if (hasKeys) {
binding.scanButton.setOnClickListener((v) -> ScanActivity.scan(this));
}
if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {
hasKeys = true;
View view = inflater.inflate(R.layout.contact_key, binding.detailsContactKeys, false);
TextView key = view.findViewById(R.id.key);
TextView keyType = view.findViewById(R.id.key_type);
keyType.setText(R.string.openpgp_key_id);
if ("pgp".equals(messageFingerprint)) {
keyType.setTextColor(ContextCompat.getColor(this, R.color.accent));
}
key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
final OnClickListener openKey = new OnClickListener() {
@Override
public void onClick(View v) {
launchOpenKeyChain(contact.getPgpKeyId());
}
};
view.setOnClickListener(openKey);
key.setOnClickListener(openKey);
keyType.setOnClickListener(openKey);
binding.detailsContactKeys.addView(view);
}
binding.keysWrapper.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
List<ListItem.Tag> tagList = contact.getTags(this);
if (tagList.size() == 0 || !this.showDynamicTags) {
binding.tags.setVisibility(View.GONE);
} else {
binding.tags.setVisibility(View.VISIBLE);
binding.tags.removeAllViewsInLayout();
for (final ListItem.Tag tag : tagList) {
final TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag, binding.tags, false);
tv.setText(tag.getName());
tv.setBackgroundColor(tag.getColor());
binding.tags.addView(tv);
}
}
}
use of de.pixart.messenger.crypto.axolotl.FingerprintStatus in project Pix-Art-Messenger by kriztan.
the class OmemoActivity method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
Object account = v.getTag(R.id.TAG_ACCOUNT);
Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
if (account != null && fingerprint != null && account instanceof Account && fingerprintStatus != null && fingerprint instanceof String && fingerprintStatus instanceof FingerprintStatus) {
getMenuInflater().inflate(R.menu.omemo_key_context, menu);
MenuItem distrust = menu.findItem(R.id.distrust_key);
MenuItem verifyScan = menu.findItem(R.id.verify_scan);
if (this instanceof TrustKeysActivity) {
distrust.setVisible(false);
verifyScan.setVisible(false);
} else {
FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
if (!status.isActive() || status.isVerified()) {
verifyScan.setVisible(false);
}
distrust.setVisible(status.isVerified() || (!status.isActive() && status.isTrusted()));
}
this.mSelectedAccount = (Account) account;
this.mSelectedFingerprint = (String) fingerprint;
}
}
use of de.pixart.messenger.crypto.axolotl.FingerprintStatus in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method verifyFingerprints.
public boolean verifyFingerprints(Contact contact, List<XmppUri.Fingerprint> fingerprints) {
boolean needsRosterWrite = false;
boolean performedVerification = false;
final AxolotlService axolotlService = contact.getAccount().getAxolotlService();
for (XmppUri.Fingerprint fp : fingerprints) {
if (fp.type == XmppUri.FingerprintType.OTR) {
performedVerification |= contact.addOtrFingerprint(fp.fingerprint);
needsRosterWrite |= performedVerification;
} else if (fp.type == XmppUri.FingerprintType.OMEMO) {
String fingerprint = "05" + fp.fingerprint.replaceAll("\\s", "");
FingerprintStatus fingerprintStatus = axolotlService.getFingerprintTrust(fingerprint);
if (fingerprintStatus != null) {
if (!fingerprintStatus.isVerified()) {
performedVerification = true;
axolotlService.setFingerprintTrust(fingerprint, fingerprintStatus.toVerified());
}
} else {
axolotlService.preVerifyFingerprint(contact, fingerprint);
}
}
}
if (needsRosterWrite) {
syncRosterToDisk(contact.getAccount());
}
return performedVerification;
}
Aggregations