diff options
Diffstat (limited to 'libraries/keychain-api-library/src')
22 files changed, 611 insertions, 622 deletions
diff --git a/libraries/keychain-api-library/src/main/AndroidManifest.xml b/libraries/keychain-api-library/src/main/AndroidManifest.xml deleted file mode 100644 index 32b4a82e5..000000000 --- a/libraries/keychain-api-library/src/main/AndroidManifest.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.sufficientlysecure.keychain.api" - android:versionCode="1" - android:versionName="1.0" > - - <uses-sdk - android:minSdkVersion="8" - android:targetSdkVersion="19" /> - - <application/> - -</manifest>
\ No newline at end of file diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpCallback.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpCallback.aidl deleted file mode 100644 index ba41de1ba..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpCallback.aidl +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2013 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; - -import org.openintents.openpgp.OpenPgpData; -import org.openintents.openpgp.OpenPgpSignatureResult; -import org.openintents.openpgp.OpenPgpError; - -interface IOpenPgpCallback { - - /** - * onSuccess returns on successful OpenPGP operations. - * - * @param output - * contains resulting output (decrypted content (when input was encrypted) - * or content without signature (when input was signed-only)) - * @param signatureResult - * signatureResult is only non-null if decryptAndVerify() was called and the content - * was encrypted or signed-and-encrypted. - */ - oneway void onSuccess(in OpenPgpData output, in OpenPgpSignatureResult signatureResult); - - /** - * onError returns on errors or when allowUserInteraction was set to false, but user interaction - * was required execute an OpenPGP operation. - * - * @param error - * See OpenPgpError class for more information. - */ - oneway void onError(in OpenPgpError error); -}
\ No newline at end of file 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 deleted file mode 100644 index 4ca356fad..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpKeyIdsCallback.aidl +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2013 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; - -import org.openintents.openpgp.OpenPgpError; - -interface IOpenPgpKeyIdsCallback { - - /** - * onSuccess returns on successful getKeyIds operations. - * - * @param keyIds - * returned key ids - */ - oneway void onSuccess(in long[] keyIds); - - /** - * onError returns on errors or when allowUserInteraction was set to false, but user interaction - * was required execute an OpenPGP operation. - * - * @param error - * See OpenPgpError class for more information. - */ - oneway void onError(in OpenPgpError error); -}
\ No newline at end of file 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 deleted file mode 100644 index 8f9e8a0fd..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2013 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; - -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 { - - /** - * Sign - * - * After successful signing, callback's onSuccess will contain the resulting output. - * - * @param input - * OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri - * @param output - * Request output format by defining OpenPgpData object - * - * new OpenPgpData(OpenPgpData.TYPE_STRING) - * Returns as String - * (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53) - * new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY) - * Returns as byte[] - * new OpenPgpData(uri) - * Writes output to given Uri - * new OpenPgpData(fileDescriptor) - * Writes output to given ParcelFileDescriptor - * @param callback - * Callback where to return results - */ - oneway void sign(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback); - - /** - * Encrypt - * - * After successful encryption, callback's onSuccess will contain the resulting output. - * - * @param input - * OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri - * @param output - * Request output format by defining OpenPgpData object - * - * new OpenPgpData(OpenPgpData.TYPE_STRING) - * Returns as String - * (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53) - * new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY) - * Returns as byte[] - * new OpenPgpData(uri) - * Writes output to given Uri - * new OpenPgpData(fileDescriptor) - * Writes output to given ParcelFileDescriptor - * @param keyIds - * Key Ids of recipients. Can be retrieved with getKeyIds() - * @param callback - * Callback where to return results - */ - oneway void encrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback); - - /** - * Sign then encrypt - * - * After successful signing and encryption, callback's onSuccess will contain the resulting output. - * - * @param input - * OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri - * @param output - * Request output format by defining OpenPgpData object - * - * new OpenPgpData(OpenPgpData.TYPE_STRING) - * Returns as String - * (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53) - * new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY) - * Returns as byte[] - * new OpenPgpData(uri) - * Writes output to given Uri - * new OpenPgpData(fileDescriptor) - * Writes output to given ParcelFileDescriptor - * @param keyIds - * Key Ids of recipients. Can be retrieved with getKeyIds() - * @param callback - * Callback where to return results - */ - 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, - * and also signed-only input. - * - * After successful decryption/verification, callback's onSuccess will contain the resulting output. - * The signatureResult in onSuccess is only non-null if signed-and-encrypted or signed-only inputBytes were given. - * - * @param input - * OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri - * @param output - * Request output format by defining OpenPgpData object - * - * new OpenPgpData(OpenPgpData.TYPE_STRING) - * Returns as String - * (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53) - * new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY) - * Returns as byte[] - * new OpenPgpData(uri) - * Writes output to given Uri - * new OpenPgpData(fileDescriptor) - * Writes output to given ParcelFileDescriptor - * @param callback - * Callback where to return results - */ - oneway void decryptAndVerify(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback); - - /** - * Get available key ids based on given user ids - * - * @param ids - * User Ids (emails) of recipients OR key ids - * @param allowUserInteraction - * Enable user interaction to lookup and import unknown keys - * @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); - -}
\ No newline at end of file diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpData.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpData.aidl deleted file mode 100644 index 3711e4fb4..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpData.aidl +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2013 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; - -// Declare OpenPgpData so AIDL can find it and knows that it implements the parcelable protocol. -parcelable OpenPgpData;
\ 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 deleted file mode 100644 index 7a6bed1e6..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2013 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; - -// 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 deleted file mode 100644 index e246792d0..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2013 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; - -// 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/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiCallback.aidl b/libraries/keychain-api-library/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiCallback.aidl deleted file mode 100644 index f69f66fd7..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiCallback.aidl +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2013 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.sufficientlysecure.keychain.service.remote; - -interface IExtendedApiCallback { - - oneway void onSuccess(in byte[] outputBytes); - - oneway void onError(in String error); -}
\ No newline at end of file diff --git a/libraries/keychain-api-library/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiService.aidl b/libraries/keychain-api-library/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiService.aidl deleted file mode 100644 index 669bd31b5..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiService.aidl +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2013 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.sufficientlysecure.keychain.service.remote; - -import org.sufficientlysecure.keychain.service.remote.IExtendedApiCallback; - -/** - * 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 IExtendedApiService { - - /** - * Symmetric Encrypt - * - * @param inputBytes - * Byte array you want to encrypt - * @param passphrase - * symmetric passhprase - * @param callback - * Callback where to return results - */ - oneway void encrypt(in byte[] inputBytes, in String passphrase, in IExtendedApiCallback callback); - - /** - * Generates self signed X509 certificate signed by OpenPGP private key (from app settings) - * - * @param subjAltNameURI - * @param callback - * Callback where to return results - */ - oneway void selfSignedX509Cert(in String subjAltNameURI, in IExtendedApiCallback callback); - -}
\ No newline at end of file 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/OpenPgpData.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpData.java deleted file mode 100644 index 6615c2146..000000000 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpData.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2013 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; - -import android.net.Uri; -import android.os.Parcel; -import android.os.ParcelFileDescriptor; -import android.os.Parcelable; - -public class OpenPgpData implements Parcelable { - public static final int TYPE_STRING = 0; - public static final int TYPE_BYTE_ARRAY = 1; - public static final int TYPE_FILE_DESCRIPTOR = 2; - public static final int TYPE_URI = 3; - - int type; - - String string; - byte[] bytes = new byte[0]; - ParcelFileDescriptor fileDescriptor; - Uri uri; - - public int getType() { - return type; - } - - public String getString() { - return string; - } - - public byte[] getBytes() { - return bytes; - } - - public ParcelFileDescriptor getFileDescriptor() { - return fileDescriptor; - } - - public Uri getUri() { - return uri; - } - - public OpenPgpData() { - - } - - /** - * Not a real constructor. This can be used to define requested output type. - * - * @param type - */ - public OpenPgpData(int type) { - this.type = type; - } - - public OpenPgpData(String string) { - this.string = string; - this.type = TYPE_STRING; - } - - public OpenPgpData(byte[] bytes) { - this.bytes = bytes; - this.type = TYPE_BYTE_ARRAY; - } - - public OpenPgpData(ParcelFileDescriptor fileDescriptor) { - this.fileDescriptor = fileDescriptor; - this.type = TYPE_FILE_DESCRIPTOR; - } - - public OpenPgpData(Uri uri) { - this.uri = uri; - this.type = TYPE_URI; - } - - public OpenPgpData(OpenPgpData b) { - this.string = b.string; - this.bytes = b.bytes; - this.fileDescriptor = b.fileDescriptor; - this.uri = b.uri; - } - - public int describeContents() { - return 0; - } - - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(type); - dest.writeString(string); - dest.writeInt(bytes.length); - dest.writeByteArray(bytes); - dest.writeParcelable(fileDescriptor, 0); - dest.writeParcelable(uri, 0); - } - - public static final Creator<OpenPgpData> CREATOR = new Creator<OpenPgpData>() { - public OpenPgpData createFromParcel(final Parcel source) { - OpenPgpData vr = new OpenPgpData(); - vr.type = source.readInt(); - vr.string = source.readString(); - vr.bytes = new byte[source.readInt()]; - source.readByteArray(vr.bytes); - vr.fileDescriptor = source.readParcelable(ParcelFileDescriptor.class.getClassLoader()); - vr.fileDescriptor = source.readParcelable(Uri.class.getClassLoader()); - return vr; - } - - public OpenPgpData[] newArray(final int size) { - return new OpenPgpData[size]; - } - }; - -} diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java deleted file mode 100644 index 7305c47ce..000000000 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2013 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; - -import java.util.List; -import java.util.regex.Pattern; - -import android.content.Context; -import android.content.Intent; -import android.content.pm.ResolveInfo; - -public class OpenPgpHelper { - private Context context; - - public static 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 OpenPgpHelper(Context context) { - super(); - this.context = context; - } - - public boolean isAvailable() { - Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); - List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0); - if (!resInfo.isEmpty()) { - return true; - } else { - return false; - } - } - -} diff --git a/libraries/keychain-api-library/src/org/openintents/openpgp/IOpenPgpService.aidl b/libraries/keychain-api-library/src/org/openintents/openpgp/IOpenPgpService.aidl new file mode 100644 index 000000000..578a7d4b5 --- /dev/null +++ b/libraries/keychain-api-library/src/org/openintents/openpgp/IOpenPgpService.aidl @@ -0,0 +1,85 @@ +/* + * 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; + +interface IOpenPgpService { + + /** + * General extras + * -------------- + * + * Bundle params: + * int api_version (required) + * boolean ascii_armor (request ascii armor for ouput) + * + * returned Bundle: + * int result_code (0, 1, or 2 (see OpenPgpConstants)) + * OpenPgpError error (if result_code == 0) + * Intent intent (if result_code == 2) + * + */ + + /** + * Sign only + * + * optional params: + * String passphrase (for key passphrase) + */ + Bundle sign(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output); + + /** + * Encrypt + * + * Bundle params: + * long[] key_ids + * or + * String[] user_ids (= emails of recipients) (if more than one key has this user_id, a PendingIntent is returned) + * + * optional params: + * String passphrase (for key passphrase) + */ + Bundle encrypt(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output); + + /** + * Sign and encrypt + * + * Bundle params: + * same as in encrypt() + */ + Bundle signAndEncrypt(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output); + + /** + * Decrypts and verifies given input bytes. This methods handles encrypted-only, signed-and-encrypted, + * and also signed-only input. + * + * returned Bundle: + * OpenPgpSignatureResult signature_result + */ + Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output); + + /** + * Retrieves key ids based on given user ids (=emails) + * + * Bundle params: + * String[] user_ids + * + * returned Bundle: + * long[] key_ids + */ + Bundle getKeyIds(in Bundle params); + +}
\ No newline at end of file diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java b/libraries/keychain-api-library/src/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/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/org/openintents/openpgp/OpenPgpSignatureResult.java index 829f8f8cf..16c79ca27 100644 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java +++ b/libraries/keychain-api-library/src/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. @@ -22,14 +22,14 @@ import android.os.Parcelable; public class OpenPgpSignatureResult implements Parcelable { // generic error on signature verification public static final int SIGNATURE_ERROR = 0; - // successfully verified signature, with trusted public key - public static final int SIGNATURE_SUCCESS_TRUSTED = 1; + // successfully verified signature, with certified public key + public static final int SIGNATURE_SUCCESS_CERTIFIED = 1; // no public key was found for this signature verification // you can retrieve the key with // getKeys(new String[] {String.valueOf(signatureResult.getKeyId)}, true, callback) public static final int SIGNATURE_UNKNOWN_PUB_KEY = 2; - // successfully verified signature, but with untrusted public key - public static final int SIGNATURE_SUCCESS_UNTRUSTED = 3; + // successfully verified signature, but with certified public key + public static final int SIGNATURE_SUCCESS_UNCERTIFIED = 3; int status; boolean signatureOnly; diff --git a/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpApi.java b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpApi.java new file mode 100644 index 000000000..f121c345d --- /dev/null +++ b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpApi.java @@ -0,0 +1,198 @@ +/* + * 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.content.Context; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.ParcelFileDescriptor; +import android.util.Log; + +import org.openintents.openpgp.IOpenPgpService; +import org.openintents.openpgp.OpenPgpError; + +import java.io.InputStream; +import java.io.OutputStream; + +public class OpenPgpApi { + + IOpenPgpService mService; + Context mContext; + + private static final int OPERATION_SIGN = 0; + private static final int OPERATION_ENCRYPT = 1; + private static final int OPERATION_SIGN_ENCRYPT = 2; + private static final int OPERATION_DECRYPT_VERIFY = 3; + private static final int OPERATION_GET_KEY_IDS = 4; + + public OpenPgpApi(Context context, IOpenPgpService service) { + this.mContext = context; + this.mService = service; + } + + public Bundle sign(InputStream is, final OutputStream os) { + return executeApi(OPERATION_SIGN, new Bundle(), is, os); + } + + public Bundle sign(Bundle params, InputStream is, final OutputStream os) { + return executeApi(OPERATION_SIGN, params, is, os); + } + + public void sign(Bundle params, InputStream is, final OutputStream os, IOpenPgpCallback callback) { + executeApiAsync(OPERATION_SIGN, params, is, os, callback); + } + + public Bundle encrypt(InputStream is, final OutputStream os) { + return executeApi(OPERATION_ENCRYPT, new Bundle(), is, os); + } + + public Bundle encrypt(Bundle params, InputStream is, final OutputStream os) { + return executeApi(OPERATION_ENCRYPT, params, is, os); + } + + public void encrypt(Bundle params, InputStream is, final OutputStream os, IOpenPgpCallback callback) { + executeApiAsync(OPERATION_ENCRYPT, params, is, os, callback); + } + + public Bundle signAndEncrypt(InputStream is, final OutputStream os) { + return executeApi(OPERATION_SIGN_ENCRYPT, new Bundle(), is, os); + } + + public Bundle signAndEncrypt(Bundle params, InputStream is, final OutputStream os) { + return executeApi(OPERATION_SIGN_ENCRYPT, params, is, os); + } + + public void signAndEncrypt(Bundle params, InputStream is, final OutputStream os, IOpenPgpCallback callback) { + executeApiAsync(OPERATION_SIGN_ENCRYPT, params, is, os, callback); + } + + public Bundle decryptAndVerify(InputStream is, final OutputStream os) { + return executeApi(OPERATION_DECRYPT_VERIFY, new Bundle(), is, os); + } + + public Bundle decryptAndVerify(Bundle params, InputStream is, final OutputStream os) { + return executeApi(OPERATION_DECRYPT_VERIFY, params, is, os); + } + + public void decryptAndVerify(Bundle params, InputStream is, final OutputStream os, IOpenPgpCallback callback) { + executeApiAsync(OPERATION_DECRYPT_VERIFY, params, is, os, callback); + } + + public Bundle getKeyIds(Bundle params) { + return executeApi(OPERATION_GET_KEY_IDS, params, null, null); + } + + public interface IOpenPgpCallback { + void onReturn(final Bundle result); + } + + private class OpenPgpAsyncTask extends AsyncTask<Void, Integer, Bundle> { + int operationId; + Bundle params; + InputStream is; + OutputStream os; + IOpenPgpCallback callback; + + private OpenPgpAsyncTask(int operationId, Bundle params, InputStream is, OutputStream os, IOpenPgpCallback callback) { + this.operationId = operationId; + this.params = params; + this.is = is; + this.os = os; + this.callback = callback; + } + + @Override + protected Bundle doInBackground(Void... unused) { + return executeApi(operationId, params, is, os); + } + + protected void onPostExecute(Bundle result) { + callback.onReturn(result); + } + + } + + private void executeApiAsync(int operationId, Bundle params, InputStream is, OutputStream os, IOpenPgpCallback callback) { + new OpenPgpAsyncTask(operationId, params, is, os, callback).execute((Void[]) null); + } + + private Bundle executeApi(int operationId, Bundle params, InputStream is, OutputStream os) { + try { + params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION); + + Bundle result = null; + + if (operationId == OPERATION_GET_KEY_IDS) { + result = mService.getKeyIds(params); + return result; + } else { + // 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 + switch (operationId) { + case OPERATION_SIGN: + result = mService.sign(params, input, output); + break; + case OPERATION_ENCRYPT: + result = mService.encrypt(params, input, output); + break; + case OPERATION_SIGN_ENCRYPT: + result = mService.signAndEncrypt(params, input, output); + break; + case OPERATION_DECRYPT_VERIFY: + result = mService.decryptAndVerify(params, input, output); + break; + } + // close() is required to halt the TransferThread + output.close(); + + // set class loader to current context to allow unparcelling + // of OpenPgpError and OpenPgpSignatureResult + // http://stackoverflow.com/a/3806769 + result.setClassLoader(mContext.getClassLoader()); + + return result; + } + } catch (Exception e) { + Log.e(OpenPgpConstants.TAG, "Exception", 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/org/openintents/openpgp/util/OpenPgpConstants.java b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpConstants.java new file mode 100644 index 000000000..263b42aaa --- /dev/null +++ b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpConstants.java @@ -0,0 +1,54 @@ +/* + * 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_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"; + 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; + // executeServiceMethod intent and do it again with params from intent + public static final int RESULT_CODE_USER_INTERACTION_REQUIRED = 2; + + /* PendingIntent returns */ + public static final String PI_RESULT_PARAMS = "params"; + +} diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java index 4ddd97485..034186a3a 100644 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java +++ b/libraries/keychain-api-library/src/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,18 +14,14 @@ * limitations under the License. */ -package org.openintents.openpgp; - -import java.util.ArrayList; -import java.util.List; +package org.openintents.openpgp.util; 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.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.DialogPreference; import android.util.AttributeSet; @@ -35,33 +31,21 @@ import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.TextView; +import java.util.ArrayList; +import java.util.List; + +import org.sufficientlysecure.keychain.api.R; + +/** + * Does not extend ListPreference, but is very similar to it! + * http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/4.4_r1/android/preference/ListPreference.java/?v=source + */ public class OpenPgpListPreference extends DialogPreference { - ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>(); + private ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>(); private String mSelectedPackage; public OpenPgpListPreference(Context context, AttributeSet attrs) { super(context, attrs); - - List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices( - new Intent(OpenPgpConstants.SERVICE_INTENT), PackageManager.GET_META_DATA); - if (!resInfo.isEmpty()) { - for (ResolveInfo resolveInfo : resInfo) { - if (resolveInfo.serviceInfo == null) - continue; - - String packageName = resolveInfo.serviceInfo.packageName; - String simpleName = String.valueOf(resolveInfo.serviceInfo.loadLabel(context - .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)); - } - } } public OpenPgpListPreference(Context context) { @@ -69,20 +53,42 @@ public class OpenPgpListPreference extends DialogPreference { } /** - * Can be used to add "no selection" - * + * Public method to add new entries for legacy applications + * * @param packageName * @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 protected void onPrepareDialogBuilder(Builder builder) { + + // get providers + mProviderList.clear(); + Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); + List<ResolveInfo> resInfo = getContext().getPackageManager().queryIntentServices(intent, 0); + if (!resInfo.isEmpty()) { + for (ResolveInfo resolveInfo : resInfo) { + if (resolveInfo.serviceInfo == null) + continue; + + String packageName = resolveInfo.serviceInfo.packageName; + String simpleName = String.valueOf(resolveInfo.serviceInfo.loadLabel(getContext() + .getPackageManager())); + Drawable icon = resolveInfo.serviceInfo.loadIcon(getContext().getPackageManager()); + + mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon)); + } + } + + // add "none"-entry + mProviderList.add(0, new OpenPgpProviderEntry("", + getContext().getString(R.string.openpgp_list_preference_none), + getContext().getResources().getDrawable(R.drawable.ic_action_cancel_launchersize))); + // Init ArrayAdapter with OpenPGP Providers ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(), android.R.layout.select_dialog_singlechoice, android.R.id.text1, mProviderList) { @@ -99,15 +105,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.REQUIRED_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 + ")"); - } - return v; } }; @@ -169,6 +166,16 @@ public class OpenPgpListPreference extends DialogPreference { return getEntryByValue(mSelectedPackage); } + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + return a.getString(index); + } + + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + setValue(restoreValue ? getPersistedString(mSelectedPackage) : (String) defaultValue); + } + public String getEntryByValue(String packageName) { for (OpenPgpProviderEntry app : mProviderList) { if (app.packageName.equals(packageName)) { @@ -183,14 +190,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/OpenPgpServiceConnection.java b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java index f7ba06aaf..8e8812faa 100644 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java +++ b/libraries/keychain-api-library/src/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; @@ -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/org/openintents/openpgp/util/OpenPgpUtils.java b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpUtils.java new file mode 100644 index 000000000..ffecaceba --- /dev/null +++ b/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpUtils.java @@ -0,0 +1,64 @@ +/* + * 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 java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ResolveInfo; + +public class OpenPgpUtils { + + public static final Pattern PGP_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", + Pattern.DOTALL); + + public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", + Pattern.DOTALL); + + 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 static boolean isAvailable(Context context) { + Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); + List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0); + if (!resInfo.isEmpty()) { + return true; + } else { + return false; + } + } + +} diff --git a/libraries/keychain-api-library/src/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java b/libraries/keychain-api-library/src/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java new file mode 100644 index 000000000..75d4b8c18 --- /dev/null +++ b/libraries/keychain-api-library/src/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) { + Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e); + } + try { + mOut.close(); + } catch (IOException e) { + Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e); + } + } + if (mListener != null) { + Log.d(OpenPgpConstants.TAG, "TransferThread " + getId() + " finished!"); + mListener.onThreadFinished(this); + } + } + } +}
\ No newline at end of file diff --git a/libraries/keychain-api-library/src/org/sufficientlysecure/keychain/api/OpenKeychainIntents.java b/libraries/keychain-api-library/src/org/sufficientlysecure/keychain/api/OpenKeychainIntents.java new file mode 100644 index 000000000..15aceb534 --- /dev/null +++ b/libraries/keychain-api-library/src/org/sufficientlysecure/keychain/api/OpenKeychainIntents.java @@ -0,0 +1,37 @@ +/* + * 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.sufficientlysecure.keychain.api; + +public class OpenKeychainIntents { + + public static final String ENCRYPT = "org.sufficientlysecure.keychain.action.ENCRYPT"; + public static final String ENCRYPT_EXTRA_TEXT = "text"; // String + public static final String ENCRYPT_ASCII_ARMOR = "ascii_armor"; // boolean + + public static final String DECRYPT = "org.sufficientlysecure.keychain.action.DECRYPT"; + public static final String DECRYPT_EXTRA_TEXT = "text"; // String + + public static final String IMPORT_KEY = "org.sufficientlysecure.keychain.action.IMPORT_KEY"; + public static final String IMPORT_KEY_EXTRA_KEY_BYTES = "key_bytes"; // byte[] + + public static final String IMPORT_KEY_FROM_KEYSERVER = "org.sufficientlysecure.keychain.action.IMPORT_KEY_FROM_KEYSERVER"; + public static final String IMPORT_KEY_FROM_KEYSERVER_QUERY = "query"; // String + public static final String IMPORT_KEY_FROM_KEYSERVER_FINGERPRINT = "fingerprint"; // String + + public static final String IMPORT_KEY_FROM_QR_CODE = "org.sufficientlysecure.keychain.action.IMPORT_KEY_FROM_QR_CODE"; + +} |