aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 02:33:21 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 02:33:21 +0100
commit7939aaaa440f84a0df5524f8a1a1c04dd569eedd (patch)
tree5b1db4213863508a48e369271e1a18a283dab206 /OpenPGP-Keychain
parent7b819e65de71a17827a3264a1a8663ca0d30b48c (diff)
downloadopen-keychain-7939aaaa440f84a0df5524f8a1a1c04dd569eedd.tar.gz
open-keychain-7939aaaa440f84a0df5524f8a1a1c04dd569eedd.tar.bz2
open-keychain-7939aaaa440f84a0df5524f8a1a1c04dd569eedd.zip
Introducing new ParcelFileDescriptor pipes
Diffstat (limited to 'OpenPGP-Keychain')
-rw-r--r--OpenPGP-Keychain/build.gradle2
-rw-r--r--OpenPGP-Keychain/src/main/AndroidManifest.xml2
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java280
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java4
4 files changed, 176 insertions, 112 deletions
diff --git a/OpenPGP-Keychain/build.gradle b/OpenPGP-Keychain/build.gradle
index 66c6a0e8f..28e8c37b1 100644
--- a/OpenPGP-Keychain/build.gradle
+++ b/OpenPGP-Keychain/build.gradle
@@ -20,7 +20,7 @@ android {
buildToolsVersion "19.0.1"
defaultConfig {
- minSdkVersion 8
+ minSdkVersion 9
targetSdkVersion 19
}
diff --git a/OpenPGP-Keychain/src/main/AndroidManifest.xml b/OpenPGP-Keychain/src/main/AndroidManifest.xml
index 6de35571f..45b034b97 100644
--- a/OpenPGP-Keychain/src/main/AndroidManifest.xml
+++ b/OpenPGP-Keychain/src/main/AndroidManifest.xml
@@ -30,7 +30,7 @@
-->
<uses-sdk
- android:minSdkVersion="8"
+ android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-feature
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 6db091ed0..9cdb12eda 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
@@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.service.remote;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -30,6 +31,7 @@ import org.openintents.openpgp.IOpenPgpService;
import org.openintents.openpgp.OpenPgpData;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult;
+import org.openintents.openpgp.util.OpenPgpConstants;
import org.spongycastle.util.Arrays;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
@@ -54,7 +56,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
-import android.os.RemoteException;
+import android.os.ParcelFileDescriptor;
public class OpenPgpService extends RemoteService {
@@ -93,6 +95,7 @@ public class OpenPgpService extends RemoteService {
return passphrase;
}
+
public class PassphraseActivityCallback extends UserInputCallback {
private boolean success = false;
@@ -109,11 +112,13 @@ public class OpenPgpService extends RemoteService {
success = false;
}
}
- };
+ }
+
+ ;
/**
* Search database for key ids based on emails.
- *
+ *
* @param encryptionUserIds
* @return
*/
@@ -213,10 +218,12 @@ public class OpenPgpService extends RemoteService {
success = false;
}
}
- };
+ }
+
+ ;
private synchronized void getKeyIdsSafe(String[] userIds, boolean allowUserInteraction,
- IOpenPgpKeyIdsCallback callback, AppSettings appSettings) {
+ IOpenPgpKeyIdsCallback callback, AppSettings appSettings) {
try {
long[] keyIds = getKeyIdsFromEmails(userIds, allowUserInteraction);
if (keyIds == null) {
@@ -225,7 +232,7 @@ public class OpenPgpService extends RemoteService {
callback.onSuccess(keyIds);
} catch (UserInteractionRequiredException e) {
- callbackOpenPgpError(callback, OpenPgpError.USER_INTERACTION_REQUIRED, e.getMessage());
+// callbackOpenPgpError(callback, OpenPgpError.USER_INTERACTION_REQUIRED, e.getMessage());
} catch (NoUserIdsException e) {
callbackOpenPgpError(callback, OpenPgpError.NO_USER_IDS, e.getMessage());
} catch (Exception e) {
@@ -234,8 +241,8 @@ public class OpenPgpService extends RemoteService {
}
private synchronized void encryptAndSignSafe(OpenPgpData inputData,
- final OpenPgpData outputData, long[] keyIds, boolean allowUserInteraction,
- IOpenPgpCallback callback, AppSettings appSettings, boolean sign) {
+ final OpenPgpData outputData, long[] keyIds, boolean allowUserInteraction,
+ IOpenPgpCallback callback, AppSettings appSettings, boolean sign) {
try {
// TODO: other options of OpenPgpData!
byte[] inputBytes = getInput(inputData);
@@ -286,7 +293,7 @@ public class OpenPgpService extends RemoteService {
// return over handler on client side
callback.onSuccess(output, null);
} catch (UserInteractionRequiredException e) {
- callbackOpenPgpError(callback, OpenPgpError.USER_INTERACTION_REQUIRED, e.getMessage());
+// callbackOpenPgpError(callback, OpenPgpError.USER_INTERACTION_REQUIRED, e.getMessage());
} catch (WrongPassphraseException e) {
callbackOpenPgpError(callback, OpenPgpError.NO_OR_WRONG_PASSPHRASE, e.getMessage());
} catch (Exception e) {
@@ -295,43 +302,61 @@ public class OpenPgpService extends RemoteService {
}
// TODO: asciiArmor?!
- private void signSafe(byte[] inputBytes, boolean allowUserInteraction,
- IOpenPgpCallback callback, AppSettings appSettings) {
+ private Bundle signImpl(ParcelFileDescriptor input, ParcelFileDescriptor output, AppSettings appSettings) {
try {
- // build InputData and write into OutputStream
- InputStream inputStream = new ByteArrayInputStream(inputBytes);
- long inputLength = inputBytes.length;
- InputData inputData = new InputData(inputStream, inputLength);
-
- OutputStream outputStream = new ByteArrayOutputStream();
-
- String passphrase = getCachedPassphrase(appSettings.getKeyId(), allowUserInteraction);
+ // get passphrase from cache, if key has "no" passphrase, this returns an empty String
+ String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId());
if (passphrase == null) {
- throw new WrongPassphraseException("No or wrong passphrase!");
- }
+ // TODO: we need to abort and return a passphrase Intent!
+ Bundle result = new Bundle();
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED);
- PgpOperation operation = new PgpOperation(getContext(), null, inputData, outputStream);
- operation.signText(appSettings.getKeyId(), passphrase, appSettings.getHashAlgorithm(),
- Preferences.getPreferences(this).getForceV3Signatures());
-
- outputStream.close();
+ return result;
+ }
- byte[] outputBytes = ((ByteArrayOutputStream) outputStream).toByteArray();
- OpenPgpData output = new OpenPgpData(new String(outputBytes));
+ // INPUT
+ InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
+ // OUTPUT
+ OutputStream os = new ParcelFileDescriptor.AutoCloseOutputStream(output);
+ try {
+ long inputLength = is.available();
+ InputData inputData = new InputData(is, inputLength);
+
+ PgpOperation operation = new PgpOperation(getContext(), null, inputData, os);
+ operation.signText(appSettings.getKeyId(), passphrase, appSettings.getHashAlgorithm(),
+ Preferences.getPreferences(this).getForceV3Signatures());
+
+ is.close();
+ os.close();
+ } catch (IOException e) {
+ Log.e(Constants.TAG, "Fail", e);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
- // return over handler on client side
- callback.onSuccess(output, null);
- } catch (UserInteractionRequiredException e) {
- callbackOpenPgpError(callback, OpenPgpError.USER_INTERACTION_REQUIRED, e.getMessage());
- } catch (WrongPassphraseException e) {
- callbackOpenPgpError(callback, OpenPgpError.NO_OR_WRONG_PASSPHRASE, e.getMessage());
+ Bundle result = new Bundle();
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_SUCCESS);
+ return result;
} catch (Exception e) {
- callbackOpenPgpError(callback, OpenPgpError.GENERIC_ERROR, e.getMessage());
+ Bundle result = new Bundle();
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
+ result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
+ new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
+ return result;
}
}
private synchronized void decryptAndVerifySafe(byte[] inputBytes, boolean allowUserInteraction,
- IOpenPgpCallback callback, AppSettings appSettings) {
+ IOpenPgpCallback callback, AppSettings appSettings) {
try {
// TODO: this is not really needed
// checked if it is text with BEGIN and END tags
@@ -458,7 +483,7 @@ public class OpenPgpService extends RemoteService {
// return over handler on client side
callback.onSuccess(output, sigResult);
} catch (UserInteractionRequiredException e) {
- callbackOpenPgpError(callback, OpenPgpError.USER_INTERACTION_REQUIRED, e.getMessage());
+// callbackOpenPgpError(callback, OpenPgpError.USER_INTERACTION_REQUIRED, e.getMessage());
} catch (WrongPassphraseException e) {
callbackOpenPgpError(callback, OpenPgpError.NO_OR_WRONG_PASSPHRASE, e.getMessage());
} catch (Exception e) {
@@ -468,7 +493,7 @@ public class OpenPgpService extends RemoteService {
/**
* Returns error to IOpenPgpCallback
- *
+ *
* @param callback
* @param errorId
* @param message
@@ -494,82 +519,125 @@ public class OpenPgpService extends RemoteService {
private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() {
@Override
- public void encrypt(final OpenPgpData input, final OpenPgpData output, final long[] keyIds,
- final IOpenPgpCallback callback) throws RemoteException {
- final AppSettings settings = getAppSettings();
-
- Runnable r = new Runnable() {
- @Override
- public void run() {
- encryptAndSignSafe(input, output, keyIds, true, callback, settings, false);
- }
- };
+ public Bundle sign(Bundle params, final ParcelFileDescriptor input, final ParcelFileDescriptor output) {
+ final AppSettings appSettings = getAppSettings();
+
+ Bundle result = new Bundle();
+ if (params.getInt(OpenPgpConstants.PARAMS_API_VERSION) != OpenPgpConstants.API_VERSION) {
+ // not compatible!
+ 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;
+ }
- checkAndEnqueue(r);
- }
+// Runnable r = new Runnable() {
+// @Override
+// public void run() {
+ return signImpl(input, output, appSettings);
+// }
+// };
- @Override
- public void signAndEncrypt(final OpenPgpData input, final OpenPgpData output,
- final long[] keyIds, final IOpenPgpCallback callback) throws RemoteException {
- final AppSettings settings = getAppSettings();
-
- Runnable r = new Runnable() {
- @Override
- public void run() {
- encryptAndSignSafe(input, output, keyIds, true, callback, settings, true);
- }
- };
+// checkAndEnqueue(r);
- checkAndEnqueue(r);
+// return null;
}
@Override
- public void sign(final OpenPgpData input, final OpenPgpData output,
- final IOpenPgpCallback callback) throws RemoteException {
- final AppSettings settings = getAppSettings();
-
- Runnable r = new Runnable() {
- @Override
- public void run() {
- signSafe(getInput(input), true, callback, settings);
- }
- };
+ public Bundle encrypt(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output) {
- checkAndEnqueue(r);
+ return null;
}
@Override
- public void decryptAndVerify(final OpenPgpData input, final OpenPgpData output,
- final IOpenPgpCallback callback) throws RemoteException {
-
- final AppSettings settings = getAppSettings();
-
- Runnable r = new Runnable() {
- @Override
- public void run() {
- decryptAndVerifySafe(getInput(input), true, callback, settings);
- }
- };
+ public Bundle signAndEncrypt(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output) {
- checkAndEnqueue(r);
+ return null;
}
@Override
- public void getKeyIds(final String[] userIds, final boolean allowUserInteraction,
- final IOpenPgpKeyIdsCallback callback) throws RemoteException {
-
- final AppSettings settings = getAppSettings();
-
- Runnable r = new Runnable() {
- @Override
- public void run() {
- getKeyIdsSafe(userIds, allowUserInteraction, callback, settings);
- }
- };
+ public Bundle decryptAndVerify(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output) {
- checkAndEnqueue(r);
+ return null;
}
+// @Override
+// public void encrypt(final OpenPgpData input, final OpenPgpData output, final long[] keyIds,
+// final IOpenPgpCallback callback) throws RemoteException {
+// final AppSettings settings = getAppSettings();
+//
+// Runnable r = new Runnable() {
+// @Override
+// public void run() {
+// encryptAndSignSafe(input, output, keyIds, true, callback, settings, false);
+// }
+// };
+//
+// checkAndEnqueue(r);
+// }
+//
+// @Override
+// public void signAndEncrypt(final OpenPgpData input, final OpenPgpData output,
+// final long[] keyIds, final IOpenPgpCallback callback) throws RemoteException {
+// final AppSettings settings = getAppSettings();
+//
+// Runnable r = new Runnable() {
+// @Override
+// public void run() {
+// encryptAndSignSafe(input, output, keyIds, true, callback, settings, true);
+// }
+// };
+//
+// checkAndEnqueue(r);
+// }
+//
+// @Override
+// public void sign(final OpenPgpData input, final OpenPgpData output,
+// final IOpenPgpCallback callback) throws RemoteException {
+// final AppSettings settings = getAppSettings();
+//
+// Runnable r = new Runnable() {
+// @Override
+// public void run() {
+// signImpl(getInput(input), true, callback, settings);
+// }
+// };
+//
+// checkAndEnqueue(r);
+// }
+//
+// @Override
+// public void decryptAndVerify(final OpenPgpData input, final OpenPgpData output,
+// final IOpenPgpCallback callback) throws RemoteException {
+//
+// final AppSettings settings = getAppSettings();
+//
+// Runnable r = new Runnable() {
+// @Override
+// public void run() {
+// decryptAndVerifySafe(getInput(input), true, callback, settings);
+// }
+// };
+//
+// checkAndEnqueue(r);
+// }
+//
+// @Override
+// public void getKeyIds(final String[] userIds, final boolean allowUserInteraction,
+// final IOpenPgpKeyIdsCallback callback) throws RemoteException {
+//
+// final AppSettings settings = getAppSettings();
+//
+// Runnable r = new Runnable() {
+// @Override
+// public void run() {
+// getKeyIdsSafe(userIds, allowUserInteraction, callback, settings);
+// }
+// };
+//
+// checkAndEnqueue(r);
+// }
+
};
private static byte[] getInput(OpenPgpData data) {
@@ -577,17 +645,17 @@ public class OpenPgpService extends RemoteService {
byte[] inBytes = null;
switch (data.getType()) {
- case OpenPgpData.TYPE_STRING:
- inBytes = data.getString().getBytes();
- break;
+ case OpenPgpData.TYPE_STRING:
+ inBytes = data.getString().getBytes();
+ break;
- case OpenPgpData.TYPE_BYTE_ARRAY:
- inBytes = data.getBytes();
- break;
+ case OpenPgpData.TYPE_BYTE_ARRAY:
+ inBytes = data.getBytes();
+ break;
- default:
- Log.e(Constants.TAG, "Uri and ParcelFileDescriptor not supported right now!");
- break;
+ default:
+ Log.e(Constants.TAG, "Uri and ParcelFileDescriptor not supported right now!");
+ break;
}
return inBytes;
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java
index bc513d532..ddc704c01 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java
@@ -162,10 +162,6 @@ public abstract class RemoteService extends Service {
/**
* Locks current thread and pauses execution of runnables and starts activity for user input
- *
- * @param action
- * @param messenger
- * @param extras
*/
protected void pauseAndStartUserInteraction(String action, BaseCallback callback, Bundle extras) {
synchronized (userInputLock) {