use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.
the class ConversationMenuConfigurator method configureEncryptionMenu.
public static void configureEncryptionMenu(@NonNull Conversation conversation, Menu menu) {
final MenuItem menuSecure = menu.findItem(R.id.action_security);
final MenuItem none = menu.findItem(R.id.encryption_choice_none);
final MenuItem otr = menu.findItem(R.id.encryption_choice_otr);
final MenuItem pgp = menu.findItem(R.id.encryption_choice_pgp);
final MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl);
boolean visible;
if (conversation.getMode() == Conversation.MODE_MULTI) {
visible = (Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices();
} else {
visible = Config.multipleEncryptionChoices();
}
menuSecure.setVisible(visible);
if (!visible) {
return;
}
if (conversation.getNextEncryption() != Message.ENCRYPTION_NONE) {
menuSecure.setIcon(R.drawable.ic_lock_white_24dp);
}
otr.setVisible(Config.supportOtr());
if (conversation.getMode() == Conversation.MODE_MULTI) {
otr.setVisible(false);
}
pgp.setVisible(Config.supportOpenPgp());
none.setVisible(Config.supportUnencrypted() || conversation.getMode() == Conversation.MODE_MULTI);
axolotl.setVisible(Config.supportOmemo());
final AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
if (axolotlService == null || !axolotlService.isConversationAxolotlCapable(conversation)) {
axolotl.setEnabled(false);
}
switch(conversation.getNextEncryption()) {
case Message.ENCRYPTION_NONE:
none.setChecked(true);
break;
case Message.ENCRYPTION_OTR:
otr.setChecked(true);
break;
case Message.ENCRYPTION_PGP:
pgp.setChecked(true);
break;
case Message.ENCRYPTION_AXOLOTL:
axolotl.setChecked(true);
break;
default:
none.setChecked(true);
break;
}
}
use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.
the class IqParser method rosterItems.
private void rosterItems(final Account account, final Element query) {
final String version = query.getAttribute("ver");
if (version != null) {
account.getRoster().setVersion(version);
}
for (final Element item : query.getChildren()) {
if (item.getName().equals("item")) {
final Jid jid = item.getAttributeAsJid("jid");
if (jid == null) {
continue;
}
final String name = item.getAttribute("name");
final String subscription = item.getAttribute("subscription");
final Contact contact = account.getRoster().getContact(jid);
boolean bothPre = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
contact.setServerName(name);
contact.parseGroupsFromElement(item);
}
if ("remove".equals(subscription)) {
contact.resetOption(Contact.Options.IN_ROSTER);
contact.resetOption(Contact.Options.DIRTY_DELETE);
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
} else {
contact.setOption(Contact.Options.IN_ROSTER);
contact.resetOption(Contact.Options.DIRTY_PUSH);
contact.parseSubscriptionFromElement(item);
}
boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
if ((both != bothPre) && both) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": gained mutual presence subscription with " + contact.getJid());
AxolotlService axolotlService = account.getAxolotlService();
if (axolotlService != null) {
axolotlService.clearErrorsInFetchStatusMap(contact.getJid());
}
}
mXmppConnectionService.getAvatarService().clear(contact);
}
}
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
mXmppConnectionService.getShortcutService().refresh();
}
use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.
the class MessageParser method parseEvent.
private void parseEvent(final Element event, final Jid from, final Account account) {
Element items = event.findChild("items");
String node = items == null ? null : items.getAttribute("node");
if ("urn:xmpp:avatar:metadata".equals(node)) {
Avatar avatar = Avatar.parseMetadata(items);
if (avatar != null) {
avatar.owner = from.toBareJid();
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
if (account.getJid().toBareJid().equals(from)) {
if (account.setAvatar(avatar.getFilename())) {
mXmppConnectionService.databaseBackend.updateAccount(account);
}
mXmppConnectionService.getAvatarService().clear(account);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
} else {
Contact contact = account.getRoster().getContact(from);
contact.setAvatar(avatar);
mXmppConnectionService.getAvatarService().clear(contact);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
}
} else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(account, avatar);
}
}
} else if ("http://jabber.org/protocol/nick".equals(node)) {
final Element i = items.findChild("item");
final String nick = i == null ? null : i.findChildContent("nick", Namespace.NICK);
if (nick != null) {
Contact contact = account.getRoster().getContact(from);
if (contact.setPresenceName(nick)) {
mXmppConnectionService.getAvatarService().clear(contact);
}
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
}
} else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
Element item = items.findChild("item");
Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list " + deviceIds + " update from " + from + ", processing... ");
AxolotlService axolotlService = account.getAxolotlService();
axolotlService.registerDevices(from, deviceIds);
mXmppConnectionService.updateAccountUi();
}
}
use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.
the class MessageParser method parseAxolotlChat.
private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status, boolean postpone) {
final AxolotlService service = conversation.getAccount().getAxolotlService();
final XmppAxolotlMessage xmppAxolotlMessage;
try {
xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid());
} catch (Exception e) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": invalid omemo message received " + e.getMessage());
return null;
}
if (xmppAxolotlMessage.hasPayload()) {
final XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage, postpone);
if (plaintextMessage != null) {
Message finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount()) + " Received Message with session fingerprint: " + plaintextMessage.getFingerprint());
return finishedMessage;
}
} else {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": received OMEMO key transport message");
service.processReceivingKeyTransportMessage(xmppAxolotlMessage, postpone);
}
return null;
}
use of de.pixart.messenger.crypto.axolotl.AxolotlService 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);
}
}
}
Aggregations