diff options
6 files changed, 79 insertions, 33 deletions
diff --git a/OpenPGP-Keychain/res/layout/share_qr_code_dialog.xml b/OpenPGP-Keychain/res/layout/share_qr_code_dialog.xml index 66102d3e5..0b58ae72f 100644 --- a/OpenPGP-Keychain/res/layout/share_qr_code_dialog.xml +++ b/OpenPGP-Keychain/res/layout/share_qr_code_dialog.xml @@ -9,7 +9,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="8dp" - android:text="@string/share_qr_code_dialog_start" android:textAppearance="@android:style/TextAppearance.Medium" /> <ImageView diff --git a/OpenPGP-Keychain/res/menu/key_view.xml b/OpenPGP-Keychain/res/menu/key_view.xml index d81c56a33..a6d2d5388 100644 --- a/OpenPGP-Keychain/res/menu/key_view.xml +++ b/OpenPGP-Keychain/res/menu/key_view.xml @@ -12,6 +12,10 @@ android:showAsAction="never" android:title="@string/menu_share"/> <item + android:id="@+id/menu_key_view_share_qr_code_fingerprint" + 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"/> diff --git a/OpenPGP-Keychain/res/values/strings.xml b/OpenPGP-Keychain/res/values/strings.xml index d5eff50a9..ba11ac824 100644 --- a/OpenPGP-Keychain/res/values/strings.xml +++ b/OpenPGP-Keychain/res/values/strings.xml @@ -43,7 +43,7 @@ <string name="section_signing_key">Your Key used for Signing</string> <string name="section_upload_key">Upload Key</string> <string name="section_key_server">Key Server</string> - + <!-- button --> <string name="btn_sign_to_clipboard">Sign (Clipboard)</string> <string name="btn_encrypt_to_clipboard">Encrypt to Clipboard</string> @@ -85,7 +85,8 @@ <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</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_copy_to_clipboard">Copy to clipboard</string> <string name="menu_sign_key">Sign key</string> @@ -353,7 +354,9 @@ <string name="api_error_wrong_signature">Signature check failed! Have you installed this app from a different source? If you are sure that this is not an attack, revoke this app\'s registration in OpenPGP Keychain and then register the app again.</string> <!-- Share --> + <string name="share_qr_code_dialog_title">Share with QR Code</string> <string name="share_qr_code_dialog_start">Go through all QR Codes using \'Next\', and scan them one by one.</string> + <string name="share_qr_code_dialog_fingerprint_text">Fingerprint:</string> <string name="share_qr_code_dialog_progress">QR Code with ID %1$d of %2$d</string> <string name="share_nfc_dialog">Share with NFC</string> diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java index 8c1f35e4e..6a5ce7415 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java @@ -454,6 +454,12 @@ public class PgpKeyHelper { return algorithmStr + ", " + keySize + " bit"; } + /** + * Converts fingerprint to hex with whitespaces after 4 characters + * + * @param fp + * @return + */ public static String convertFingerprintToHex(byte[] fp) { String fingerPrint = ""; for (int i = 0; i < fp.length; ++i) { diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 83bc083e9..30fd23e74 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -169,8 +169,11 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN case R.id.menu_key_view_share_default: shareKey(mDataUri); return true; + case R.id.menu_key_view_share_qr_code_fingerprint: + shareKeyQrCode(mDataUri, true); + return true; case R.id.menu_key_view_share_qr_code: - shareKeyQrCode(mDataUri); + shareKeyQrCode(mDataUri, false); return true; case R.id.menu_key_view_share_nfc: shareNfc(); @@ -318,10 +321,12 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN // the first key here is our master key if (data.moveToFirst()) { // get key id from MASTER_KEY_ID - String keyId = "0x" - + PgpKeyHelper.convertKeyIdToHex(data.getLong(KEYS_INDEX_KEY_ID)); - mKeyId.setText(keyId); + long keyId = data.getLong(KEYS_INDEX_KEY_ID); + + String keyIdStr = "0x" + PgpKeyHelper.convertKeyIdToHex(keyId); + mKeyId.setText(keyIdStr); + // get creation date from CREATION if (data.isNull(KEYS_INDEX_CREATION)) { mCreation.setText(R.string.none); } else { @@ -331,6 +336,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN creationDate)); } + // get creation date from EXPIRY if (data.isNull(KEYS_INDEX_EXPIRY)) { mExpiry.setText(R.string.none); } else { @@ -344,14 +350,9 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN data.getInt(KEYS_INDEX_ALGORITHM), data.getInt(KEYS_INDEX_KEY_SIZE)); mAlgorithm.setText(algorithmStr); - // TODO: Don't get key object here!!! - // put fingerprint in database? - PGPPublicKeyRing ring = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, - mDataUri); - PGPPublicKey publicKey = ring.getPublicKey(); + // TODO: Can this be done better? fingerprint in db? + String fingerprint = PgpKeyHelper.getFingerPrint(this, keyId); - String fingerprint = PgpKeyHelper.convertFingerprintToHex(publicKey - .getFingerprint()); fingerprint = fingerprint.replace(" ", "\n"); mFingerprint.setText(fingerprint); @@ -448,14 +449,9 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN getResources().getText(R.string.action_share_key_with))); } - private void shareKeyQrCode(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 }); - - ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(keyringArmored - .get(0)); + private void shareKeyQrCode(Uri dataUri, boolean fingerprintOnly) { + ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(dataUri, + fingerprintOnly); dialog.show(getSupportFragmentManager(), "shareQrCodeDialog"); } diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java index d11f0d323..771816bfc 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java @@ -19,12 +19,17 @@ package org.sufficientlysecure.keychain.ui.dialog; import java.util.ArrayList; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.QrCodeUtils; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -35,7 +40,8 @@ import android.widget.TextView; import com.actionbarsherlock.app.SherlockDialogFragment; public class ShareQrCodeDialogFragment extends SherlockDialogFragment { - private static final String ARG_CONTENT = "content"; + private static final String ARG_URI = "uri"; + private static final String ARG_FINGERPRINT_ONLY = "fingerprint_only"; private ImageView mImage; private TextView mText; @@ -52,10 +58,11 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment { * Content to be shared via QR Codes * @return */ - public static ShareQrCodeDialogFragment newInstance(String content) { + public static ShareQrCodeDialogFragment newInstance(Uri dataUri, boolean fingerprintOnly) { ShareQrCodeDialogFragment frag = new ShareQrCodeDialogFragment(); Bundle args = new Bundle(); - args.putString(ARG_CONTENT, content); + args.putParcelable(ARG_URI, dataUri); + args.putBoolean(ARG_FINGERPRINT_ONLY, fingerprintOnly); frag.setArguments(args); @@ -69,12 +76,12 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); - String content = getArguments().getString(ARG_CONTENT); - mContentList = splitString(content, 1000); + Uri dataUri = getArguments().getParcelable(ARG_URI); + boolean fingerprintOnly = getArguments().getBoolean(ARG_FINGERPRINT_ONLY); AlertDialog.Builder alert = new AlertDialog.Builder(activity); - alert.setTitle(R.string.menu_share_qr_code); + alert.setTitle(R.string.share_qr_code_dialog_title); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.share_qr_code_dialog, null); @@ -83,15 +90,46 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment { mImage = (ImageView) view.findViewById(R.id.share_qr_code_dialog_image); mText = (TextView) view.findViewById(R.id.share_qr_code_dialog_text); + // TODO + long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri); + + String content = null; + if (fingerprintOnly) { + content = "openpgp4fpr:"; + + String fingerprint = PgpKeyHelper.convertKeyToHex(masterKeyId); + + mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " " + + fingerprint); + + content = content + fingerprint; + + Log.d(Constants.TAG, "content: " + content); + + alert.setPositiveButton(R.string.btn_okay, null); + } else { + mText.setText(R.string.share_qr_code_dialog_start); + + // get public keyring as ascii armored string + ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString( + getActivity(), dataUri, new long[] { masterKeyId }); + + // TODO: binary? + + content = keyringArmored.get(0); + + // OnClickListener are set in onResume to prevent automatic dismissing of Dialogs + // http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked + alert.setPositiveButton(R.string.btn_next, null); + alert.setNegativeButton(android.R.string.cancel, null); + } + + mContentList = splitString(content, 1000); + // start with first mCounter = 0; updateQrCode(); - // OnClickListener are set in onResume to prevent automatic dismissing of Dialogs - // http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked - alert.setPositiveButton(R.string.btn_next, null); - alert.setNegativeButton(android.R.string.cancel, null); - return alert.create(); } |