aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 13:40:24 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 13:40:24 +0100
commitacad2ba95723a940467e89a07e91498188a88745 (patch)
treeaf2eac0d330c9995f9c64e98116ed2d84493dcd6 /OpenPGP-Keychain
parentee2fec17597c35ad2329f44cc697e18e3e4169cc (diff)
downloadopen-keychain-acad2ba95723a940467e89a07e91498188a88745.tar.gz
open-keychain-acad2ba95723a940467e89a07e91498188a88745.tar.bz2
open-keychain-acad2ba95723a940467e89a07e91498188a88745.zip
PendingIntent to handle user input
Diffstat (limited to 'OpenPGP-Keychain')
-rw-r--r--OpenPGP-Keychain/src/main/AndroidManifest.xml7
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java2
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java79
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java60
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java2
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java2
-rw-r--r--OpenPGP-Keychain/src/main/res/values/strings.xml2
7 files changed, 94 insertions, 60 deletions
diff --git a/OpenPGP-Keychain/src/main/AndroidManifest.xml b/OpenPGP-Keychain/src/main/AndroidManifest.xml
index 45b034b97..ba2bd5571 100644
--- a/OpenPGP-Keychain/src/main/AndroidManifest.xml
+++ b/OpenPGP-Keychain/src/main/AndroidManifest.xml
@@ -362,10 +362,9 @@
<activity
android:name="org.sufficientlysecure.keychain.service.remote.RemoteServiceActivity"
android:exported="false"
- android:label="@string/app_name"
- android:launchMode="singleTop"
- android:process=":remote_api"
- android:taskAffinity=":remote_api" />
+ android:label="@string/app_name" />
+ <!--android:launchMode="singleTop"-->
+ <!--android:process=":remote_api"-->
<activity
android:name="org.sufficientlysecure.keychain.service.remote.RegisteredAppsListActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index 870e45ea5..1de9ab985 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -235,7 +235,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
String action = intent.getAction();
- // execute action from extra bundle
+ // executeServiceMethod action from extra bundle
if (ACTION_ENCRYPT_SIGN.equals(action)) {
try {
/* Input */
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java
index 006754bae..4bc5a90ac 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java
@@ -50,6 +50,8 @@ import org.sufficientlysecure.keychain.service.exception.WrongPassphraseExceptio
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log;
+import android.app.PendingIntent;
+import android.content.ComponentName;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
@@ -308,8 +310,20 @@ public class OpenPgpService extends RemoteService {
String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId());
if (passphrase == null) {
// TODO: we need to abort and return a passphrase Intent!
+
+ Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class);
+ // TODO: setComponent really needed for security?
+// intent.setComponent(new ComponentName(Constants.PACKAGE_NAME,
+// "org.sufficientlysecure.keychain.service.remote.RemoteServiceActivity"));
+// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setAction(RemoteServiceActivity.ACTION_CACHE_PASSPHRASE);
+ intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, appSettings.getKeyId());
+ PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 42, intent, 0);
+
+
Bundle result = new Bundle();
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED);
+ result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
return result;
}
@@ -328,19 +342,19 @@ public class OpenPgpService extends RemoteService {
is.close();
os.close();
- } catch (IOException e) {
- Log.e(Constants.TAG, "Fail", e);
+// } catch (IOException e) {
+// Log.e(Constants.TAG, "Fail", e);
} finally {
- try {
+// try {
is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
+// try {
os.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
}
Bundle result = new Bundle();
@@ -516,27 +530,42 @@ public class OpenPgpService extends RemoteService {
}
}
+ /**
+ * Checks that params != null and API version fits
+ *
+ * @param params
+ * @return
+ */
+ private Bundle validateParamsAndVersion(Bundle params) {
+ if (params == null) {
+ Bundle result = new Bundle();
+ OpenPgpError error = new OpenPgpError(OpenPgpError.GENERIC_ERROR, "params Bundle required!");
+ result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
+ return result;
+ }
+
+ if (params.getInt(OpenPgpConstants.PARAMS_API_VERSION) != OpenPgpConstants.API_VERSION) {
+ // not compatible!
+ Bundle result = new Bundle();
+ OpenPgpError error = new OpenPgpError(OpenPgpError.INCOMPATIBLE_API_VERSIONS, "Incompatible API versions!");
+ result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
+ return result;
+ }
+
+ return null;
+ }
+
private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() {
@Override
public Bundle sign(Bundle params, final ParcelFileDescriptor input, final ParcelFileDescriptor output) {
final AppSettings appSettings = getAppSettings();
- if (params == null) {
- Bundle result = new Bundle();
- OpenPgpError error = new OpenPgpError(OpenPgpError.GENERIC_ERROR, "params Bundle required!");
- result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
- result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
- return result;
- }
-
- if (params.getInt(OpenPgpConstants.PARAMS_API_VERSION) != OpenPgpConstants.API_VERSION) {
- // not compatible!
- Bundle result = new Bundle();
- OpenPgpError error = new OpenPgpError(OpenPgpError.INCOMPATIBLE_API_VERSIONS, "Incompatible API versions!");
- result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
- result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
- return result;
+ Bundle errorResult = validateParamsAndVersion(params);
+ if (errorResult != null) {
+ return errorResult;
}
// Runnable r = new Runnable() {
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java
index 7ab39fce1..9852a2008 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java
@@ -86,15 +86,15 @@ public class RemoteServiceActivity extends ActionBarActivity {
protected void onStop() {
super.onStop();
- if (!finishHandled) {
- Message msg = Message.obtain();
- msg.arg1 = RemoteService.RegisterActivityCallback.CANCEL;
- try {
- mMessenger.send(msg);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoServiceActivity", e);
- }
- }
+// if (!finishHandled) {
+// Message msg = Message.obtain();
+// msg.arg1 = RemoteService.RegisterActivityCallback.CANCEL;
+// try {
+// mMessenger.send(msg);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoServiceActivity", e);
+// }
+// }
}
protected void handleActions(Intent intent, Bundle savedInstanceState) {
@@ -237,7 +237,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
Message msg = Message.obtain();
msg.arg1 = OpenPgpService.SelectPubKeysActivityCallback.CANCEL;
- ;
+
try {
mMessenger.send(msg);
} catch (RemoteException e) {
@@ -313,25 +313,31 @@ public class RemoteServiceActivity extends ActionBarActivity {
@Override
public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
- Message msg = Message.obtain();
- msg.arg1 = OpenPgpService.PassphraseActivityCallback.OKAY;
- try {
- mMessenger.send(msg);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoServiceActivity", e);
- }
+// Message msg = Message.obtain();
+// msg.arg1 = OpenPgpService.PassphraseActivityCallback.OKAY;
+// try {
+// mMessenger.send(msg);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoServiceActivity", e);
+// }
+
+ RemoteServiceActivity.this.setResult(RESULT_OK);
+ RemoteServiceActivity.this.finish();
} else {
- Message msg = Message.obtain();
- msg.arg1 = OpenPgpService.PassphraseActivityCallback.CANCEL;
- try {
- mMessenger.send(msg);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoServiceActivity", e);
- }
+// Message msg = Message.obtain();
+// msg.arg1 = OpenPgpService.PassphraseActivityCallback.CANCEL;
+// try {
+// mMessenger.send(msg);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoServiceActivity", e);
+// }
+
+ RemoteServiceActivity.this.setResult(RESULT_CANCELED);
+ RemoteServiceActivity.this.finish();
}
- finishHandled = true;
- finish();
+// finishHandled = true;
+// finish();
}
};
@@ -346,7 +352,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
} catch (PgpGeneralException e) {
Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!");
// send message to handler to start encryption directly
- returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
+// returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
}
}
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java
index 3dd077d12..b8eed83c9 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java
@@ -300,7 +300,7 @@ public class DecryptActivity extends DrawerActivity {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// handle like normal text decryption, override action and extras to later
- // execute ACTION_DECRYPT in main actions
+ // executeServiceMethod ACTION_DECRYPT in main actions
extras.putString(EXTRA_TEXT, sharedText);
action = ACTION_DECRYPT;
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
index 81446db99..85bfba224 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
@@ -173,7 +173,7 @@ public class EncryptActivity extends DrawerActivity {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// handle like normal text encryption, override action and extras to later
- // execute ACTION_ENCRYPT in main actions
+ // executeServiceMethod ACTION_ENCRYPT in main actions
extras.putString(EXTRA_TEXT, sharedText);
extras.putBoolean(EXTRA_ASCII_ARMOR, true);
action = ACTION_ENCRYPT;
diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml
index 88ad10a0a..2a0b4b6f9 100644
--- a/OpenPGP-Keychain/src/main/res/values/strings.xml
+++ b/OpenPGP-Keychain/src/main/res/values/strings.xml
@@ -383,7 +383,7 @@
<string name="api_settings_revoke">Revoke access</string>
<string name="api_settings_package_name">Package Name</string>
<string name="api_settings_package_signature">SHA-256 of Package Signature</string>
- <string name="api_register_text">The following application requests access to OpenPGP Keychain.\n\nAllow permanent access?</string>
+ <string name="api_register_text">The following application requests access to OpenPGP Keychain.\n\nAllow access (you can revoke it later)?</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>