mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 00:18:51 -05:00
Merge branch 'development' of github.com:open-keychain/open-keychain into development
This commit is contained in:
commit
b8ed54bc69
@ -138,6 +138,7 @@
|
||||
android:name=".ui.SafeSlingerActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||
android:label="@string/title_exchange_keys"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:parentActivityName=".ui.KeyListActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
@ -266,7 +267,7 @@
|
||||
<!-- Keychain's own Actions -->
|
||||
<!-- DECRYPT with data Uri -->
|
||||
<intent-filter>
|
||||
<action android:name="org.sufficientlysecure.keychain.action.DECRYPT" />
|
||||
<action android:name="org.sufficientlysecure.keychain.action.DECRYPT_DATA" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
|
@ -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 share(Uri dataUri, ProviderHelper providerHelper, boolean fingerprintOnly,
|
||||
boolean toClipboard, boolean toSafeSlinger) {
|
||||
private void startSafeSlinger(Uri dataUri) {
|
||||
long keyId = 0;
|
||||
try {
|
||||
String content = null;
|
||||
byte[] keyBlob = null;
|
||||
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) {
|
||||
try {
|
||||
String content;
|
||||
if (fingerprintOnly) {
|
||||
byte[] data = (byte[]) providerHelper.getGenericData(
|
||||
KeyRings.buildUnifiedKeyRingUri(dataUri),
|
||||
@ -188,14 +194,9 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
if (toClipboard) {
|
||||
ClipboardReflection.copyToClipboard(getActivity(), content);
|
||||
@ -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);
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user