diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-11-08 20:02:50 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-11-08 20:02:50 +0100 |
commit | 89d016c49be3d9258822f2803744697a0d48c80b (patch) | |
tree | 7c9f0b048e6ccc7531420671c0e53265fae87aeb /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote | |
parent | 2f640980dd17b8641afe815c46800a3b9411dd2f (diff) | |
download | open-keychain-89d016c49be3d9258822f2803744697a0d48c80b.tar.gz open-keychain-89d016c49be3d9258822f2803744697a0d48c80b.tar.bz2 open-keychain-89d016c49be3d9258822f2803744697a0d48c80b.zip |
Get whole public key via ACTION_GET_KEY
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java | 44 |
1 files changed, 38 insertions, 6 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; |