diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-01-19 13:42:34 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-01-19 13:42:34 +0100 |
commit | 6f1dbc2f7444c969ab590013e310257ca8e15ba7 (patch) | |
tree | a5b753c1c648e66642e3efedc0b720dc64267c70 | |
parent | a966d1afa1063d9e5ef5a4ef7b2a6b06386b800d (diff) | |
download | open-keychain-6f1dbc2f7444c969ab590013e310257ca8e15ba7.tar.gz open-keychain-6f1dbc2f7444c969ab590013e310257ca8e15ba7.tar.bz2 open-keychain-6f1dbc2f7444c969ab590013e310257ca8e15ba7.zip |
improve sharing of key
-rw-r--r-- | OpenPGP-Keychain/res/menu/key_view.xml | 50 | ||||
-rw-r--r-- | OpenPGP-Keychain/res/values/strings.xml | 14 | ||||
-rw-r--r-- | OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java | 39 |
3 files changed, 76 insertions, 27 deletions
diff --git a/OpenPGP-Keychain/res/menu/key_view.xml b/OpenPGP-Keychain/res/menu/key_view.xml index a6d2d5388..6d7a06ece 100644 --- a/OpenPGP-Keychain/res/menu/key_view.xml +++ b/OpenPGP-Keychain/res/menu/key_view.xml @@ -8,25 +8,43 @@ android:title="@string/menu_share"> <menu> <item - android:id="@+id/menu_key_view_share_default" + android:id="@+id/menu_key_view_share_fingerprint_title" android:showAsAction="never" - android:title="@string/menu_share"/> + android:title="@string/menu_share_title_fingerprint"> + <menu> + <item + android:id="@+id/menu_key_view_share_default_fingerprint" + android:showAsAction="never" + android:title="@string/menu_share_default_fingerprint"/> + <item + android:id="@+id/menu_key_view_share_qr_code_fingerprint" + android:showAsAction="never" + android:title="@string/menu_share_qr_code_fingerprint"/> + </menu> + </item> <item - android:id="@+id/menu_key_view_share_qr_code_fingerprint" + android:id="@+id/menu_key_view_share_title" android:showAsAction="never" - android:title="@string/menu_share_qr_code_fingerprint"/> - <item - android:id="@+id/menu_key_view_share_qr_code" - android:showAsAction="never" - android:title="@string/menu_share_qr_code"/> - <item - android:id="@+id/menu_key_view_share_nfc" - android:showAsAction="never" - android:title="@string/menu_share_nfc"/> - <item - android:id="@+id/menu_key_view_share_clipboard" - android:showAsAction="never" - android:title="@string/menu_copy_to_clipboard"/> + android:title="@string/menu_share_title"> + <menu> + <item + android:id="@+id/menu_key_view_share_default" + android:showAsAction="never" + android:title="@string/menu_share_default"/> + <item + android:id="@+id/menu_key_view_share_qr_code" + android:showAsAction="never" + android:title="@string/menu_share_qr_code"/> + <item + android:id="@+id/menu_key_view_share_nfc" + android:showAsAction="never" + android:title="@string/menu_share_nfc"/> + <item + android:id="@+id/menu_key_view_share_clipboard" + android:showAsAction="never" + android:title="@string/menu_copy_to_clipboard"/> + </menu> + </item> </menu> </item> <item diff --git a/OpenPGP-Keychain/res/values/strings.xml b/OpenPGP-Keychain/res/values/strings.xml index ba11ac824..07ed55a25 100644 --- a/OpenPGP-Keychain/res/values/strings.xml +++ b/OpenPGP-Keychain/res/values/strings.xml @@ -84,10 +84,15 @@ <string name="menu_key_server">Import from key server</string> <string name="menu_update_key">Update from key server</string> <string name="menu_export_key_to_server">Upload to key server</string> - <string name="menu_share">Share with…</string> - <string name="menu_share_qr_code">Share with QR Code (whole key)</string> - <string name="menu_share_qr_code_fingerprint">Share with QR Code (fingerprint)</string> - <string name="menu_share_nfc">Share with NFC</string> + <string name="menu_share">Share</string> + <string name="menu_share_title_fingerprint">Share fingerprint…</string> + <string name="menu_share_title">Share data…</string> + + <string name="menu_share_default_fingerprint">with…</string> + <string name="menu_share_default">with…</string> + <string name="menu_share_qr_code">with QR Code</string> + <string name="menu_share_qr_code_fingerprint">with QR Code</string> + <string name="menu_share_nfc">with NFC</string> <string name="menu_copy_to_clipboard">Copy to clipboard</string> <string name="menu_sign_key">Sign key</string> <string name="menu_beam_preferences">Beam settings</string> @@ -211,6 +216,7 @@ <string name="key_copied_to_clipboard">Key has been copied to the clipboard!</string> <string name="key_has_already_been_signed">Key has already been signed!</string> <string name="select_key_to_sign">Please select a key to be used for signing!</string> + <string name="key_too_big_for_sharing">Key is too big to be shared this way!</string> <!-- errors diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 30fd23e74..d0696464c 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -166,8 +166,11 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN mExportHelper.showExportKeysDialog(mDataUri, Id.type.public_key, Constants.path.APP_DIR + "/pubexport.asc"); return true; + case R.id.menu_key_view_share_default_fingerprint: + shareKey(mDataUri, true); + return true; case R.id.menu_key_view_share_default: - shareKey(mDataUri); + shareKey(mDataUri, false); return true; case R.id.menu_key_view_share_qr_code_fingerprint: shareKeyQrCode(mDataUri, true); @@ -435,15 +438,37 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN startActivity(signIntent); } - private void shareKey(Uri dataUri) { - // get public keyring as ascii armored string - long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri); - ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(this, dataUri, - new long[] { masterKeyId }); + private void shareKey(Uri dataUri, boolean fingerprintOnly) { + String content = null; + if (fingerprintOnly) { + long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri); + + // TODO: dublicated in ShareQrCodeDialog + content = "openpgp4fpr:"; + + String fingerprint = PgpKeyHelper.convertKeyToHex(masterKeyId); + + content = content + fingerprint; + } else { + // get public keyring as ascii armored string + long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri); + ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(this, + dataUri, new long[] { masterKeyId }); + + content = keyringArmored.get(0); + + // Android will fail with android.os.TransactionTooLargeException if key is too big + // see http://www.lonestarprod.com/?p=34 + if (content.length() >= 86389) { + Toast.makeText(getApplicationContext(), R.string.key_too_big_for_sharing, + Toast.LENGTH_LONG).show(); + return; + } + } // let user choose application Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, keyringArmored.get(0)); + sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.action_share_key_with))); |