From 89d016c49be3d9258822f2803744697a0d48c80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sun, 8 Nov 2015 20:02:50 +0100 Subject: Get whole public key via ACTION_GET_KEY --- .../keychain/remote/OpenPgpService.java | 44 +++++++++++++++++++--- extern/openpgp-api-lib | 2 +- 2 files changed, 39 insertions(+), 7 deletions(-) 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 e7709e58e..7dfb3f3f6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -25,7 +25,6 @@ import android.net.Uri; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.Parcelable; -import android.support.annotation.Nullable; import android.text.TextUtils; import org.openintents.openpgp.IOpenPgpService; @@ -34,13 +33,15 @@ import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpApi; +import org.spongycastle.bcpg.ArmoredOutputStream; 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.PgpSecurityConstants; -import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; +import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; +import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; +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; @@ -684,16 +685,47 @@ public class OpenPgpService extends RemoteService { } - private Intent getKeyImpl(Intent data) { + private Intent getKeyImpl(Intent data, ParcelFileDescriptor output) { try { long masterKeyId = data.getLongExtra(OpenPgpApi.EXTRA_KEY_ID, 0); + // output is optional, for getting the key + OutputStream outputStream = + (output != null) ? new ParcelFileDescriptor.AutoCloseOutputStream(output) : null; + try { // try to find key, throws NotFoundException if not in db! - mProviderHelper.getCanonicalizedPublicKeyRing(masterKeyId); + CanonicalizedPublicKeyRing keyRing = + mProviderHelper.getCanonicalizedPublicKeyRing(masterKeyId); Intent result = new Intent(); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); + + // return public key if requested by defining a output stream + if (outputStream != null) { + boolean requestAsciiArmor = + data.getBooleanExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, false); + + ArmoredOutputStream arOutStream = null; + try { + if (requestAsciiArmor) { + arOutStream = new ArmoredOutputStream(outputStream); + keyRing.encode(arOutStream); + } else { + keyRing.encode(outputStream); + } + } finally { + try { + if (arOutStream != null) { + arOutStream.close(); + } + outputStream.close(); + } catch (IOException e) { + Log.e(Constants.TAG, "IOException when closing OutputStream", e); + } + } + } + // also return PendingIntent that opens the key view activity result.putExtra(OpenPgpApi.RESULT_INTENT, getShowKeyPendingIntent(masterKeyId)); @@ -890,7 +922,7 @@ public class OpenPgpService extends RemoteService { return getKeyIdsImpl(data); } case OpenPgpApi.ACTION_GET_KEY: { - return getKeyImpl(data); + return getKeyImpl(data, output); } default: { return null; diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib index 0ba256969..04b9c31dc 160000 --- a/extern/openpgp-api-lib +++ b/extern/openpgp-api-lib @@ -1 +1 @@ -Subproject commit 0ba25696981a4c4d5aef01e4a1d683c8adf7522a +Subproject commit 04b9c31dc7800307184c1561d0a3f86bfb56e11a -- cgit v1.2.3