From ed01c37fe18f98c25b7515c459ae446efa8232ca Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Wed, 25 Dec 2013 18:14:38 +0100 Subject: [PATCH 1/4] Added shortifyFingerprint() to PGPHelper --- .../sufficientlysecure/keychain/pgp/PgpKeyHelper.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java index e2d89bfab..5a3d332c4 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java @@ -40,6 +40,17 @@ import android.content.Context; public class PgpKeyHelper { + /** + * Returns the last 9 chars of a fingerprint + * + * @param fingerprint + * String containing short or long fingerprint + * @return + */ + public static String shortifyFingerprint(String fingerprint) { + return fingerprint.substring(41); + } + public static Date getCreationDate(PGPPublicKey key) { return key.getCreationTime(); } From 208ea19d5d56fe374bbf26e4ab4cce13dc99656b Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Wed, 25 Dec 2013 18:15:30 +0100 Subject: [PATCH 2/4] Added first draft of KeyDetailsActivity --- OpenPGP-Keychain/AndroidManifest.xml | 10 ++ OpenPGP-Keychain/res/layout/key_view.xml | 110 ++++++++++++++++++ OpenPGP-Keychain/res/values/strings.xml | 7 +- .../keychain/ui/KeyDetailsActivity.java | 90 ++++++++++++++ 4 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 OpenPGP-Keychain/res/layout/key_view.xml create mode 100644 OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java diff --git a/OpenPGP-Keychain/AndroidManifest.xml b/OpenPGP-Keychain/AndroidManifest.xml index ca203c1f2..36b835266 100644 --- a/OpenPGP-Keychain/AndroidManifest.xml +++ b/OpenPGP-Keychain/AndroidManifest.xml @@ -123,6 +123,16 @@ android:label="@string/title_edit_key" android:uiOptions="splitActionBarWhenNarrow" android:windowSoftInputMode="stateHidden" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenPGP-Keychain/res/values/strings.xml b/OpenPGP-Keychain/res/values/strings.xml index 63f267277..9909292d3 100644 --- a/OpenPGP-Keychain/res/values/strings.xml +++ b/OpenPGP-Keychain/res/values/strings.xml @@ -44,6 +44,7 @@ Export to Key Server Unknown Signature Key Sign Key + Key Details Help Share key with NFC @@ -53,6 +54,7 @@ General Defaults Advanced + Master Key Sign (Clipboard) @@ -142,6 +144,8 @@ %s key server(s) Fingerprint: Secret Key: + not valid + Secret Keyring None @@ -340,5 +344,4 @@ Go through all QR Codes using \'Next\', and scan them one by one. QR Code %1$d of %2$d - - \ No newline at end of file + diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java new file mode 100644 index 000000000..652b8a89b --- /dev/null +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java @@ -0,0 +1,90 @@ +package org.sufficientlysecure.keychain.ui; + +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.spongycastle.openpgp.PGPPublicKey; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.util.Log; + +import android.os.Bundle; +import android.text.format.DateFormat; +import android.widget.TextView; + +import com.actionbarsherlock.app.SherlockActivity; + +public class KeyDetailsActivity extends SherlockActivity { + + private PGPPublicKey publicKey; + private TextView mAlgorithm; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Bundle extras = getIntent().getExtras(); + setContentView(R.layout.key_view); + if (extras == null) { + return; + } + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + long key = extras.getLong("key"); + + KeyRings.buildPublicKeyRingsByMasterKeyIdUri(key + ""); + String[] projection = new String[]{""}; + + this.publicKey = ProviderHelper.getPGPPublicKeyByKeyId( + getApplicationContext(), key); + + TextView fingerprint = (TextView) this.findViewById(R.id.fingerprint); + fingerprint.setText(PgpKeyHelper.shortifyFingerprint(PgpKeyHelper.getFingerPrint(getApplicationContext(), key))); + String[] mainUserId = splitUserId(""); + + TextView expiry = (TextView) this.findViewById(R.id.expiry); + Date expiryDate = PgpKeyHelper.getExpiryDate(publicKey); + if (expiryDate == null) { + expiry.setText(""); + } else { + expiry.setText(DateFormat.getDateFormat(getApplicationContext()) + .format(expiryDate)); + } + + TextView creation = (TextView) this.findViewById(R.id.creation); + creation.setText(DateFormat.getDateFormat(getApplicationContext()) + .format(PgpKeyHelper.getCreationDate(publicKey))); + mAlgorithm = (TextView) this.findViewById(R.id.algorithm); + mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(publicKey)); + + } + + private String[] splitUserId(String userId) { + + String[] result = new String[]{"", "", ""}; + Log.v("UserID", userId); + + Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$"); + Matcher matcher = withComment.matcher(userId); + if (matcher.matches()) { + result[0] = matcher.group(1); + result[1] = matcher.group(2); + result[2] = matcher.group(3); + return result; + } + + Pattern withoutComment = Pattern.compile("^(.*) <(.*)>$"); + matcher = withoutComment.matcher(userId); + if (matcher.matches()) { + result[0] = matcher.group(1); + result[1] = matcher.group(2); + return result; + } + return result; + } +} From e823ef6efce29fce8a8deb31b22a2d75416702c4 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Wed, 25 Dec 2013 19:33:47 +0100 Subject: [PATCH 3/4] Renamed keyDetails to key_details --- OpenPGP-Keychain/AndroidManifest.xml | 2 +- OpenPGP-Keychain/res/values/strings.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenPGP-Keychain/AndroidManifest.xml b/OpenPGP-Keychain/AndroidManifest.xml index 36b835266..e363047e6 100644 --- a/OpenPGP-Keychain/AndroidManifest.xml +++ b/OpenPGP-Keychain/AndroidManifest.xml @@ -126,7 +126,7 @@ Export to Key Server Unknown Signature Key Sign Key - Key Details + Key Details Help Share key with NFC From f265cd4d68a4bb398467da1a8d19b6ca0b125602 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Wed, 25 Dec 2013 19:33:53 +0100 Subject: [PATCH 4/4] Added context menu item KeyDetails to KeyListPublicFragment --- .../keychain/ui/KeyListPublicFragment.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java index 0fdcea809..790ec5ccf 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java @@ -73,9 +73,10 @@ public class KeyListPublicFragment extends KeyListFragment implements @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - menu.add(0, Id.menu.update, 1, R.string.menu_update_key); - menu.add(0, Id.menu.signKey, 2, R.string.menu_sign_key); - menu.add(0, Id.menu.exportToServer, 3, R.string.menu_export_key_to_server); + menu.add(0, 23, 1, R.string.title_key_details); // :TODO: Fix magic number + menu.add(0, Id.menu.update, 2, R.string.menu_update_key); + menu.add(0, Id.menu.signKey, 3, R.string.menu_sign_key); + menu.add(0, Id.menu.exportToServer, 4, R.string.menu_export_key_to_server); menu.add(0, Id.menu.share, 6, R.string.menu_share); menu.add(0, Id.menu.share_qr_code, 7, R.string.menu_share_qr_code); menu.add(0, Id.menu.share_nfc, 8, R.string.menu_share_nfc); @@ -112,7 +113,13 @@ public class KeyListPublicFragment extends KeyListFragment implements startActivityForResult(queryIntent, Id.request.look_up_key_id); return true; - + case 23: + + Intent detailsIntent = new Intent(mKeyListActivity, KeyDetailsActivity.class); + detailsIntent.putExtra("key", ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId)); + startActivity(detailsIntent); + return true; + case Id.menu.exportToServer: Intent uploadIntent = new Intent(mKeyListActivity, KeyServerUploadActivity.class); uploadIntent.setAction(KeyServerUploadActivity.ACTION_EXPORT_KEY_TO_SERVER);