aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--OpenPGP-Keychain-API/example-app/build.gradle3
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml2
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java332
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml2
-rw-r--r--OpenPGP-Keychain-API/gradle/wrapper/gradle-wrapper.properties4
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/build.gradle1
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/AndroidManifest.xml2
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl2
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl46
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl2
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl2
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java10
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java11
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java2
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java83
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java48
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java (renamed from libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java)14
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java (renamed from libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java)4
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java (renamed from libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java)8
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java104
-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
-rw-r--r--libraries/keychain-api-library/build.gradle12
-rw-r--r--libraries/keychain-api-library/src/main/AndroidManifest.xml2
-rw-r--r--libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl2
-rw-r--r--libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl46
-rw-r--r--libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl2
-rw-r--r--libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl2
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java10
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java11
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java2
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java83
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java48
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java (renamed from OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java)14
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java (renamed from OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java)4
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java (renamed from OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java)8
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java104
39 files changed, 958 insertions, 362 deletions
diff --git a/OpenPGP-Keychain-API/example-app/build.gradle b/OpenPGP-Keychain-API/example-app/build.gradle
index 99a09f094..373f83690 100644
--- a/OpenPGP-Keychain-API/example-app/build.gradle
+++ b/OpenPGP-Keychain-API/example-app/build.gradle
@@ -1,3 +1,4 @@
+// please leave this here, so this library builds on its own
buildscript {
repositories {
mavenCentral()
@@ -20,7 +21,7 @@ android {
buildToolsVersion "19.0.1"
defaultConfig {
- minSdkVersion 8
+ minSdkVersion 9
targetSdkVersion 19
}
diff --git a/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml b/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
index 8b8c43776..39a990f72 100644
--- a/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
+++ b/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
@@ -5,7 +5,7 @@
android:versionName="1.1" >
<uses-sdk
- android:minSdkVersion="8"
+ android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
index 4a96de5a1..81f9eee68 100644
--- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
@@ -16,17 +16,6 @@
package org.sufficientlysecure.keychain.demo;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openintents.openpgp.IOpenPgpKeyIdsCallback;
-import org.openintents.openpgp.OpenPgpData;
-import org.openintents.openpgp.OpenPgpError;
-import org.openintents.openpgp.OpenPgpServiceConnection;
-import org.openintents.openpgp.OpenPgpSignatureResult;
-import org.openintents.openpgp.IOpenPgpCallback;
-import org.openintents.openpgp.IOpenPgpService;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
@@ -34,7 +23,6 @@ import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -44,6 +32,19 @@ import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
+import org.openintents.openpgp.IOpenPgpService;
+import org.openintents.openpgp.OpenPgpError;
+import org.openintents.openpgp.util.OpenPgpApi;
+import org.openintents.openpgp.util.OpenPgpConstants;
+import org.openintents.openpgp.util.OpenPgpServiceConnection;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
public class OpenPgpProviderActivity extends Activity {
Activity mActivity;
@@ -67,123 +68,123 @@ public class OpenPgpProviderActivity extends Activity {
selectCryptoProvider();
}
- /**
- * Callback from remote openpgp service
- */
- final IOpenPgpKeyIdsCallback.Stub getKeysEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
-
- @Override
- public void onSuccess(final long[] keyIds) throws RemoteException {
- Log.d(Constants.TAG, "getKeysEncryptCallback keyId " + keyIds[0]);
- mActivity.runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- // encrypt after getting key ids
- String inputStr = mMessage.getText().toString();
- OpenPgpData input = new OpenPgpData(inputStr);
-
- Log.d(Constants.TAG, "getKeysEncryptCallback inputStr " + inputStr);
-
- try {
- mCryptoServiceConnection.getService().encrypt(input,
- new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoProviderDemo", e);
- }
- }
- });
- }
-
- @Override
- public void onError(OpenPgpError error) throws RemoteException {
- handleError(error);
- }
-
- };
-
- final IOpenPgpKeyIdsCallback.Stub getKeysSignAndEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
-
- @Override
- public void onSuccess(final long[] keyIds) throws RemoteException {
- Log.d(Constants.TAG, "getKeysSignAndEncryptCallback keyId " + keyIds[0]);
-
- mActivity.runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- // encrypt after getting key ids
- String inputStr = mMessage.getText().toString();
- OpenPgpData input = new OpenPgpData(inputStr);
-
- try {
- mCryptoServiceConnection.getService().signAndEncrypt(input,
- new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoProviderDemo", e);
- }
- }
- });
- }
-
- @Override
- public void onError(OpenPgpError error) throws RemoteException {
- handleError(error);
- }
-
- };
-
- final IOpenPgpCallback.Stub encryptCallback = new IOpenPgpCallback.Stub() {
-
- @Override
- public void onSuccess(final OpenPgpData output, OpenPgpSignatureResult signatureResult)
- throws RemoteException {
- Log.d(Constants.TAG, "encryptCallback");
-
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- mCiphertext.setText(output.getString());
- }
- });
- }
-
- @Override
- public void onError(OpenPgpError error) throws RemoteException {
- handleError(error);
- }
-
- };
-
- final IOpenPgpCallback.Stub decryptAndVerifyCallback = new IOpenPgpCallback.Stub() {
-
- @Override
- public void onSuccess(final OpenPgpData output, final OpenPgpSignatureResult signatureResult)
- throws RemoteException {
- Log.d(Constants.TAG, "decryptAndVerifyCallback");
-
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- mMessage.setText(output.getString());
- if (signatureResult != null) {
- Toast.makeText(OpenPgpProviderActivity.this,
- "signature result:\n" + signatureResult.toString(),
- Toast.LENGTH_LONG).show();
- }
- }
- });
-
- }
-
- @Override
- public void onError(OpenPgpError error) throws RemoteException {
- handleError(error);
- }
-
- };
+// /**
+// * Callback from remote openpgp service
+// */
+// final IOpenPgpKeyIdsCallback.Stub getKeysEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
+//
+// @Override
+// public void onSuccess(final long[] keyIds) throws RemoteException {
+// Log.d(Constants.TAG, "getKeysEncryptCallback keyId " + keyIds[0]);
+// mActivity.runOnUiThread(new Runnable() {
+//
+// @Override
+// public void run() {
+// // encrypt after getting key ids
+// String inputStr = mMessage.getText().toString();
+// OpenPgpData input = new OpenPgpData(inputStr);
+//
+// Log.d(Constants.TAG, "getKeysEncryptCallback inputStr " + inputStr);
+//
+// try {
+// mCryptoServiceConnection.getService().encrypt(input,
+// new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoProviderDemo", e);
+// }
+// }
+// });
+// }
+//
+// @Override
+// public void onError(OpenPgpError error) throws RemoteException {
+// handleError(error);
+// }
+//
+// };
+//
+// final IOpenPgpKeyIdsCallback.Stub getKeysSignAndEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
+//
+// @Override
+// public void onSuccess(final long[] keyIds) throws RemoteException {
+// Log.d(Constants.TAG, "getKeysSignAndEncryptCallback keyId " + keyIds[0]);
+//
+// mActivity.runOnUiThread(new Runnable() {
+//
+// @Override
+// public void run() {
+// // encrypt after getting key ids
+// String inputStr = mMessage.getText().toString();
+// OpenPgpData input = new OpenPgpData(inputStr);
+//
+// try {
+// mCryptoServiceConnection.getService().signAndEncrypt(input,
+// new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoProviderDemo", e);
+// }
+// }
+// });
+// }
+//
+// @Override
+// public void onError(OpenPgpError error) throws RemoteException {
+// handleError(error);
+// }
+//
+// };
+//
+// final IOpenPgpCallback.Stub encryptCallback = new IOpenPgpCallback.Stub() {
+//
+// @Override
+// public void onSuccess(final OpenPgpData output, OpenPgpSignatureResult signatureResult)
+// throws RemoteException {
+// Log.d(Constants.TAG, "encryptCallback");
+//
+// runOnUiThread(new Runnable() {
+//
+// @Override
+// public void run() {
+// mCiphertext.setText(output.getString());
+// }
+// });
+// }
+//
+// @Override
+// public void onError(OpenPgpError error) throws RemoteException {
+// handleError(error);
+// }
+//
+// };
+//
+// final IOpenPgpCallback.Stub decryptAndVerifyCallback = new IOpenPgpCallback.Stub() {
+//
+// @Override
+// public void onSuccess(final OpenPgpData output, final OpenPgpSignatureResult signatureResult)
+// throws RemoteException {
+// Log.d(Constants.TAG, "decryptAndVerifyCallback");
+//
+// runOnUiThread(new Runnable() {
+//
+// @Override
+// public void run() {
+// mMessage.setText(output.getString());
+// if (signatureResult != null) {
+// Toast.makeText(OpenPgpProviderActivity.this,
+// "signature result:\n" + signatureResult.toString(),
+// Toast.LENGTH_LONG).show();
+// }
+// }
+// });
+//
+// }
+//
+// @Override
+// public void onError(OpenPgpError error) throws RemoteException {
+// handleError(error);
+// }
+//
+// };
private void handleError(final OpenPgpError error) {
mActivity.runOnUiThread(new Runnable() {
@@ -200,46 +201,61 @@ public class OpenPgpProviderActivity extends Activity {
}
public void encryptOnClick(View view) {
- try {
- mCryptoServiceConnection.getService().getKeyIds(
- mEncryptUserIds.getText().toString().split(","), true, getKeysEncryptCallback);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoProviderDemo", e);
- }
+// try {
+// mCryptoServiceConnection.getService().getKeyIds(
+// mEncryptUserIds.getText().toString().split(","), true, getKeysEncryptCallback);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoProviderDemo", e);
+// }
}
public void signOnClick(View view) {
- String inputStr = mMessage.getText().toString();
- OpenPgpData input = new OpenPgpData(inputStr);
-
try {
- mCryptoServiceConnection.getService().sign(input,
- new OpenPgpData(OpenPgpData.TYPE_STRING), encryptCallback);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoProviderDemo", e);
+ String inputStr = mMessage.getText().toString();
+ InputStream is = new ByteArrayInputStream(inputStr.getBytes("UTF-8"));
+
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ OpenPgpApi api = new OpenPgpApi(mCryptoServiceConnection.getService());
+ api.sign(is, os);
+
+ Log.d(OpenPgpConstants.TAG, "Test #1 read result: " + os.toByteArray().length
+ + " str=" + os.toString("UTF-8"));
+
+ mCiphertext.setText(os.toString("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
}
+// OpenPgpData input = new OpenPgpData(inputStr);
+//
+// try {
+// mCryptoServiceConnection.getService().sign(input,
+// new OpenPgpData(OpenPgpData.TYPE_STRING), encryptCallback);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoProviderDemo", e);
+// }
}
public void signAndEncryptOnClick(View view) {
- try {
- mCryptoServiceConnection.getService().getKeyIds(
- mEncryptUserIds.getText().toString().split(","), true,
- getKeysSignAndEncryptCallback);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoProviderDemo", e);
- }
+// try {
+// mCryptoServiceConnection.getService().getKeyIds(
+// mEncryptUserIds.getText().toString().split(","), true,
+// getKeysSignAndEncryptCallback);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoProviderDemo", e);
+// }
}
public void decryptAndVerifyOnClick(View view) {
- String inputStr = mCiphertext.getText().toString();
- OpenPgpData input = new OpenPgpData(inputStr);
-
- try {
- mCryptoServiceConnection.getService().decryptAndVerify(input,
- new OpenPgpData(OpenPgpData.TYPE_STRING), decryptAndVerifyCallback);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "CryptoProviderDemo", e);
- }
+// String inputStr = mCiphertext.getText().toString();
+// OpenPgpData input = new OpenPgpData(inputStr);
+//
+// try {
+// mCryptoServiceConnection.getService().decryptAndVerify(input,
+// new OpenPgpData(OpenPgpData.TYPE_STRING), decryptAndVerifyCallback);
+// } catch (RemoteException e) {
+// Log.e(Constants.TAG, "CryptoProviderDemo", e);
+// }
}
@Override
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml b/OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml
index 5febfad44..86b461742 100644
--- a/OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml
@@ -12,7 +12,7 @@
<!-- android:title="AIDL Demo (ACCESS_KEYS permission)" /> -->
<!-- </PreferenceCategory> -->
<PreferenceCategory android:title="OpenPGP Provider" >
- <org.openintents.openpgp.OpenPgpListPreference
+ <org.openintents.openpgp.util.OpenPgpListPreference
android:key="openpgp_provider_list"
android:title="Select OpenPGP Provider!" />
<Preference
diff --git a/OpenPGP-Keychain-API/gradle/wrapper/gradle-wrapper.properties b/OpenPGP-Keychain-API/gradle/wrapper/gradle-wrapper.properties
index 425cd64c7..932184188 100644
--- a/OpenPGP-Keychain-API/gradle/wrapper/gradle-wrapper.properties
+++ b/OpenPGP-Keychain-API/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Sun Feb 09 19:10:32 CET 2014
+#Fri Feb 14 01:26:40 CET 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/build.gradle b/OpenPGP-Keychain-API/libraries/keychain-api-library/build.gradle
index 2eacd2065..f9da72cb8 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/build.gradle
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/build.gradle
@@ -1,3 +1,4 @@
+// please leave this here, so this library builds on its own
buildscript {
repositories {
mavenCentral()
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/AndroidManifest.xml b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/AndroidManifest.xml
index 32b4a82e5..768922c22 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/AndroidManifest.xml
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/AndroidManifest.xml
@@ -5,7 +5,7 @@
android:versionName="1.0" >
<uses-sdk
- android:minSdkVersion="8"
+ android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application/>
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl
index 4ca356fad..f9b5fc453 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl
index 8f9e8a0fd..ef390a7f6 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,36 @@ import org.openintents.openpgp.OpenPgpData;
import org.openintents.openpgp.IOpenPgpCallback;
import org.openintents.openpgp.IOpenPgpKeyIdsCallback;
-/**
- * All methods are oneway, which means they are asynchronous and non-blocking.
- * Results are returned to the callback, which has to be implemented on client side.
- */
interface IOpenPgpService {
/**
+ * Bundle params:
+ * api_version 1,2,3,... (current: 1)
+ * ascii_armor true/false (for output)
+ * key_ids long[] (for encrypt method)
+ *
+ *
+ * Bundle return:
+ * result_code RESULT_ERROR=0 (see error), RESULT_OK=1, RESULT_USER_INTERACTION_REQUIRED=2 (execute intent and do it again with params from intent)
+ * signature_result OpenPgpSignatureResult
+ * error OpenPgpError
+ * intent Intent
+ *
+ */
+
+ Bundle sign(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+ Bundle encrypt(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+ Bundle signAndEncrypt(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+ Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+
+/*
+ ------------------OLD--------------------------
+*/
+ /**
* Sign
*
* After successful signing, callback's onSuccess will contain the resulting output.
@@ -48,8 +71,9 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void sign(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
-
+ //oneway void sign(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
+
+
/**
* Encrypt
*
@@ -74,7 +98,7 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void encrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
+ //oneway void encrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
/**
* Sign then encrypt
@@ -100,7 +124,7 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void signAndEncrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
+ //oneway void signAndEncrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
/**
* Decrypts and verifies given input bytes. This methods handles encrypted-only, signed-and-encrypted,
@@ -126,7 +150,7 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void decryptAndVerify(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
+ //oneway void decryptAndVerify(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
/**
* Get available key ids based on given user ids
@@ -138,6 +162,6 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results (different type than callback in other functions!)
*/
- oneway void getKeyIds(in String[] ids, in boolean allowUserInteraction, in IOpenPgpKeyIdsCallback callback);
+ //oneway void getKeyIds(in String[] ids, in boolean allowUserInteraction, in IOpenPgpKeyIdsCallback callback);
} \ No newline at end of file
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
index 7a6bed1e6..7f867653d 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
index e246792d0..d1d138b30 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java
deleted file mode 100644
index b1ca1bfe6..000000000
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.openintents.openpgp;
-
-public class OpenPgpConstants {
-
- public static final String TAG = "OpenPgp API";
-
- public static final int REQUIRED_API_VERSION = 1;
- public static final String SERVICE_INTENT = "org.openintents.openpgp.IOpenPgpService";
-
-}
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java
index f108d3169..4dd2cc641 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,13 @@ import android.os.Parcel;
import android.os.Parcelable;
public class OpenPgpError implements Parcelable {
+ public static final int CLIENT_SIDE_ERROR = -1;
+
public static final int GENERIC_ERROR = 0;
- public static final int NO_OR_WRONG_PASSPHRASE = 1;
- public static final int NO_USER_IDS = 2;
- public static final int USER_INTERACTION_REQUIRED = 3;
+ public static final int INCOMPATIBLE_API_VERSIONS = 1;
+
+ public static final int NO_OR_WRONG_PASSPHRASE = 2;
+ public static final int NO_USER_IDS = 3;
int errorId;
String message;
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
index 829f8f8cf..226eeacc2 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java
new file mode 100644
index 000000000..6efb507c4
--- /dev/null
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp.util;
+
+import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.util.Log;
+
+import org.openintents.openpgp.IOpenPgpService;
+import org.openintents.openpgp.OpenPgpError;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class OpenPgpApi {
+
+ IOpenPgpService mService;
+
+ public OpenPgpApi(IOpenPgpService service) {
+ this.mService = service;
+ }
+
+ public Bundle sign(InputStream is, final OutputStream os) {
+ try {
+ // send the input and output pfds
+ ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is,
+ new ParcelFileDescriptorUtil.IThreadListener() {
+
+ @Override
+ public void onThreadFinished(Thread thread) {
+ Log.d(OpenPgpConstants.TAG, "Copy to service finished");
+ }
+ });
+ ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os,
+ new ParcelFileDescriptorUtil.IThreadListener() {
+
+ @Override
+ public void onThreadFinished(Thread thread) {
+ Log.d(OpenPgpConstants.TAG, "Service finished writing!");
+ }
+ });
+
+ // blocks until result is ready
+ Bundle result = mService.sign(null, input, output);
+ // close() is required to halt the TransferThread
+ output.close();
+
+ return result;
+ } catch (RemoteException e) {
+ Log.e(OpenPgpConstants.TAG, "RemoteException", e);
+ Bundle result = new Bundle();
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
+ result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
+ new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
+ return result;
+ } catch (IOException e) {
+ Log.e(OpenPgpConstants.TAG, "IOException", e);
+ Bundle result = new Bundle();
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
+ result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
+ new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
+ return result;
+ }
+ }
+
+
+}
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java
new file mode 100644
index 000000000..3dd9391d0
--- /dev/null
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp.util;
+
+public class OpenPgpConstants {
+
+ public static final String TAG = "OpenPgp API";
+
+ public static final int API_VERSION = 1;
+ public static final String SERVICE_INTENT = "org.openintents.openpgp.IOpenPgpService";
+
+
+ /* Bundle params */
+ public static final String PARAMS_API_VERSION = "api_version";
+ // request ASCII Armor for output
+ // OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
+ public static final String PARAMS_REQUEST_ASCII_ARMOR = "ascii_armor";
+ // (for encrypt method)
+ public static final String PARAMS_KEY_IDS = "key_ids";
+
+ /* Bundle return */
+ public static final String RESULT_CODE = "result_code";
+ public static final String RESULT_SIGNATURE = "signature";
+ public static final String RESULT_ERRORS = "error";
+ public static final String RESULT_INTENT = "intent";
+
+ // get actual error object from RESULT_ERRORS
+ public static final int RESULT_CODE_ERROR = 0;
+ // success!
+ public static final int RESULT_CODE_SUCCESS = 1;
+ // execute intent and do it again with params from intent
+ public static final int RESULT_CODE_USER_INTERACTION_REQUIRED = 2;
+
+}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
index 4ddd97485..ea287a7a9 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openintents.openpgp;
+package org.openintents.openpgp.util;
import java.util.ArrayList;
import java.util.List;
@@ -70,13 +70,13 @@ public class OpenPgpListPreference extends DialogPreference {
/**
* Can be used to add "no selection"
- *
+ *
* @param packageName
* @param simpleName
* @param icon
*/
public void addProvider(int position, String packageName, String simpleName, Drawable icon,
- int apiVersion) {
+ int apiVersion) {
mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon,
apiVersion));
}
@@ -100,12 +100,12 @@ public class OpenPgpListPreference extends DialogPreference {
tv.setCompoundDrawablePadding(dp10);
// disable if it has the wrong api_version
- if (mProviderList.get(position).apiVersion == OpenPgpConstants.REQUIRED_API_VERSION) {
+ if (mProviderList.get(position).apiVersion == OpenPgpConstants.API_VERSION) {
tv.setEnabled(true);
} else {
tv.setEnabled(false);
tv.setText(tv.getText() + " (API v" + mProviderList.get(position).apiVersion
- + ", needs v" + OpenPgpConstants.REQUIRED_API_VERSION + ")");
+ + ", needs v" + OpenPgpConstants.API_VERSION + ")");
}
return v;
@@ -186,7 +186,7 @@ public class OpenPgpListPreference extends DialogPreference {
private int apiVersion;
public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon,
- int apiVersion) {
+ int apiVersion) {
this.packageName = packageName;
this.simpleName = simpleName;
this.icon = icon;
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java
index f7ba06aaf..780b4606b 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openintents.openpgp;
+package org.openintents.openpgp.util;
import org.openintents.openpgp.IOpenPgpService;
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java
index 7305c47ce..6dbf76897 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openintents.openpgp;
+package org.openintents.openpgp.util;
import java.util.List;
import java.util.regex.Pattern;
@@ -23,7 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
-public class OpenPgpHelper {
+public class OpenPgpUtils {
private Context context;
public static Pattern PGP_MESSAGE = Pattern.compile(
@@ -34,7 +34,7 @@ public class OpenPgpHelper {
".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
Pattern.DOTALL);
- public OpenPgpHelper(Context context) {
+ public OpenPgpUtils(Context context) {
super();
this.context = context;
}
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java
new file mode 100644
index 000000000..20f8c36f3
--- /dev/null
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ * 2013 Flow (http://stackoverflow.com/questions/18212152/transfer-inputstream-to-another-service-across-process-boundaries-with-parcelf)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp.util;
+
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class ParcelFileDescriptorUtil {
+
+ public interface IThreadListener {
+ void onThreadFinished(final Thread thread);
+ }
+
+ public static ParcelFileDescriptor pipeFrom(InputStream inputStream, IThreadListener listener)
+ throws IOException {
+ ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
+ ParcelFileDescriptor readSide = pipe[0];
+ ParcelFileDescriptor writeSide = pipe[1];
+
+ // start the transfer thread
+ new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide),
+ listener)
+ .start();
+
+ return readSide;
+ }
+
+ public static ParcelFileDescriptor pipeTo(OutputStream outputStream, IThreadListener listener)
+ throws IOException {
+ ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
+ ParcelFileDescriptor readSide = pipe[0];
+ ParcelFileDescriptor writeSide = pipe[1];
+
+ // start the transfer thread
+ new TransferThread(new ParcelFileDescriptor.AutoCloseInputStream(readSide), outputStream,
+ listener)
+ .start();
+
+ return writeSide;
+ }
+
+ static class TransferThread extends Thread {
+ final InputStream mIn;
+ final OutputStream mOut;
+ final IThreadListener mListener;
+
+ TransferThread(InputStream in, OutputStream out, IThreadListener listener) {
+ super("ParcelFileDescriptor Transfer Thread");
+ mIn = in;
+ mOut = out;
+ mListener = listener;
+ setDaemon(true);
+ }
+
+ @Override
+ public void run() {
+ byte[] buf = new byte[1024];
+ int len;
+
+ try {
+ while ((len = mIn.read(buf)) > 0) {
+ mOut.write(buf, 0, len);
+ }
+ mOut.flush(); // just to be safe
+ } catch (IOException e) {
+ Log.e(OpenPgpConstants.TAG, "TransferThread" + getId() + ": writing failed", e);
+ } finally {
+ try {
+ mIn.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ mOut.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (mListener != null) {
+ Log.d(OpenPgpConstants.TAG, "TransferThread " + getId() + " finished!");
+ mListener.onThreadFinished(this);
+ }
+ }
+ }
+} \ No newline at end of file
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) {
diff --git a/libraries/keychain-api-library/build.gradle b/libraries/keychain-api-library/build.gradle
index 5436ecd0a..f9da72cb8 100644
--- a/libraries/keychain-api-library/build.gradle
+++ b/libraries/keychain-api-library/build.gradle
@@ -1,5 +1,15 @@
-apply plugin: 'android-library'
+// please leave this here, so this library builds on its own
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.8.0'
+ }
+}
+apply plugin: 'android-library'
android {
compileSdkVersion 19
diff --git a/libraries/keychain-api-library/src/main/AndroidManifest.xml b/libraries/keychain-api-library/src/main/AndroidManifest.xml
index 32b4a82e5..768922c22 100644
--- a/libraries/keychain-api-library/src/main/AndroidManifest.xml
+++ b/libraries/keychain-api-library/src/main/AndroidManifest.xml
@@ -5,7 +5,7 @@
android:versionName="1.0" >
<uses-sdk
- android:minSdkVersion="8"
+ android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application/>
diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl
index 4ca356fad..f9b5fc453 100644
--- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl
+++ b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl
index 8f9e8a0fd..ef390a7f6 100644
--- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl
+++ b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,36 @@ import org.openintents.openpgp.OpenPgpData;
import org.openintents.openpgp.IOpenPgpCallback;
import org.openintents.openpgp.IOpenPgpKeyIdsCallback;
-/**
- * All methods are oneway, which means they are asynchronous and non-blocking.
- * Results are returned to the callback, which has to be implemented on client side.
- */
interface IOpenPgpService {
/**
+ * Bundle params:
+ * api_version 1,2,3,... (current: 1)
+ * ascii_armor true/false (for output)
+ * key_ids long[] (for encrypt method)
+ *
+ *
+ * Bundle return:
+ * result_code RESULT_ERROR=0 (see error), RESULT_OK=1, RESULT_USER_INTERACTION_REQUIRED=2 (execute intent and do it again with params from intent)
+ * signature_result OpenPgpSignatureResult
+ * error OpenPgpError
+ * intent Intent
+ *
+ */
+
+ Bundle sign(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+ Bundle encrypt(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+ Bundle signAndEncrypt(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+ Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
+
+
+/*
+ ------------------OLD--------------------------
+*/
+ /**
* Sign
*
* After successful signing, callback's onSuccess will contain the resulting output.
@@ -48,8 +71,9 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void sign(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
-
+ //oneway void sign(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
+
+
/**
* Encrypt
*
@@ -74,7 +98,7 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void encrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
+ //oneway void encrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
/**
* Sign then encrypt
@@ -100,7 +124,7 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void signAndEncrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
+ //oneway void signAndEncrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
/**
* Decrypts and verifies given input bytes. This methods handles encrypted-only, signed-and-encrypted,
@@ -126,7 +150,7 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results
*/
- oneway void decryptAndVerify(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
+ //oneway void decryptAndVerify(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
/**
* Get available key ids based on given user ids
@@ -138,6 +162,6 @@ interface IOpenPgpService {
* @param callback
* Callback where to return results (different type than callback in other functions!)
*/
- oneway void getKeyIds(in String[] ids, in boolean allowUserInteraction, in IOpenPgpKeyIdsCallback callback);
+ //oneway void getKeyIds(in String[] ids, in boolean allowUserInteraction, in IOpenPgpKeyIdsCallback callback);
} \ No newline at end of file
diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
index 7a6bed1e6..7f867653d 100644
--- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
+++ b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
index e246792d0..d1d138b30 100644
--- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
+++ b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java
deleted file mode 100644
index b1ca1bfe6..000000000
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.openintents.openpgp;
-
-public class OpenPgpConstants {
-
- public static final String TAG = "OpenPgp API";
-
- public static final int REQUIRED_API_VERSION = 1;
- public static final String SERVICE_INTENT = "org.openintents.openpgp.IOpenPgpService";
-
-}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java
index f108d3169..4dd2cc641 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,13 @@ import android.os.Parcel;
import android.os.Parcelable;
public class OpenPgpError implements Parcelable {
+ public static final int CLIENT_SIDE_ERROR = -1;
+
public static final int GENERIC_ERROR = 0;
- public static final int NO_OR_WRONG_PASSPHRASE = 1;
- public static final int NO_USER_IDS = 2;
- public static final int USER_INTERACTION_REQUIRED = 3;
+ public static final int INCOMPATIBLE_API_VERSIONS = 1;
+
+ public static final int NO_OR_WRONG_PASSPHRASE = 2;
+ public static final int NO_USER_IDS = 3;
int errorId;
String message;
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
index 829f8f8cf..226eeacc2 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java
new file mode 100644
index 000000000..6efb507c4
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp.util;
+
+import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.util.Log;
+
+import org.openintents.openpgp.IOpenPgpService;
+import org.openintents.openpgp.OpenPgpError;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class OpenPgpApi {
+
+ IOpenPgpService mService;
+
+ public OpenPgpApi(IOpenPgpService service) {
+ this.mService = service;
+ }
+
+ public Bundle sign(InputStream is, final OutputStream os) {
+ try {
+ // send the input and output pfds
+ ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is,
+ new ParcelFileDescriptorUtil.IThreadListener() {
+
+ @Override
+ public void onThreadFinished(Thread thread) {
+ Log.d(OpenPgpConstants.TAG, "Copy to service finished");
+ }
+ });
+ ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os,
+ new ParcelFileDescriptorUtil.IThreadListener() {
+
+ @Override
+ public void onThreadFinished(Thread thread) {
+ Log.d(OpenPgpConstants.TAG, "Service finished writing!");
+ }
+ });
+
+ // blocks until result is ready
+ Bundle result = mService.sign(null, input, output);
+ // close() is required to halt the TransferThread
+ output.close();
+
+ return result;
+ } catch (RemoteException e) {
+ Log.e(OpenPgpConstants.TAG, "RemoteException", e);
+ Bundle result = new Bundle();
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
+ result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
+ new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
+ return result;
+ } catch (IOException e) {
+ Log.e(OpenPgpConstants.TAG, "IOException", e);
+ Bundle result = new Bundle();
+ result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
+ result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
+ new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
+ return result;
+ }
+ }
+
+
+}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java
new file mode 100644
index 000000000..3dd9391d0
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp.util;
+
+public class OpenPgpConstants {
+
+ public static final String TAG = "OpenPgp API";
+
+ public static final int API_VERSION = 1;
+ public static final String SERVICE_INTENT = "org.openintents.openpgp.IOpenPgpService";
+
+
+ /* Bundle params */
+ public static final String PARAMS_API_VERSION = "api_version";
+ // request ASCII Armor for output
+ // OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
+ public static final String PARAMS_REQUEST_ASCII_ARMOR = "ascii_armor";
+ // (for encrypt method)
+ public static final String PARAMS_KEY_IDS = "key_ids";
+
+ /* Bundle return */
+ public static final String RESULT_CODE = "result_code";
+ public static final String RESULT_SIGNATURE = "signature";
+ public static final String RESULT_ERRORS = "error";
+ public static final String RESULT_INTENT = "intent";
+
+ // get actual error object from RESULT_ERRORS
+ public static final int RESULT_CODE_ERROR = 0;
+ // success!
+ public static final int RESULT_CODE_SUCCESS = 1;
+ // execute intent and do it again with params from intent
+ public static final int RESULT_CODE_USER_INTERACTION_REQUIRED = 2;
+
+}
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
index 4ddd97485..ea287a7a9 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openintents.openpgp;
+package org.openintents.openpgp.util;
import java.util.ArrayList;
import java.util.List;
@@ -70,13 +70,13 @@ public class OpenPgpListPreference extends DialogPreference {
/**
* Can be used to add "no selection"
- *
+ *
* @param packageName
* @param simpleName
* @param icon
*/
public void addProvider(int position, String packageName, String simpleName, Drawable icon,
- int apiVersion) {
+ int apiVersion) {
mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon,
apiVersion));
}
@@ -100,12 +100,12 @@ public class OpenPgpListPreference extends DialogPreference {
tv.setCompoundDrawablePadding(dp10);
// disable if it has the wrong api_version
- if (mProviderList.get(position).apiVersion == OpenPgpConstants.REQUIRED_API_VERSION) {
+ if (mProviderList.get(position).apiVersion == OpenPgpConstants.API_VERSION) {
tv.setEnabled(true);
} else {
tv.setEnabled(false);
tv.setText(tv.getText() + " (API v" + mProviderList.get(position).apiVersion
- + ", needs v" + OpenPgpConstants.REQUIRED_API_VERSION + ")");
+ + ", needs v" + OpenPgpConstants.API_VERSION + ")");
}
return v;
@@ -186,7 +186,7 @@ public class OpenPgpListPreference extends DialogPreference {
private int apiVersion;
public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon,
- int apiVersion) {
+ int apiVersion) {
this.packageName = packageName;
this.simpleName = simpleName;
this.icon = icon;
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java
index f7ba06aaf..780b4606b 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openintents.openpgp;
+package org.openintents.openpgp.util;
import org.openintents.openpgp.IOpenPgpService;
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java
index 7305c47ce..6dbf76897 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openintents.openpgp;
+package org.openintents.openpgp.util;
import java.util.List;
import java.util.regex.Pattern;
@@ -23,7 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
-public class OpenPgpHelper {
+public class OpenPgpUtils {
private Context context;
public static Pattern PGP_MESSAGE = Pattern.compile(
@@ -34,7 +34,7 @@ public class OpenPgpHelper {
".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
Pattern.DOTALL);
- public OpenPgpHelper(Context context) {
+ public OpenPgpUtils(Context context) {
super();
this.context = context;
}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java
new file mode 100644
index 000000000..20f8c36f3
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ * 2013 Flow (http://stackoverflow.com/questions/18212152/transfer-inputstream-to-another-service-across-process-boundaries-with-parcelf)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp.util;
+
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class ParcelFileDescriptorUtil {
+
+ public interface IThreadListener {
+ void onThreadFinished(final Thread thread);
+ }
+
+ public static ParcelFileDescriptor pipeFrom(InputStream inputStream, IThreadListener listener)
+ throws IOException {
+ ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
+ ParcelFileDescriptor readSide = pipe[0];
+ ParcelFileDescriptor writeSide = pipe[1];
+
+ // start the transfer thread
+ new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide),
+ listener)
+ .start();
+
+ return readSide;
+ }
+
+ public static ParcelFileDescriptor pipeTo(OutputStream outputStream, IThreadListener listener)
+ throws IOException {
+ ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
+ ParcelFileDescriptor readSide = pipe[0];
+ ParcelFileDescriptor writeSide = pipe[1];
+
+ // start the transfer thread
+ new TransferThread(new ParcelFileDescriptor.AutoCloseInputStream(readSide), outputStream,
+ listener)
+ .start();
+
+ return writeSide;
+ }
+
+ static class TransferThread extends Thread {
+ final InputStream mIn;
+ final OutputStream mOut;
+ final IThreadListener mListener;
+
+ TransferThread(InputStream in, OutputStream out, IThreadListener listener) {
+ super("ParcelFileDescriptor Transfer Thread");
+ mIn = in;
+ mOut = out;
+ mListener = listener;
+ setDaemon(true);
+ }
+
+ @Override
+ public void run() {
+ byte[] buf = new byte[1024];
+ int len;
+
+ try {
+ while ((len = mIn.read(buf)) > 0) {
+ mOut.write(buf, 0, len);
+ }
+ mOut.flush(); // just to be safe
+ } catch (IOException e) {
+ Log.e(OpenPgpConstants.TAG, "TransferThread" + getId() + ": writing failed", e);
+ } finally {
+ try {
+ mIn.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ mOut.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (mListener != null) {
+ Log.d(OpenPgpConstants.TAG, "TransferThread " + getId() + " finished!");
+ mListener.onThreadFinished(this);
+ }
+ }
+ }
+} \ No newline at end of file