diff options
Diffstat (limited to 'OpenKeychain')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java | 102 | ||||
-rw-r--r-- | OpenKeychain/src/main/res/layout/log_display_activity.xml | 8 |
2 files changed, 30 insertions, 80 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java index a913057f0..aa260b654 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyShareFragment.java @@ -41,23 +41,20 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; -import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.dialog.ShareNfcDialogFragment; -import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; +import org.sufficientlysecure.keychain.util.Log; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import edu.cmu.cylab.starslinger.exchange.ExchangeActivity; -import edu.cmu.cylab.starslinger.exchange.ExchangeConfig; - public class ViewKeyShareFragment extends LoaderFragment implements LoaderManager.LoaderCallbacks<Cursor> { @@ -77,12 +74,8 @@ public class ViewKeyShareFragment extends LoaderFragment implements ProviderHelper mProviderHelper; - private static final int QR_CODE_SIZE = 1000; - private static final int LOADER_ID_UNIFIED = 0; - private static final int REQUEST_CODE_SAFESLINGER = 1; - private Uri mDataUri; @Override @@ -122,31 +115,31 @@ public class ViewKeyShareFragment extends LoaderFragment implements mFingerprintShareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - share(mDataUri, mProviderHelper, true, false, false); + share(mDataUri, mProviderHelper, true, false); } }); mFingerprintClipboardButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - share(mDataUri, mProviderHelper, true, true, false); + share(mDataUri, mProviderHelper, true, true); } }); mKeyShareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - share(mDataUri, mProviderHelper, false, false, false); + share(mDataUri, mProviderHelper, false, false); } }); mKeyClipboardButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - share(mDataUri, mProviderHelper, false, true, false); + share(mDataUri, mProviderHelper, false, true); } }); mKeySafeSlingerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - share(mDataUri, mProviderHelper, false, false, true); + startSafeSlinger(mDataUri); } }); mNfcHelpButton.setOnClickListener(new View.OnClickListener() { @@ -171,11 +164,24 @@ public class ViewKeyShareFragment extends LoaderFragment implements return root; } + private void startSafeSlinger(Uri dataUri) { + long keyId = 0; + try { + keyId = new ProviderHelper(getActivity()) + .getCachedPublicKeyRing(dataUri) + .extractOrGetMasterKeyId(); + } catch (PgpKeyNotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + } + Intent safeSlingerIntent = new Intent(getActivity(), SafeSlingerActivity.class); + safeSlingerIntent.putExtra(SafeSlingerActivity.EXTRA_MASTER_KEY_ID, keyId); + startActivityForResult(safeSlingerIntent, 0); + } + private void share(Uri dataUri, ProviderHelper providerHelper, boolean fingerprintOnly, - boolean toClipboard, boolean toSafeSlinger) { + boolean toClipboard) { try { - String content = null; - byte[] keyBlob = null; + String content; if (fingerprintOnly) { byte[] data = (byte[]) providerHelper.getGenericData( KeyRings.buildUnifiedKeyRingUri(dataUri), @@ -188,13 +194,8 @@ public class ViewKeyShareFragment extends LoaderFragment implements } } else { Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri); - if (toSafeSlinger) { - keyBlob = (byte[]) providerHelper.getGenericData( - uri, KeychainContract.KeyRingData.KEY_RING_DATA, ProviderHelper.FIELD_TYPE_BLOB); - } else { - // get public keyring as ascii armored string - content = providerHelper.getKeyRingAsArmoredString(uri); - } + // get public keyring as ascii armored string + content = providerHelper.getKeyRingAsArmoredString(uri); } if (toClipboard) { @@ -206,11 +207,6 @@ public class ViewKeyShareFragment extends LoaderFragment implements message = getResources().getString(R.string.key_copied_to_clipboard); } Notify.showNotify(getActivity(), message, Notify.Style.OK); - } else if (toSafeSlinger) { - Intent slingerIntent = new Intent(getActivity(), ExchangeActivity.class); - slingerIntent.putExtra(ExchangeConfig.extra.USER_DATA, keyBlob); - slingerIntent.putExtra(ExchangeConfig.extra.HOST_NAME, Constants.SAFESLINGER_SERVER); - startActivityForResult(slingerIntent, REQUEST_CODE_SAFESLINGER); } else { // Android will fail with android.os.TransactionTooLargeException if key is too big // see http://www.lonestarprod.com/?p=34 @@ -244,52 +240,6 @@ public class ViewKeyShareFragment extends LoaderFragment implements } } - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case REQUEST_CODE_SAFESLINGER: - switch (resultCode) { - case ExchangeActivity.RESULT_EXCHANGE_OK: - // import exchanged keys - Intent importIntent = new Intent(getActivity(), ImportKeysActivity.class); - importIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY); - importIntent.putExtra(ImportKeysActivity.EXTRA_KEY_BYTES, getSlingedKeys(data)); - startActivity(importIntent); - break; - case ExchangeActivity.RESULT_EXCHANGE_CANCELED: - // handle canceled result - // ... - break; - } - break; - } - super.onActivityResult(requestCode, resultCode, data); - } - - private static byte[] getSlingedKeys(Intent data) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - Bundle extras = data.getExtras(); - if (extras != null) { - byte[] d; - int i = 0; - do { - d = extras.getByteArray(ExchangeConfig.extra.MEMBER_DATA + i); - if (d != null) { - try { - out.write(d); - } catch (IOException e) { - Log.e(Constants.TAG, "IOException", e); - } - i++; - } - } while (d != null); - } - - return out.toByteArray(); - } - - private void showQrCodeDialog() { Intent qrCodeIntent = new Intent(getActivity(), QrCodeViewActivity.class); qrCodeIntent.setData(mDataUri); diff --git a/OpenKeychain/src/main/res/layout/log_display_activity.xml b/OpenKeychain/src/main/res/layout/log_display_activity.xml index 954467aa3..518b56776 100644 --- a/OpenKeychain/src/main/res/layout/log_display_activity.xml +++ b/OpenKeychain/src/main/res/layout/log_display_activity.xml @@ -2,15 +2,15 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:paddingLeft="8dp" + android:paddingRight="8dp"> <fragment android:id="@+id/list" android:name="org.sufficientlysecure.keychain.ui.LogDisplayFragment" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_weight="0.9" - android:layout_marginRight="8dp" - android:layout_marginLeft="8dp" /> + android:layout_weight="0.9" /> </LinearLayout>
\ No newline at end of file |