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 7f867653d..0fbea0a8c 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 @@ -16,5 +16,7 @@ package org.openintents.openpgp; +import org.openintents.openpgp.OpenPgpError; + // Declare OpenPgpError so AIDL can find it and knows that it implements the parcelable protocol. parcelable OpenPgpError; \ No newline at end of file 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 d1d138b30..dfc7e0992 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 @@ -16,5 +16,7 @@ package org.openintents.openpgp; +import org.openintents.openpgp.OpenPgpSignatureResult; + // Declare OpenPgpSignatureResult so AIDL can find it and knows that it implements the parcelable protocol. parcelable OpenPgpSignatureResult; \ No newline at end of file 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 index 229c8d42a..263b42aaa 100644 --- 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 @@ -32,6 +32,8 @@ public class OpenPgpConstants { // (for encrypt method) public static final String PARAMS_USER_IDS = "user_ids"; public static final String PARAMS_KEY_IDS = "key_ids"; + // optional parameter: + public static final String PARAMS_PASSPHRASE = "passphrase"; /* Service Bundle returns */ public static final String RESULT_CODE = "result_code"; diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java index ea287a7a9..e29794e87 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java @@ -16,16 +16,11 @@ package org.openintents.openpgp.util; -import java.util.ArrayList; -import java.util.List; - import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.pm.ServiceInfo; import android.graphics.drawable.Drawable; import android.preference.DialogPreference; import android.util.AttributeSet; @@ -35,6 +30,9 @@ import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.TextView; +import java.util.ArrayList; +import java.util.List; + public class OpenPgpListPreference extends DialogPreference { ArrayList mProviderList = new ArrayList(); private String mSelectedPackage; @@ -42,8 +40,8 @@ public class OpenPgpListPreference extends DialogPreference { public OpenPgpListPreference(Context context, AttributeSet attrs) { super(context, attrs); - List resInfo = context.getPackageManager().queryIntentServices( - new Intent(OpenPgpConstants.SERVICE_INTENT), PackageManager.GET_META_DATA); + Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); + List resInfo = context.getPackageManager().queryIntentServices(intent, 0); if (!resInfo.isEmpty()) { for (ResolveInfo resolveInfo : resInfo) { if (resolveInfo.serviceInfo == null) @@ -54,12 +52,7 @@ public class OpenPgpListPreference extends DialogPreference { .getPackageManager())); Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager()); - // get api version - ServiceInfo si = resolveInfo.serviceInfo; - int apiVersion = si.metaData.getInt("api_version"); - - mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon, - apiVersion)); + mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon)); } } } @@ -75,10 +68,8 @@ public class OpenPgpListPreference extends DialogPreference { * @param simpleName * @param icon */ - public void addProvider(int position, String packageName, String simpleName, Drawable icon, - int apiVersion) { - mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon, - apiVersion)); + public void addProvider(int position, String packageName, String simpleName, Drawable icon) { + mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon)); } @Override @@ -99,15 +90,6 @@ public class OpenPgpListPreference extends DialogPreference { int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp10); - // disable if it has the wrong 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.API_VERSION + ")"); - } - return v; } }; @@ -183,14 +165,11 @@ public class OpenPgpListPreference extends DialogPreference { private String packageName; private String simpleName; private Drawable icon; - private int apiVersion; - public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon, - int apiVersion) { + public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon) { this.packageName = packageName; this.simpleName = simpleName; this.icon = icon; - this.apiVersion = apiVersion; } @Override diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java index 780b4606b..8e8812faa 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java @@ -61,11 +61,12 @@ public class OpenPgpServiceConnection { /** * If not already bound, bind! - * + * * @return */ public boolean bindToService() { - if (mService == null && !mBound) { // if not already connected + // if not already connected + if (mService == null && !mBound) { try { Log.d(OpenPgpConstants.TAG, "not bound yet"); diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java index 6dbf76897..ffecaceba 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java @@ -17,6 +17,7 @@ package org.openintents.openpgp.util; import java.util.List; +import java.util.regex.Matcher; import java.util.regex.Pattern; import android.content.Context; @@ -24,22 +25,33 @@ import android.content.Intent; import android.content.pm.ResolveInfo; public class OpenPgpUtils { - private Context context; - public static Pattern PGP_MESSAGE = Pattern.compile( - ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); + public static final Pattern PGP_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", + Pattern.DOTALL); - public static Pattern PGP_SIGNED_MESSAGE = Pattern - .compile( - ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", - Pattern.DOTALL); + public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", + Pattern.DOTALL); - public OpenPgpUtils(Context context) { - super(); - this.context = context; + public static final int PARSE_RESULT_NO_PGP = -1; + public static final int PARSE_RESULT_MESSAGE = 0; + public static final int PARSE_RESULT_SIGNED_MESSAGE = 1; + + public static int parseMessage(String message) { + Matcher matcherSigned = PGP_SIGNED_MESSAGE.matcher(message); + Matcher matcherMessage = PGP_MESSAGE.matcher(message); + + if (matcherMessage.matches()) { + return PARSE_RESULT_MESSAGE; + } else if (matcherSigned.matches()) { + return PARSE_RESULT_SIGNED_MESSAGE; + } else { + return PARSE_RESULT_NO_PGP; + } } - public boolean isAvailable() { + public static boolean isAvailable(Context context) { Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); List resInfo = context.getPackageManager().queryIntentServices(intent, 0); if (!resInfo.isEmpty()) { 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 b1635ec10..5362aa603 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 @@ -138,7 +138,8 @@ public class OpenPgpService extends RemoteService { // TODO: asciiArmor?! - private Bundle signImpl(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output, AppSettings appSettings) { + private Bundle signImpl(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output, + AppSettings appSettings) { try { // get passphrase from cache, if key has "no" passphrase, this returns an empty String String passphrase; diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index 2a0b4b6f9..0608b108f 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -383,7 +383,7 @@ Revoke access Package Name SHA-256 of Package Signature - The following application requests access to OpenPGP Keychain.\n\nAllow access (you can revoke it later)? + The displayed application requests access to OpenPGP Keychain.\nAllow access?\n\nWARNING: If you do not know why this screen appeared, disallow access! You can revoke access later using the \'Registered Applications\' screen. Allow access Disallow access Please select a key! 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 7f867653d..0fbea0a8c 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 @@ -16,5 +16,7 @@ package org.openintents.openpgp; +import org.openintents.openpgp.OpenPgpError; + // Declare OpenPgpError so AIDL can find it and knows that it implements the parcelable protocol. parcelable OpenPgpError; \ No newline at end of file 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 d1d138b30..dfc7e0992 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 @@ -16,5 +16,7 @@ package org.openintents.openpgp; +import org.openintents.openpgp.OpenPgpSignatureResult; + // Declare OpenPgpSignatureResult so AIDL can find it and knows that it implements the parcelable protocol. parcelable OpenPgpSignatureResult; \ No newline at end of file diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java index ea287a7a9..e29794e87 100644 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java +++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java @@ -16,16 +16,11 @@ package org.openintents.openpgp.util; -import java.util.ArrayList; -import java.util.List; - import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.pm.ServiceInfo; import android.graphics.drawable.Drawable; import android.preference.DialogPreference; import android.util.AttributeSet; @@ -35,6 +30,9 @@ import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.TextView; +import java.util.ArrayList; +import java.util.List; + public class OpenPgpListPreference extends DialogPreference { ArrayList mProviderList = new ArrayList(); private String mSelectedPackage; @@ -42,8 +40,8 @@ public class OpenPgpListPreference extends DialogPreference { public OpenPgpListPreference(Context context, AttributeSet attrs) { super(context, attrs); - List resInfo = context.getPackageManager().queryIntentServices( - new Intent(OpenPgpConstants.SERVICE_INTENT), PackageManager.GET_META_DATA); + Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); + List resInfo = context.getPackageManager().queryIntentServices(intent, 0); if (!resInfo.isEmpty()) { for (ResolveInfo resolveInfo : resInfo) { if (resolveInfo.serviceInfo == null) @@ -54,12 +52,7 @@ public class OpenPgpListPreference extends DialogPreference { .getPackageManager())); Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager()); - // get api version - ServiceInfo si = resolveInfo.serviceInfo; - int apiVersion = si.metaData.getInt("api_version"); - - mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon, - apiVersion)); + mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon)); } } } @@ -75,10 +68,8 @@ public class OpenPgpListPreference extends DialogPreference { * @param simpleName * @param icon */ - public void addProvider(int position, String packageName, String simpleName, Drawable icon, - int apiVersion) { - mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon, - apiVersion)); + public void addProvider(int position, String packageName, String simpleName, Drawable icon) { + mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon)); } @Override @@ -99,15 +90,6 @@ public class OpenPgpListPreference extends DialogPreference { int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp10); - // disable if it has the wrong 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.API_VERSION + ")"); - } - return v; } }; @@ -183,14 +165,11 @@ public class OpenPgpListPreference extends DialogPreference { private String packageName; private String simpleName; private Drawable icon; - private int apiVersion; - public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon, - int apiVersion) { + public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon) { this.packageName = packageName; this.simpleName = simpleName; this.icon = icon; - this.apiVersion = apiVersion; } @Override diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java index 780b4606b..8e8812faa 100644 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java +++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java @@ -61,11 +61,12 @@ public class OpenPgpServiceConnection { /** * If not already bound, bind! - * + * * @return */ public boolean bindToService() { - if (mService == null && !mBound) { // if not already connected + // if not already connected + if (mService == null && !mBound) { try { Log.d(OpenPgpConstants.TAG, "not bound yet"); diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java index 6dbf76897..ffecaceba 100644 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java +++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java @@ -17,6 +17,7 @@ package org.openintents.openpgp.util; import java.util.List; +import java.util.regex.Matcher; import java.util.regex.Pattern; import android.content.Context; @@ -24,22 +25,33 @@ import android.content.Intent; import android.content.pm.ResolveInfo; public class OpenPgpUtils { - private Context context; - public static Pattern PGP_MESSAGE = Pattern.compile( - ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); + public static final Pattern PGP_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", + Pattern.DOTALL); - public static Pattern PGP_SIGNED_MESSAGE = Pattern - .compile( - ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", - Pattern.DOTALL); + public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", + Pattern.DOTALL); - public OpenPgpUtils(Context context) { - super(); - this.context = context; + public static final int PARSE_RESULT_NO_PGP = -1; + public static final int PARSE_RESULT_MESSAGE = 0; + public static final int PARSE_RESULT_SIGNED_MESSAGE = 1; + + public static int parseMessage(String message) { + Matcher matcherSigned = PGP_SIGNED_MESSAGE.matcher(message); + Matcher matcherMessage = PGP_MESSAGE.matcher(message); + + if (matcherMessage.matches()) { + return PARSE_RESULT_MESSAGE; + } else if (matcherSigned.matches()) { + return PARSE_RESULT_SIGNED_MESSAGE; + } else { + return PARSE_RESULT_NO_PGP; + } } - public boolean isAvailable() { + public static boolean isAvailable(Context context) { Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); List resInfo = context.getPackageManager().queryIntentServices(intent, 0); if (!resInfo.isEmpty()) {