From d3bda969539061e11aaa2dc4ea8eec84942b136b Mon Sep 17 00:00:00 2001 From: mgeier63 Date: Thu, 27 Aug 2015 09:12:21 +0200 Subject: service side support for https://github.com/open-keychain/openpgp-api/pull/3 --- OpenKeychain/src/main/AndroidManifest.xml | 18 ++- .../keychain/remote/OpenPgpService.java | 129 +++++++++++---------- .../keychain/remote/OpenPgpService2.java | 120 +++++++++++++++++++ 3 files changed, 204 insertions(+), 63 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService2.java (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml index 0bc2e87ec..d57dae535 100644 --- a/OpenKeychain/src/main/AndroidManifest.xml +++ b/OpenKeychain/src/main/AndroidManifest.xml @@ -761,8 +761,9 @@ android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:exported="false" /> - + + + + + + + + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.remote; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.net.Uri; +import android.os.Binder; +import android.os.IBinder; +import android.os.ParcelFileDescriptor; +import android.os.Parcelable; +import android.text.TextUtils; + +import org.openintents.openpgp.IOpenPgpService2; +import org.openintents.openpgp.OpenPgpDecryptionResult; +import org.openintents.openpgp.OpenPgpError; +import org.openintents.openpgp.OpenPgpMetadata; +import org.openintents.openpgp.OpenPgpSignatureResult; +import org.openintents.openpgp.util.OpenPgpApi; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel; +import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; +import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; +import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; +import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants; +import org.sufficientlysecure.keychain.pgp.PgpSignEncryptInputParcel; +import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.remote.ui.RemoteServiceActivity; +import org.sufficientlysecure.keychain.remote.ui.SelectAllowedKeysActivity; +import org.sufficientlysecure.keychain.remote.ui.SelectSignKeyIdActivity; +import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; +import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; +import org.sufficientlysecure.keychain.ui.ImportKeysActivity; +import org.sufficientlysecure.keychain.ui.NfcOperationActivity; +import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; +import org.sufficientlysecure.keychain.ui.ViewKeyActivity; +import org.sufficientlysecure.keychain.util.InputData; +import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Passphrase; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +public class OpenPgpService2 extends OpenPgpService { + + + + private Map mOutputPipeMap = new HashMap(); + + private long createKey(int id) { + int callingPid = Binder.getCallingPid(); + return ((long) callingPid << 32) | ((long) id & 0xFFFFFFFL); + } + + private final IOpenPgpService2.Stub mBinder = new IOpenPgpService2.Stub() { + + @Override + public ParcelFileDescriptor createOutputPipe(int outputPipeId) { + try { + ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); + mOutputPipeMap.put(createKey(outputPipeId), pipe[1]); + return pipe[0]; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + + } + + @Override + public Intent execute(Intent data, ParcelFileDescriptor input,int outputPipeId) { + long key = createKey(outputPipeId); + ParcelFileDescriptor output = mOutputPipeMap.get(key); + mOutputPipeMap.remove(key); + return executeInternal(data, input, output); + } + + + + + }; + + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + + +} -- cgit v1.2.3 From 76522d90faa5a8727493a34786b4490919defc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Fri, 28 Aug 2015 17:14:40 +0200 Subject: Cleanup OpenPgpService2 code, update openpgp-api lib --- .../keychain/remote/OpenPgpService2.java | 54 ++-------------------- 1 file changed, 3 insertions(+), 51 deletions(-) (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService2.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService2.java index 317d4dd73..110302e55 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService2.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService2.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 Dominik Schürmann + * Copyright (C) 2015 Dominik Schürmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,64 +17,21 @@ package org.sufficientlysecure.keychain.remote; -import android.app.PendingIntent; -import android.content.Context; import android.content.Intent; -import android.database.Cursor; -import android.net.Uri; import android.os.Binder; import android.os.IBinder; import android.os.ParcelFileDescriptor; -import android.os.Parcelable; -import android.text.TextUtils; import org.openintents.openpgp.IOpenPgpService2; -import org.openintents.openpgp.OpenPgpDecryptionResult; -import org.openintents.openpgp.OpenPgpError; -import org.openintents.openpgp.OpenPgpMetadata; -import org.openintents.openpgp.OpenPgpSignatureResult; -import org.openintents.openpgp.util.OpenPgpApi; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; -import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel; -import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; -import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; -import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; -import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants; -import org.sufficientlysecure.keychain.pgp.PgpSignEncryptInputParcel; -import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; -import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.remote.ui.RemoteServiceActivity; -import org.sufficientlysecure.keychain.remote.ui.SelectAllowedKeysActivity; -import org.sufficientlysecure.keychain.remote.ui.SelectSignKeyIdActivity; -import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; -import org.sufficientlysecure.keychain.ui.ImportKeysActivity; -import org.sufficientlysecure.keychain.ui.NfcOperationActivity; -import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; -import org.sufficientlysecure.keychain.ui.ViewKeyActivity; -import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.Passphrase; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; public class OpenPgpService2 extends OpenPgpService { - - private Map mOutputPipeMap = new HashMap(); private long createKey(int id) { @@ -91,23 +48,20 @@ public class OpenPgpService2 extends OpenPgpService { mOutputPipeMap.put(createKey(outputPipeId), pipe[1]); return pipe[0]; } catch (IOException e) { - e.printStackTrace(); + Log.e(Constants.TAG, "IOException in OpenPgpService2", e); return null; } } @Override - public Intent execute(Intent data, ParcelFileDescriptor input,int outputPipeId) { + public Intent execute(Intent data, ParcelFileDescriptor input, int outputPipeId) { long key = createKey(outputPipeId); ParcelFileDescriptor output = mOutputPipeMap.get(key); mOutputPipeMap.remove(key); return executeInternal(data, input, output); } - - - }; @Override @@ -115,6 +69,4 @@ public class OpenPgpService2 extends OpenPgpService { return mBinder; } - - } -- cgit v1.2.3 From 8a780c9c492711af915a1e37d6e90a3c1df50552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Fri, 28 Aug 2015 17:46:57 +0200 Subject: Support OpenPGP API v9 --- .../keychain/remote/OpenPgpService.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index cc4a08fb4..57dd068ef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -66,8 +66,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashSet; +import java.util.List; public class OpenPgpService extends RemoteService { @@ -813,19 +815,14 @@ public class OpenPgpService extends RemoteService { } // version code is required and needs to correspond to version code of service! - // History of versions in org.openintents.openpgp.util.OpenPgpApi - // we support 3, 4, 5, 6 - if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != 3 - && data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != 4 - && data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != 5 - && data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != 6 - && data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != 7 - && data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != 8) { + // History of versions in openpgp-api's CHANGELOG.md + List supportedVersions = Arrays.asList(3, 4, 5, 6, 7, 8, 9); + if (!supportedVersions.contains(data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1))) { Intent result = new Intent(); OpenPgpError error = new OpenPgpError (OpenPgpError.INCOMPATIBLE_API_VERSIONS, "Incompatible API versions!\n" + "used API version: " + data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) + "\n" - + "supported API versions: 3-8"); + + "supported API versions: " + supportedVersions.toString()); result.putExtra(OpenPgpApi.RESULT_ERROR, error); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); return result; @@ -855,7 +852,6 @@ public class OpenPgpService extends RemoteService { } - protected Intent executeInternal(Intent data, ParcelFileDescriptor input, ParcelFileDescriptor output) { try { Intent errorResult = checkRequirements(data); -- cgit v1.2.3 From 3c25dc2b0c20d0bc24a60478779a007489faa5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Fri, 28 Aug 2015 17:47:56 +0200 Subject: Improve decrypt strings --- OpenKeychain/src/main/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index ddd29efb4..08e9ba022 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -1501,8 +1501,8 @@ "Error loading keys!" "(error, empty log)" "Could not read input to decrypt!" - ]]> - ]]> + Unknown filename (click to open) + Text (click to show) Show Signed/Encrypted Content "View in OpenKeychain" "Error preparing data!" -- cgit v1.2.3