diff options
Diffstat (limited to 'src')
8 files changed, 176 insertions, 62 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java index c906c7514..1979acbb9 100644 --- a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java +++ b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java @@ -304,10 +304,6 @@ public class PgpEngine { } } - public PendingIntent getIntentForKey(Contact contact) { - return getIntentForKey(contact.getPgpKeyId()); - } - public PendingIntent getIntentForKey(long pgpKeyId) { Intent params = new Intent(); params.setAction(OpenPgpApi.ACTION_GET_KEY); diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index e9fb800cc..18e991367 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -554,7 +554,11 @@ public class Account extends AbstractEntity { public boolean setPgpSignId(long pgpID) { synchronized (this.keys) { try { - keys.put(KEY_PGP_ID, pgpID); + if (pgpID == 0) { + keys.remove(KEY_PGP_ID); + } else { + keys.put(KEY_PGP_ID, pgpID); + } } catch (JSONException e) { return false; } diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index 1c54d2ff3..a38ae7e59 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicInteger; import de.pixart.messenger.Config; import de.pixart.messenger.R; -import de.pixart.messenger.crypto.PgpEngine; import de.pixart.messenger.crypto.axolotl.AxolotlService; import de.pixart.messenger.crypto.axolotl.FingerprintStatus; import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession; @@ -555,7 +554,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp .findViewById(R.id.button_remove); removeButton.setVisibility(View.VISIBLE); key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint)); - if (otrFingerprint != null && otrFingerprint.equals(messageFingerprint)) { + if (otrFingerprint != null && otrFingerprint.equalsIgnoreCase(messageFingerprint)) { keyType.setText(R.string.otr_fingerprint_selected_message); keyType.setTextColor(ContextCompat.getColor(this, R.color.accent)); } else { @@ -613,14 +612,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp @Override public void onClick(View v) { - PgpEngine pgp = ContactDetailsActivity.this.xmppConnectionService.getPgpEngine(); - try { - startIntentSenderForResult( - pgp.getIntentForKey(contact).getIntentSender(), 0, null, 0, - 0, 0); - } catch (Throwable e) { - Toast.makeText(ContactDetailsActivity.this, R.string.openpgp_error, Toast.LENGTH_SHORT).show(); - } + launchOpenKeyChain(contact.getPgpKeyId()); } }; view.setOnClickListener(openKey); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 4ba88d49a..342e52451 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -516,6 +516,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { fingerprint = "pgp"; + } else if (message.getEncryption() == Message.ENCRYPTION_OTR) { + fingerprint = "otr"; } else { fingerprint = message.getFingerprint(); } diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index ab1cbc836..320823120 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -36,6 +36,8 @@ import android.widget.TableRow; import android.widget.TextView; import android.widget.Toast; +import org.openintents.openpgp.util.OpenPgpUtils; + import java.util.Arrays; import java.util.List; import java.util.Set; @@ -93,13 +95,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private TextView mSessionEst; private TextView mOtrFingerprint; private TextView mAxolotlFingerprint; + private TextView mPgpFingerprint; private TextView mOwnFingerprintDesc; + private TextView mOtrFingerprintDesc; + private TextView getmPgpFingerprintDesc; private TextView mAccountJidLabel; private ImageView mAvatar; private RelativeLayout mOtrFingerprintBox; private RelativeLayout mAxolotlFingerprintBox; + private RelativeLayout mPgpFingerprintBox; private ImageButton mOtrFingerprintToClipboardButton; private ImageButton mAxolotlFingerprintToClipboardButton; + private ImageButton mPgpDeleteFingerprintButton; private LinearLayout keys; private LinearLayout keysCard; private LinearLayout mNamePort; @@ -512,7 +519,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mServerInfoHttpUpload = (TextView) findViewById(R.id.server_info_http_upload); this.mPushRow = (TableRow) findViewById(R.id.push_row); this.mServerInfoPush = (TextView) findViewById(R.id.server_info_push); + this.mPgpFingerprintBox = (RelativeLayout) findViewById(R.id.pgp_fingerprint_box); + this.mPgpFingerprint = (TextView) findViewById(R.id.pgp_fingerprint); + this.getmPgpFingerprintDesc = (TextView) findViewById(R.id.pgp_fingerprint_desc); + this.mPgpDeleteFingerprintButton = (ImageButton) findViewById(R.id.action_delete_pgp); this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint); + this.mOtrFingerprintDesc = (TextView) findViewById(R.id.otr_fingerprint_desc); this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box); this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard); this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint); @@ -932,8 +944,36 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } else { this.mServerInfoPush.setText(R.string.server_info_unavailable); } + final long pgpKeyId = this.mAccount.getPgpId(); + if (pgpKeyId != 0 && Config.supportOpenPgp()) { + OnClickListener openPgp = new OnClickListener() { + @Override + public void onClick(View view) { + launchOpenKeyChain(pgpKeyId); + } + }; + OnClickListener delete = new OnClickListener() { + @Override + public void onClick(View view) { + showDeletePgpDialog(); + } + }; + this.mPgpFingerprintBox.setVisibility(View.VISIBLE); + this.mPgpFingerprint.setText(OpenPgpUtils.convertKeyIdToHex(pgpKeyId)); + this.mPgpFingerprint.setOnClickListener(openPgp); + if ("pgp".equals(messageFingerprint)) { + this.getmPgpFingerprintDesc.setTextColor(ContextCompat.getColor(this, R.color.accent)); + } + this.getmPgpFingerprintDesc.setOnClickListener(openPgp); + this.mPgpDeleteFingerprintButton.setOnClickListener(delete); + } else { + this.mPgpFingerprintBox.setVisibility(View.GONE); + } final String otrFingerprint = this.mAccount.getOtrFingerprint(); if (otrFingerprint != null && Config.supportOtr()) { + if ("otr".equals(messageFingerprint)) { + this.mOtrFingerprintDesc.setTextColor(ContextCompat.getColor(this, R.color.accent)); + } this.mOtrFingerprintBox.setVisibility(View.VISIBLE); this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint)); this.mOtrFingerprintToClipboardButton @@ -1022,6 +1062,24 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } } + private void showDeletePgpDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.unpublish_pgp); + builder.setMessage(R.string.unpublish_pgp_message); + builder.setNegativeButton(R.string.cancel, null); + builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + mAccount.setPgpSignId(0); + mAccount.unsetPgpSignature(); + xmppConnectionService.databaseBackend.updateAccount(mAccount); + xmppConnectionService.sendPresence(mAccount); + refreshUiReal(); + } + }); + builder.create().show(); + } + private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) { this.mOsOptimizations.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE); if (showDataSaverWarning) { diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 0ea105f59..2187a467b 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -69,6 +69,7 @@ import java.util.concurrent.atomic.AtomicInteger; import de.pixart.messenger.Config; import de.pixart.messenger.R; +import de.pixart.messenger.crypto.PgpEngine; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; @@ -1074,6 +1075,17 @@ public abstract class XmppActivity extends Activity { } } + protected void launchOpenKeyChain(long keyId) { + PgpEngine pgp = XmppActivity.this.xmppConnectionService.getPgpEngine(); + try { + startIntentSenderForResult( + pgp.getIntentForKey(keyId).getIntentSender(), 0, null, 0, + 0, 0); + } catch (Throwable e) { + Toast.makeText(XmppActivity.this, R.string.openpgp_error, Toast.LENGTH_SHORT).show(); + } + } + @Override public void onResume() { super.onResume(); diff --git a/src/main/res/layout/activity_edit_account.xml b/src/main/res/layout/activity_edit_account.xml index 8feb6c2af..78f1ccf6e 100644 --- a/src/main/res/layout/activity_edit_account.xml +++ b/src/main/res/layout/activity_edit_account.xml @@ -213,13 +213,13 @@ <Button android:id="@+id/os_optimization_disable" style="?android:attr/borderlessButtonStyle" - android:layout_marginRight="-8dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_below="@+id/os_optimization_body" + android:layout_marginRight="-8dp" android:text="@string/disable" android:textColor="@color/accent" /> </RelativeLayout> @@ -251,19 +251,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_session_established" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/session_est" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -285,19 +285,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_pep" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_pep" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -309,19 +309,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_blocking" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_blocking" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -333,19 +333,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_stream_management" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_sm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -357,19 +357,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_roster_version" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_roster_version" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -381,19 +381,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_carbon_messages" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_carbons" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -405,19 +405,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_mam" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_mam" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -429,19 +429,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_csi" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_csi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" tools:ignore="RtlHardcoded" /> </TableRow> @@ -454,19 +454,19 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_push" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_push" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" /> </TableRow> @@ -477,26 +477,26 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:ellipsize="end" + android:singleLine="true" android:text="@string/server_info_http_upload" android:textColor="@color/black87" - android:textSize="?attr/TextSizeBody" - android:singleLine="true" - android:ellipsize="end" /> + android:textSize="?attr/TextSizeBody" /> <TextView android:id="@+id/server_info_http_upload" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" - android:textColor="@color/black87" android:paddingLeft="4dp" + android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" /> </TableRow> </TableLayout> <RelativeLayout - android:id="@+id/otr_fingerprint_box" + android:id="@+id/pgp_fingerprint_box" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginTop="32dp"> @@ -505,6 +505,52 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" + android:layout_centerVertical="true" + android:layout_toLeftOf="@+id/action_delete_pgp" + android:orientation="vertical"> + + <TextView + android:id="@+id/pgp_fingerprint" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:fontFamily="monospace" + android:textColor="@color/primary" + android:textSize="?attr/TextSizeBody" + android:typeface="monospace" /> + + <TextView + android:id="@+id/pgp_fingerprint_desc" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/openpgp_key_id" + android:textColor="@color/black54" + android:textSize="?attr/TextSizeInfo" /> + </LinearLayout> + + <ImageButton + android:id="@+id/action_delete_pgp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:alpha="1.0" + android:background="?android:selectableItemBackground" + android:padding="@dimen/image_button_padding" + android:src="?attr/icon_remove" + android:visibility="visible" /> + </RelativeLayout> + + <RelativeLayout + android:id="@+id/otr_fingerprint_box" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_marginTop="24dp"> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_centerVertical="true" android:layout_toLeftOf="@+id/action_copy_to_clipboard" android:orientation="vertical"> @@ -518,6 +564,7 @@ android:typeface="monospace" /> <TextView + android:id="@+id/otr_fingerprint_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/otr_fingerprint" @@ -543,12 +590,13 @@ android:id="@+id/axolotl_fingerprint_box" android:layout_width="wrap_content" android:layout_height="match_parent" - android:layout_marginTop="32dp"> + android:layout_marginTop="24dp"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" + android:layout_centerVertical="true" android:layout_toLeftOf="@+id/axolotl_actions" android:orientation="vertical"> @@ -629,16 +677,16 @@ android:layout_height="wrap_content" android:divider="?android:dividerHorizontal" android:orientation="vertical" - android:showDividers="middle"> - </LinearLayout> + android:showDividers="middle"></LinearLayout> + <Button android:id="@+id/clear_devices" style="?android:attr/borderlessButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/clear_other_devices" android:layout_gravity="center_horizontal" - android:textColor="@color/accent"/> + android:text="@string/clear_other_devices" + android:textColor="@color/accent" /> </LinearLayout> </LinearLayout> </ScrollView> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 0dbf82efd..ad6d67d33 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -162,6 +162,8 @@ <string name="mgmt_account_delete">Delete account</string> <string name="mgmt_account_publish_avatar">Publish avatar</string> <string name="mgmt_account_publish_pgp">Publish OpenPGP public key</string> + <string name="unpublish_pgp">Remove OpenPGP public key</string> + <string name="unpublish_pgp_message">Are you sure you want to remove your OpenPGP public key from your presence announcement?\nYour contacts will no longer be able to send you OpenPGP encrypted messages.</string> <string name="openpgp_has_been_published">OpenPGP public key has been published.</string> <string name="republish_pgp_keys">Remember to republish your OpenPGP public keys!</string> <string name="mgmt_account_are_you_sure">Are you sure?</string> |