Merge pull request #2034 from open-keychain/secret-key-selection
redesign access and allowed secret key api dialogs
This commit is contained in:
commit
84605097cb
|
@ -82,7 +82,7 @@ public class OpenPgpServiceTest {
|
|||
pi.send();
|
||||
|
||||
Thread.sleep(ACTIVITY_WAIT_TIME); // Wait for activity to start
|
||||
onView(withText(R.string.api_register_allow)).perform(click());
|
||||
onView(withText(R.string.button_allow)).perform(click());
|
||||
}
|
||||
|
||||
byte[] ciphertext;
|
||||
|
@ -121,10 +121,7 @@ public class OpenPgpServiceTest {
|
|||
pi.send();
|
||||
|
||||
Thread.sleep(ACTIVITY_WAIT_TIME); // Wait for activity to start
|
||||
onData(withKeyItemId(0x9D604D2F310716A3L))
|
||||
.inAdapterView(isAssignableFrom(AdapterView.class))
|
||||
.perform(click());
|
||||
onView(withText(R.string.api_settings_save)).perform(click());
|
||||
onView(withText(R.string.button_allow)).perform(click());
|
||||
}
|
||||
|
||||
{ // decrypt again, this time pending passphrase
|
||||
|
|
|
@ -861,6 +861,7 @@
|
|||
<activity
|
||||
android:name=".remote.ui.RemoteRegisterActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.Keychain.Transparent"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".remote.ui.RemoteSelectPubKeyActivity"
|
||||
|
@ -871,8 +872,9 @@
|
|||
android:exported="false"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".remote.ui.SelectAllowedKeysActivity"
|
||||
android:name=".remote.ui.RequestKeyPermissionActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.Keychain.Transparent"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".remote.ui.AppSettingsActivity"
|
||||
|
|
|
@ -40,14 +40,22 @@ public class DecryptVerifyResult extends InputPendingResult {
|
|||
byte[] mOutputBytes;
|
||||
|
||||
public long mOperationTime;
|
||||
private final long[] mSkippedDisallowedKeys;
|
||||
|
||||
public DecryptVerifyResult(int result, OperationLog log) {
|
||||
super(result, log);
|
||||
mSkippedDisallowedKeys = null;
|
||||
}
|
||||
|
||||
public DecryptVerifyResult(int result, OperationLog log, long[] skippedDisallowedKeys) {
|
||||
super(result, log);
|
||||
mSkippedDisallowedKeys = skippedDisallowedKeys;
|
||||
}
|
||||
|
||||
public DecryptVerifyResult(OperationLog log, RequiredInputParcel requiredInput,
|
||||
CryptoInputParcel cryptoInputParcel) {
|
||||
super(log, requiredInput, cryptoInputParcel);
|
||||
mSkippedDisallowedKeys = null;
|
||||
}
|
||||
|
||||
public DecryptVerifyResult(Parcel source) {
|
||||
|
@ -56,6 +64,7 @@ public class DecryptVerifyResult extends InputPendingResult {
|
|||
mDecryptionResult = source.readParcelable(OpenPgpDecryptionResult.class.getClassLoader());
|
||||
mDecryptionMetadata = source.readParcelable(OpenPgpMetadata.class.getClassLoader());
|
||||
mCachedCryptoInputParcel = source.readParcelable(CryptoInputParcel.class.getClassLoader());
|
||||
mSkippedDisallowedKeys = source.createLongArray();
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,6 +112,10 @@ public class DecryptVerifyResult extends InputPendingResult {
|
|||
return mOutputBytes;
|
||||
}
|
||||
|
||||
public long[] getSkippedDisallowedKeys() {
|
||||
return mSkippedDisallowedKeys;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
@ -113,6 +126,7 @@ public class DecryptVerifyResult extends InputPendingResult {
|
|||
dest.writeParcelable(mDecryptionResult, flags);
|
||||
dest.writeParcelable(mDecryptionMetadata, flags);
|
||||
dest.writeParcelable(mCachedCryptoInputParcel, flags);
|
||||
dest.writeLongArray(mSkippedDisallowedKeys);
|
||||
}
|
||||
|
||||
public static final Creator<DecryptVerifyResult> CREATOR = new Creator<DecryptVerifyResult>() {
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.io.OutputStream;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.security.SignatureException;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -208,7 +209,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||
|
||||
int symmetricEncryptionAlgo = 0;
|
||||
|
||||
boolean skippedDisallowedKey = false;
|
||||
HashSet<Long> skippedDisallowedEncryptionKeys = new HashSet<>();
|
||||
boolean insecureEncryptionKey = false;
|
||||
|
||||
// convenience method to return with error
|
||||
|
@ -607,7 +608,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||
if (!input.getAllowedKeyIds().contains(masterKeyId)) {
|
||||
// this key is in our db, but NOT allowed!
|
||||
// continue with the next packet in the while loop
|
||||
result.skippedDisallowedKey = true;
|
||||
result.skippedDisallowedEncryptionKeys.add(subKeyId);
|
||||
log.add(LogType.MSG_DC_ASKIP_NOT_ALLOWED, indent + 1);
|
||||
continue;
|
||||
}
|
||||
|
@ -816,9 +817,12 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||
return result.with(new DecryptVerifyResult(DecryptVerifyResult.RESULT_NO_DATA, log));
|
||||
}
|
||||
// there was data but key wasn't allowed
|
||||
if (result.skippedDisallowedKey) {
|
||||
if (!result.skippedDisallowedEncryptionKeys.isEmpty()) {
|
||||
log.add(LogType.MSG_DC_ERROR_NO_KEY, indent + 1);
|
||||
return result.with(new DecryptVerifyResult(DecryptVerifyResult.RESULT_KEY_DISALLOWED, log));
|
||||
long[] skippedDisallowedEncryptionKeys =
|
||||
KeyFormattingUtils.getUnboxedLongArray(result.skippedDisallowedEncryptionKeys);
|
||||
return result.with(new DecryptVerifyResult(
|
||||
DecryptVerifyResult.RESULT_KEY_DISALLOWED, log, skippedDisallowedEncryptionKeys));
|
||||
}
|
||||
// no packet has been found where we have the corresponding secret key in our db
|
||||
log.add(LogType.MSG_DC_ERROR_NO_KEY, indent + 1);
|
||||
|
|
|
@ -241,6 +241,11 @@ public class ApiDataAccessObject {
|
|||
mQueryInterface.insert(uri, values);
|
||||
}
|
||||
|
||||
public void addAllowedKeyIdForApp(String packageName, long allowedKeyId) {
|
||||
Uri uri = ApiAllowedKeys.buildBaseUri(packageName);
|
||||
addAllowedKeyIdForApp(uri, allowedKeyId);
|
||||
}
|
||||
|
||||
public byte[] getApiAppCertificate(String packageName) {
|
||||
Uri queryUri = ApiApps.buildByPackageNameUri(packageName);
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
|
||||
package org.sufficientlysecure.keychain.remote;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -31,14 +34,12 @@ import org.sufficientlysecure.keychain.remote.ui.RemotePassphraseDialogActivity;
|
|||
import org.sufficientlysecure.keychain.remote.ui.RemoteRegisterActivity;
|
||||
import org.sufficientlysecure.keychain.remote.ui.RemoteSecurityTokenOperationActivity;
|
||||
import org.sufficientlysecure.keychain.remote.ui.RemoteSelectPubKeyActivity;
|
||||
import org.sufficientlysecure.keychain.remote.ui.SelectAllowedKeysActivity;
|
||||
import org.sufficientlysecure.keychain.remote.ui.RequestKeyPermissionActivity;
|
||||
import org.sufficientlysecure.keychain.remote.ui.SelectSignKeyIdActivity;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.ViewKeyActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ApiPendingIntentFactory {
|
||||
|
||||
Context mContext;
|
||||
|
@ -103,9 +104,10 @@ public class ApiPendingIntentFactory {
|
|||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
PendingIntent createSelectAllowedKeysPendingIntent(Intent data, String packageName) {
|
||||
Intent intent = new Intent(mContext, SelectAllowedKeysActivity.class);
|
||||
intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(packageName));
|
||||
PendingIntent createRequestKeyPermissionPendingIntent(Intent data, String packageName, long[] masterKeyIds) {
|
||||
Intent intent = new Intent(mContext, RequestKeyPermissionActivity.class);
|
||||
intent.putExtra(RequestKeyPermissionActivity.EXTRA_PACKAGE_NAME, packageName);
|
||||
intent.putExtra(RequestKeyPermissionActivity.EXTRA_REQUESTED_KEY_IDS, masterKeyIds);
|
||||
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
|
|
@ -104,8 +104,7 @@ public class ApiPermissionHelper {
|
|||
}
|
||||
Log.e(Constants.TAG, "Not allowed to use service! return PendingIntent for registration!");
|
||||
|
||||
PendingIntent pi = piFactory.createRegisterPendingIntent(data,
|
||||
packageName, packageCertificate);
|
||||
PendingIntent pi = piFactory.createRegisterPendingIntent(data, packageName, packageCertificate);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
|
@ -230,7 +229,7 @@ public class ApiPermissionHelper {
|
|||
*
|
||||
* @throws WrongPackageCertificateException
|
||||
*/
|
||||
private boolean isPackageAllowed(String packageName) throws WrongPackageCertificateException {
|
||||
public boolean isPackageAllowed(String packageName) throws WrongPackageCertificateException {
|
||||
Log.d(Constants.TAG, "isPackageAllowed packageName: " + packageName);
|
||||
|
||||
byte[] storedPackageCert = mApiDao.getApiAppCertificate(packageName);
|
||||
|
|
|
@ -19,6 +19,15 @@
|
|||
package org.sufficientlysecure.keychain.remote;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
|
@ -66,15 +75,6 @@ import org.sufficientlysecure.keychain.util.InputData;
|
|||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class OpenPgpService extends Service {
|
||||
public static final int API_VERSION_WITH_RESULT_METADATA = 4;
|
||||
public static final int API_VERSION_WITH_KEY_REVOKED_EXPIRED = 5;
|
||||
|
@ -393,13 +393,15 @@ public class OpenPgpService extends Service {
|
|||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
|
||||
return result;
|
||||
} else {
|
||||
//
|
||||
if (pgpResult.isKeysDisallowed()) {
|
||||
long[] skippedDisallowedEncryptionKeys = pgpResult.getSkippedDisallowedKeys();
|
||||
if (pgpResult.isKeysDisallowed() &&
|
||||
skippedDisallowedEncryptionKeys != null && skippedDisallowedEncryptionKeys.length > 0) {
|
||||
// allow user to select allowed keys
|
||||
Intent result = new Intent();
|
||||
String packageName = mApiPermissionHelper.getCurrentCallingPackage();
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT,
|
||||
mApiPendingIntentFactory.createSelectAllowedKeysPendingIntent(data, packageName));
|
||||
mApiPendingIntentFactory.createRequestKeyPermissionPendingIntent(
|
||||
data, packageName, skippedDisallowedEncryptionKeys));
|
||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.sufficientlysecure.keychain.remote;
|
|||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
|
@ -10,7 +9,6 @@ import android.content.ContentResolver;
|
|||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
|
@ -21,6 +19,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing;
|
|||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
|
||||
|
@ -146,7 +145,7 @@ class OpenPgpServiceKeyIdExtractor {
|
|||
}
|
||||
|
||||
if (!hasUserIds || hasMissingUserIds || hasDuplicateUserIds) {
|
||||
long[] keyIdsArray = getUnboxedLongArray(keyIds);
|
||||
long[] keyIdsArray = KeyFormattingUtils.getUnboxedLongArray(keyIds);
|
||||
PendingIntent pi = apiPendingIntentFactory.createSelectPublicKeyPendingIntent(data, keyIdsArray,
|
||||
missingEmails, duplicateEmails, hasUserIds);
|
||||
|
||||
|
@ -164,16 +163,6 @@ class OpenPgpServiceKeyIdExtractor {
|
|||
return new KeyIdResult(keyIds);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static long[] getUnboxedLongArray(@NonNull Collection<Long> arrayList) {
|
||||
long[] result = new long[arrayList.size()];
|
||||
int i = 0;
|
||||
for (Long e : arrayList) {
|
||||
result[i++] = e;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static class KeyIdResult {
|
||||
private final Intent mResultIntent;
|
||||
private final HashSet<Long> mKeyIds;
|
||||
|
@ -206,7 +195,7 @@ class OpenPgpServiceKeyIdExtractor {
|
|||
if (mKeyIds == null) {
|
||||
throw new AssertionError("key ids must not be null when getKeyIds is called!");
|
||||
}
|
||||
return getUnboxedLongArray(mKeyIds);
|
||||
return KeyFormattingUtils.getUnboxedLongArray(mKeyIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,73 +18,173 @@
|
|||
package org.sufficientlysecure.keychain.remote.ui;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.ApiDataAccessObject;
|
||||
import org.sufficientlysecure.keychain.remote.AppSettings;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.remote.ui.RemoteRegisterPresenter.RemoteRegisterView;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
|
||||
|
||||
public class RemoteRegisterActivity extends BaseActivity {
|
||||
|
||||
public class RemoteRegisterActivity extends FragmentActivity {
|
||||
public static final String EXTRA_PACKAGE_NAME = "package_name";
|
||||
public static final String EXTRA_PACKAGE_SIGNATURE = "package_signature";
|
||||
|
||||
public static final String EXTRA_DATA = "data";
|
||||
|
||||
private AppSettingsHeaderFragment mAppSettingsHeaderFragment;
|
||||
|
||||
@Override
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.api_remote_register_app);
|
||||
}
|
||||
private RemoteRegisterPresenter presenter;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Bundle extras = getIntent().getExtras();
|
||||
this.presenter = new RemoteRegisterPresenter(getBaseContext());
|
||||
|
||||
final String packageName = extras.getString(EXTRA_PACKAGE_NAME);
|
||||
final byte[] packageSignature = extras.getByteArray(EXTRA_PACKAGE_SIGNATURE);
|
||||
Log.d(Constants.TAG, "ACTION_REGISTER packageName: " + packageName);
|
||||
if (savedInstanceState == null) {
|
||||
RemoteRegisterDialogFragment frag = new RemoteRegisterDialogFragment();
|
||||
frag.show(getSupportFragmentManager(), "requestKeyDialog");
|
||||
}
|
||||
}
|
||||
|
||||
final ApiDataAccessObject apiDao = new ApiDataAccessObject(this);
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
mAppSettingsHeaderFragment = (AppSettingsHeaderFragment) getSupportFragmentManager().findFragmentById(
|
||||
R.id.api_app_settings_fragment);
|
||||
Intent intent = getIntent();
|
||||
Intent resultData = intent.getParcelableExtra(EXTRA_DATA);
|
||||
String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
|
||||
byte[] packageSignature = intent.getByteArrayExtra(EXTRA_PACKAGE_SIGNATURE);
|
||||
|
||||
AppSettings settings = new AppSettings(packageName, packageSignature);
|
||||
mAppSettingsHeaderFragment.setAppSettings(settings);
|
||||
presenter.setupFromIntentData(resultData, packageName, packageSignature);
|
||||
}
|
||||
|
||||
// Inflate a "Done"/"Cancel" custom action bar view
|
||||
setFullScreenDialogTwoButtons(
|
||||
R.string.api_register_allow, R.drawable.ic_check_white_24dp,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Allow
|
||||
apiDao.insertApiApp(mAppSettingsHeaderFragment.getAppSettings());
|
||||
public static class RemoteRegisterDialogFragment extends DialogFragment {
|
||||
private RemoteRegisterPresenter presenter;
|
||||
private RemoteRegisterView mvpView;
|
||||
|
||||
// give data through for new service call
|
||||
Intent resultData = extras.getParcelable(EXTRA_DATA);
|
||||
RemoteRegisterActivity.this.setResult(RESULT_OK, resultData);
|
||||
RemoteRegisterActivity.this.finish();
|
||||
}
|
||||
}, R.string.api_register_disallow, R.drawable.ic_close_white_24dp,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Disallow
|
||||
RemoteRegisterActivity.this.setResult(RESULT_CANCELED);
|
||||
RemoteRegisterActivity.this.finish();
|
||||
private Button buttonAllow;
|
||||
private Button buttonCancel;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Activity activity = getActivity();
|
||||
|
||||
ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity);
|
||||
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
View view = LayoutInflater.from(theme).inflate(R.layout.api_remote_register_app, null, false);
|
||||
alert.setView(view);
|
||||
|
||||
buttonAllow = (Button) view.findViewById(R.id.button_allow);
|
||||
buttonCancel = (Button) view.findViewById(R.id.button_cancel);
|
||||
|
||||
setupListenersForPresenter();
|
||||
mvpView = createMvpView(view);
|
||||
|
||||
return alert.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
presenter = ((RemoteRegisterActivity) getActivity()).presenter;
|
||||
presenter.setView(mvpView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
super.onCancel(dialog);
|
||||
|
||||
if (presenter != null) {
|
||||
presenter.onCancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
|
||||
if (presenter != null) {
|
||||
presenter.setView(null);
|
||||
presenter = null;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private RemoteRegisterView createMvpView(View view) {
|
||||
final TextView titleText = (TextView) view.findViewById(R.id.api_register_text);
|
||||
final ImageView iconClientApp = (ImageView) view.findViewById(R.id.icon_client_app);
|
||||
|
||||
return new RemoteRegisterView() {
|
||||
@Override
|
||||
public void finishWithResult(Intent resultIntent) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
activity.setResult(RESULT_OK, resultIntent);
|
||||
activity.finish();
|
||||
}
|
||||
);
|
||||
|
||||
@Override
|
||||
public void finishAsCancelled() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
activity.setResult(RESULT_CANCELED);
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitleText(String text) {
|
||||
titleText.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitleClientIcon(Drawable drawable) {
|
||||
iconClientApp.setImageDrawable(drawable);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setupListenersForPresenter() {
|
||||
buttonAllow.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
presenter.onClickAllow();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
presenter.onClickCancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package org.sufficientlysecure.keychain.remote.ui;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.ApiDataAccessObject;
|
||||
import org.sufficientlysecure.keychain.remote.AppSettings;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
|
||||
class RemoteRegisterPresenter {
|
||||
private final ApiDataAccessObject apiDao;
|
||||
private final PackageManager packageManager;
|
||||
private final Context context;
|
||||
|
||||
|
||||
private RemoteRegisterView view;
|
||||
private Intent resultData;
|
||||
private AppSettings appSettings;
|
||||
|
||||
|
||||
RemoteRegisterPresenter(Context context) {
|
||||
this.context = context;
|
||||
|
||||
apiDao = new ApiDataAccessObject(context);
|
||||
packageManager = context.getPackageManager();
|
||||
}
|
||||
|
||||
public void setView(RemoteRegisterView view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
void setupFromIntentData(Intent resultData, String packageName, byte[] packageSignature) {
|
||||
this.appSettings = new AppSettings(packageName, packageSignature);
|
||||
this.resultData = resultData;
|
||||
|
||||
try {
|
||||
setPackageInfo(packageName);
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.e(Constants.TAG, "Unable to find info of calling app!");
|
||||
view.finishAsCancelled();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void setPackageInfo(String packageName) throws NameNotFoundException {
|
||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
|
||||
Drawable appIcon = packageManager.getApplicationIcon(applicationInfo);
|
||||
CharSequence appName = packageManager.getApplicationLabel(applicationInfo);
|
||||
|
||||
view.setTitleClientIcon(appIcon);
|
||||
view.setTitleText(context.getString(R.string.api_register_text, appName));
|
||||
}
|
||||
|
||||
void onClickAllow() {
|
||||
apiDao.insertApiApp(appSettings);
|
||||
view.finishWithResult(resultData);
|
||||
}
|
||||
|
||||
void onClickCancel() {
|
||||
view.finishAsCancelled();
|
||||
}
|
||||
|
||||
void onCancel() {
|
||||
view.finishAsCancelled();
|
||||
}
|
||||
|
||||
interface RemoteRegisterView {
|
||||
void finishWithResult(Intent resultData);
|
||||
void finishAsCancelled();
|
||||
|
||||
void setTitleText(String text);
|
||||
void setTitleClientIcon(Drawable drawable);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Vincent Breitmoser <look@my.amazin.horse>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.remote.ui;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpUtils.UserId;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.remote.ui.RequestKeyPermissionPresenter.RequestKeyPermissionMvpView;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
|
||||
|
||||
|
||||
public class RequestKeyPermissionActivity extends FragmentActivity {
|
||||
public static final String EXTRA_PACKAGE_NAME = "package_name";
|
||||
public static final String EXTRA_REQUESTED_KEY_IDS = "requested_key_ids";
|
||||
|
||||
|
||||
private RequestKeyPermissionPresenter presenter;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
presenter = RequestKeyPermissionPresenter.createRequestKeyPermissionPresenter(getBaseContext());
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
RequestKeyPermissionFragment frag = new RequestKeyPermissionFragment();
|
||||
frag.show(getSupportFragmentManager(), "requestKeyDialog");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
Intent intent = getIntent();
|
||||
String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
|
||||
long masterKeyIds[] = intent.getLongArrayExtra(EXTRA_REQUESTED_KEY_IDS);
|
||||
|
||||
presenter.setupFromIntentData(packageName, masterKeyIds);
|
||||
}
|
||||
|
||||
public static class RequestKeyPermissionFragment extends DialogFragment {
|
||||
private RequestKeyPermissionMvpView mvpView;
|
||||
private RequestKeyPermissionPresenter presenter;
|
||||
private Button buttonCancel;
|
||||
private Button buttonAllow;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Activity activity = getActivity();
|
||||
|
||||
ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity);
|
||||
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
View view = LayoutInflater.from(theme).inflate(R.layout.api_remote_request_key_permission, null, false);
|
||||
alert.setView(view);
|
||||
|
||||
buttonAllow = (Button) view.findViewById(R.id.button_allow);
|
||||
buttonCancel = (Button) view.findViewById(R.id.button_cancel);
|
||||
|
||||
setupListenersForPresenter();
|
||||
mvpView = createMvpView(view);
|
||||
|
||||
return alert.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
presenter = ((RequestKeyPermissionActivity) getActivity()).presenter;
|
||||
presenter.setView(mvpView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
super.onCancel(dialog);
|
||||
|
||||
if (presenter != null) {
|
||||
presenter.onCancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
|
||||
if (presenter != null) {
|
||||
presenter.setView(null);
|
||||
presenter = null;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private RequestKeyPermissionMvpView createMvpView(View view) {
|
||||
final TextView titleText = (TextView) view.findViewById(R.id.select_identity_key_title);
|
||||
final TextView keyUserIdView = (TextView) view.findViewById(R.id.select_key_item_name);
|
||||
final ImageView iconClientApp = (ImageView) view.findViewById(R.id.icon_client_app);
|
||||
final View keyUnavailableWarning = view.findViewById(R.id.requested_key_unavailable_warning);
|
||||
final View keyInfoLayout = view.findViewById(R.id.key_info_layout);
|
||||
|
||||
return new RequestKeyPermissionMvpView() {
|
||||
@Override
|
||||
public void switchToLayoutRequestKeyChoice() {
|
||||
keyInfoLayout.setVisibility(View.VISIBLE);
|
||||
keyUnavailableWarning.setVisibility(View.GONE);
|
||||
buttonAllow.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchToLayoutNoSecret() {
|
||||
keyInfoLayout.setVisibility(View.VISIBLE);
|
||||
keyUnavailableWarning.setVisibility(View.VISIBLE);
|
||||
buttonAllow.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayKeyInfo(UserId userId) {
|
||||
keyUserIdView.setText(userId.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
activity.setResult(Activity.RESULT_OK);
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishAsCancelled() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
activity.setResult(Activity.RESULT_CANCELED);
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitleText(String text) {
|
||||
titleText.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitleClientIcon(Drawable drawable) {
|
||||
iconClientApp.setImageDrawable(drawable);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setupListenersForPresenter() {
|
||||
buttonAllow.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
presenter.onClickAllow();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
presenter.onClickCancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
package org.sufficientlysecure.keychain.remote.ui;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpUtils.UserId;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.ApiDataAccessObject;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.remote.ApiPermissionHelper;
|
||||
import org.sufficientlysecure.keychain.remote.ApiPermissionHelper.WrongPackageCertificateException;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
|
||||
class RequestKeyPermissionPresenter {
|
||||
private final Context context;
|
||||
private final PackageManager packageManager;
|
||||
private final ApiDataAccessObject apiDataAccessObject;
|
||||
private final ApiPermissionHelper apiPermissionHelper;
|
||||
|
||||
private RequestKeyPermissionMvpView view;
|
||||
|
||||
private String packageName;
|
||||
private long masterKeyId;
|
||||
private ProviderHelper providerHelper;
|
||||
|
||||
|
||||
static RequestKeyPermissionPresenter createRequestKeyPermissionPresenter(Context context) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context);
|
||||
ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject);
|
||||
ProviderHelper providerHelper = new ProviderHelper(context);
|
||||
|
||||
return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager,
|
||||
providerHelper);
|
||||
}
|
||||
|
||||
private RequestKeyPermissionPresenter(Context context, ApiDataAccessObject apiDataAccessObject,
|
||||
ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, ProviderHelper providerHelper) {
|
||||
this.context = context;
|
||||
this.apiDataAccessObject = apiDataAccessObject;
|
||||
this.apiPermissionHelper = apiPermissionHelper;
|
||||
this.packageManager = packageManager;
|
||||
this.providerHelper = providerHelper;
|
||||
}
|
||||
|
||||
void setView(RequestKeyPermissionMvpView view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
void setupFromIntentData(String packageName, long[] masterKeyIds) {
|
||||
checkPackageAllowed(packageName);
|
||||
|
||||
try {
|
||||
setPackageInfo(packageName);
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.e(Constants.TAG, "Unable to find info of calling app!");
|
||||
view.finishAsCancelled();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setRequestedMasterKeyId(masterKeyIds);
|
||||
} catch (PgpKeyNotFoundException e) {
|
||||
view.finishAsCancelled();
|
||||
}
|
||||
}
|
||||
|
||||
private void setRequestedMasterKeyId(long[] subKeyIds) throws PgpKeyNotFoundException {
|
||||
CachedPublicKeyRing secretKeyRingOrPublicFallback = findSecretKeyRingOrPublicFallback(subKeyIds);
|
||||
|
||||
if (secretKeyRingOrPublicFallback == null) {
|
||||
throw new PgpKeyNotFoundException("No key found among requested!");
|
||||
}
|
||||
|
||||
this.masterKeyId = secretKeyRingOrPublicFallback.getMasterKeyId();
|
||||
|
||||
UserId userId = secretKeyRingOrPublicFallback.getSplitPrimaryUserIdWithFallback();
|
||||
view.displayKeyInfo(userId);
|
||||
|
||||
if (secretKeyRingOrPublicFallback.hasAnySecret()) {
|
||||
view.switchToLayoutRequestKeyChoice();
|
||||
} else {
|
||||
view.switchToLayoutNoSecret();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CachedPublicKeyRing findSecretKeyRingOrPublicFallback(long[] subKeyIds) {
|
||||
CachedPublicKeyRing publicFallbackRing = null;
|
||||
for (long candidateSubKeyId : subKeyIds) {
|
||||
try {
|
||||
CachedPublicKeyRing cachedPublicKeyRing = providerHelper.getCachedPublicKeyRing(
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(candidateSubKeyId)
|
||||
);
|
||||
|
||||
SecretKeyType secretKeyType = cachedPublicKeyRing.getSecretKeyType(candidateSubKeyId);
|
||||
if (secretKeyType.isUsable()) {
|
||||
return cachedPublicKeyRing;
|
||||
}
|
||||
if (publicFallbackRing == null) {
|
||||
publicFallbackRing = cachedPublicKeyRing;
|
||||
}
|
||||
} catch (PgpKeyNotFoundException | NotFoundException e) {
|
||||
// no matter
|
||||
}
|
||||
}
|
||||
return publicFallbackRing;
|
||||
}
|
||||
|
||||
private void setPackageInfo(String packageName) throws NameNotFoundException {
|
||||
this.packageName = packageName;
|
||||
|
||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
|
||||
Drawable appIcon = packageManager.getApplicationIcon(applicationInfo);
|
||||
CharSequence appName = packageManager.getApplicationLabel(applicationInfo);
|
||||
|
||||
view.setTitleClientIcon(appIcon);
|
||||
view.setTitleText(context.getString(R.string.request_permission_msg, appName));
|
||||
}
|
||||
|
||||
private void checkPackageAllowed(String packageName) {
|
||||
boolean packageAllowed;
|
||||
try {
|
||||
packageAllowed = apiPermissionHelper.isPackageAllowed(packageName);
|
||||
} catch (WrongPackageCertificateException e) {
|
||||
packageAllowed = false;
|
||||
}
|
||||
if (!packageAllowed) {
|
||||
throw new IllegalStateException("Pending intent launched by unknown app!");
|
||||
}
|
||||
}
|
||||
|
||||
void onClickAllow() {
|
||||
apiDataAccessObject.addAllowedKeyIdForApp(packageName, masterKeyId);
|
||||
view.finish();
|
||||
}
|
||||
|
||||
void onClickCancel() {
|
||||
view.finishAsCancelled();
|
||||
}
|
||||
|
||||
void onCancel() {
|
||||
view.finishAsCancelled();
|
||||
}
|
||||
|
||||
interface RequestKeyPermissionMvpView {
|
||||
void switchToLayoutRequestKeyChoice();
|
||||
void switchToLayoutNoSecret();
|
||||
|
||||
void setTitleText(String text);
|
||||
void setTitleClientIcon(Drawable drawable);
|
||||
|
||||
void displayKeyInfo(UserId userId);
|
||||
|
||||
void finish();
|
||||
void finishAsCancelled();
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.remote.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
public class SelectAllowedKeysActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_SERVICE_INTENT = "data";
|
||||
|
||||
private AppSettingsAllowedKeysListFragment mAllowedKeysFragment;
|
||||
|
||||
Intent mServiceData;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Inflate a "Done" custom action bar
|
||||
setFullScreenDialogDoneClose(R.string.api_settings_save,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
save();
|
||||
}
|
||||
},
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
|
||||
Intent intent = getIntent();
|
||||
mServiceData = intent.getParcelableExtra(EXTRA_SERVICE_INTENT);
|
||||
Uri appUri = intent.getData();
|
||||
if (appUri == null) {
|
||||
Log.e(Constants.TAG, "Intent data missing. Should be Uri of app!");
|
||||
finish();
|
||||
return;
|
||||
} else {
|
||||
Log.d(Constants.TAG, "uri: " + appUri);
|
||||
loadData(savedInstanceState, appUri);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.api_remote_select_allowed_keys);
|
||||
}
|
||||
|
||||
private void save() {
|
||||
mAllowedKeysFragment.saveAllowedKeys();
|
||||
setResult(Activity.RESULT_OK, mServiceData);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void loadData(Bundle savedInstanceState, Uri appUri) {
|
||||
Uri allowedKeysUri = appUri.buildUpon().appendPath(KeychainContract.PATH_ALLOWED_KEYS).build();
|
||||
Log.d(Constants.TAG, "allowedKeysUri: " + allowedKeysUri);
|
||||
startListFragments(savedInstanceState, allowedKeysUri);
|
||||
}
|
||||
|
||||
private void startListFragments(Bundle savedInstanceState, Uri allowedKeysUri) {
|
||||
// However, if we're being restored from a previous state,
|
||||
// then we don't need to do anything and should return or else
|
||||
// we could end up with overlapping fragments.
|
||||
if (savedInstanceState != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create an instance of the fragments
|
||||
mAllowedKeysFragment = AppSettingsAllowedKeysListFragment.newInstance(allowedKeysUri);
|
||||
// Add the fragment to the 'fragment_container' FrameLayout
|
||||
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.api_allowed_keys_list_fragment, mAllowedKeysFragment)
|
||||
.commitAllowingStateLoss();
|
||||
// do it immediately!
|
||||
getSupportFragmentManager().executePendingTransactions();
|
||||
}
|
||||
|
||||
}
|
|
@ -293,7 +293,7 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
|||
setupEditTextFocusNext(mCodeEditText);
|
||||
setupEditTextSuccessListener(mCodeEditText);
|
||||
|
||||
mStatusAnimator = (ToolableViewAnimator) view.findViewById(R.id.status_animator);
|
||||
mStatusAnimator = (ToolableViewAnimator) view.findViewById(R.id.button_bar_animator);
|
||||
mTitleAnimator = (ToolableViewAnimator) view.findViewById(R.id.title_animator);
|
||||
mCodeFieldsAnimator = (ToolableViewAnimator) view.findViewById(R.id.code_animator);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.content.Context;
|
|||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
|
@ -51,6 +52,7 @@ import java.nio.ByteBuffer;
|
|||
import java.security.DigestException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
public class KeyFormattingUtils {
|
||||
|
@ -410,6 +412,16 @@ public class KeyFormattingUtils {
|
|||
|
||||
public static final int DEFAULT_COLOR = -1;
|
||||
|
||||
@NonNull
|
||||
public static long[] getUnboxedLongArray(@NonNull Collection<Long> arrayList) {
|
||||
long[] result = new long[arrayList.size()];
|
||||
int i = 0;
|
||||
for (Long e : arrayList) {
|
||||
result[i++] = e;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
REVOKED,
|
||||
EXPIRED,
|
||||
|
|
|
@ -354,7 +354,7 @@
|
|||
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
|
||||
|
||||
<org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator
|
||||
android:id="@+id/status_animator"
|
||||
android:id="@+id/button_bar_animator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
|
|
|
@ -354,7 +354,7 @@
|
|||
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
|
||||
|
||||
<org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator
|
||||
android:id="@+id/status_animator"
|
||||
android:id="@+id/button_bar_animator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
|
|
|
@ -1,39 +1,114 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:layout_marginTop="24dp"
|
||||
>
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbar_include"
|
||||
layout="@layout/toolbar_standalone" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_below="@id/toolbar_include"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:elevation="4dp"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="center_horizontal"
|
||||
tools:targetApi="lollipop">
|
||||
|
||||
<LinearLayout
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:src="@drawable/link_24dp"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/icon_client_app"
|
||||
tools:src="@drawable/apps_k9"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:orientation="vertical">
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/api_register_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="3dip"
|
||||
android:text="@string/api_register_text"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/api_app_settings_fragment"
|
||||
android:name="org.sufficientlysecure.keychain.remote.ui.AppSettingsHeaderFragment"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:layout="@layout/api_app_settings_fragment" />
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingRight="24dp"
|
||||
android:paddingTop="24dp"
|
||||
android:paddingBottom="16dp"
|
||||
>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:textAppearanceLarge"
|
||||
android:text="@string/api_register_title"
|
||||
android:id="@+id/dialog_title"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/api_register_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:text="@string/api_register_text"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end"
|
||||
android:padding="8dp"
|
||||
style="?buttonBarStyle">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_cancel"
|
||||
android:id="@+id/button_cancel"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_allow"
|
||||
android:id="@+id/button_allow"
|
||||
style="?buttonBarButtonStyle" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,166 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:layout_marginTop="24dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:elevation="4dp"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="center_horizontal"
|
||||
tools:targetApi="lollipop">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:src="@drawable/link_24dp"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/icon_client_app"
|
||||
tools:src="@drawable/apps_k9"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingRight="24dp"
|
||||
android:paddingTop="24dp"
|
||||
android:paddingBottom="16dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:textAppearanceLarge"
|
||||
android:text="@string/request_permission_title"
|
||||
android:id="@+id/dialog_title"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/select_identity_key_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:text="@string/request_permission_msg"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="horizontal"
|
||||
android:background="?selectableItemBackground"
|
||||
android:id="@+id/key_info_layout"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:padding="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:src="@drawable/ic_vpn_key_grey_24dp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/requested_key_label"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/select_key_item_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Alice Skywalker"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/requested_key_unavailable_warning"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:textColor="@color/android_red_dark"
|
||||
android:id="@+id/requested_key_unavailable_warning"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end"
|
||||
android:padding="8dp"
|
||||
style="?buttonBarStyle">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_cancel"
|
||||
android:id="@+id/button_cancel"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_allow"
|
||||
android:id="@+id/button_allow"
|
||||
tools:enabled="false"
|
||||
style="?buttonBarButtonStyle" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,38 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbar_include"
|
||||
layout="@layout/toolbar_standalone" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_below="@id/toolbar_include"
|
||||
android:padding="16dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/api_select_keys_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/api_select_keys_text" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/api_allowed_keys_list_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -384,7 +384,7 @@
|
|||
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
|
||||
|
||||
<org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator
|
||||
android:id="@+id/status_animator"
|
||||
android:id="@+id/button_bar_animator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
|
|
|
@ -655,7 +655,8 @@
|
|||
<string name="api_settings_accounts_empty">"No accounts attached to this app."</string>
|
||||
<string name="api_create_account_text">"No key is configured for this account. Please select one of your existing keys or create a new one.\nApps can only decrypt/sign with the keys selected here!"</string>
|
||||
<string name="api_update_account_text">"The key saved for this account has been deleted. Please select a different one!\nApps can only decrypt/sign with the keys selected here!"</string>
|
||||
<string name="api_register_text">"The displayed app wants to encrypt/decrypt messages and sign them in your name.\nAllow access?\n\nWARNING: If you do not know why this screen appeared, disallow access! You can revoke access later using the 'Apps' screen."</string>
|
||||
<string name="api_register_title">"Allow access to OpenKeychain?"</string>
|
||||
<string name="api_register_text">"%s requests to use OpenKeychain as a crypto provider. You will still be asked for permission before the app can use any of your keys for decryption.\n\nYou can revoke access later in the 'Apps' screen."</string>
|
||||
<string name="api_register_allow">"Allow access"</string>
|
||||
<string name="api_register_disallow">"Disallow access"</string>
|
||||
<string name="api_register_error_select_key">"Please select a key!"</string>
|
||||
|
@ -1797,4 +1798,11 @@
|
|||
<string name="redirect_import_key_yes">"Scan again"</string>
|
||||
<string name="redirect_import_key_no">"Close"</string>
|
||||
<string name="title_activity_redirect_key">"Key import redirection"</string>
|
||||
|
||||
<string name="request_permission_title">Allow access to your key?</string>
|
||||
<string name="request_permission_msg">%1$s requests access to one of your keys, which allows it to decrypt messages sent to this key. You can revoke access later in OpenKeychain.</string>
|
||||
<string name="requested_key_unavailable_warning">This key is not available. To use it, you must import it as one of your own!</string>
|
||||
<string name="button_allow">Allow</string>
|
||||
<string name="button_cancel">Cancel</string>
|
||||
<string name="requested_key_label">Requested key:</string>
|
||||
</resources>
|
||||
|
|
|
@ -22,6 +22,17 @@
|
|||
<item name="android:textColor">@color/card_view_button</item>
|
||||
</style>
|
||||
|
||||
<style name="BorderlessButton">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_centerVertical">true</item>
|
||||
<item name="android:background">?android:attr/selectableItemBackground</item>
|
||||
<item name="android:minHeight">0dp</item>
|
||||
<item name="android:minWidth">0dp</item>
|
||||
<item name="android:padding">8dp</item>
|
||||
<item name="android:textColor">@color/card_view_button</item>
|
||||
</style>
|
||||
|
||||
<style name="SectionHeader">
|
||||
<item name="android:drawableBottom">?attr/sectionHeaderDrawable</item>
|
||||
<item name="android:drawablePadding">4dp</item>
|
||||
|
|
Loading…
Reference in a new issue