Decrypt metadata api
This commit is contained in:
@@ -71,7 +71,7 @@ public class PgpDecryptVerify {
|
|||||||
private boolean mAllowSymmetricDecryption;
|
private boolean mAllowSymmetricDecryption;
|
||||||
private String mPassphrase;
|
private String mPassphrase;
|
||||||
private Set<Long> mAllowedKeyIds;
|
private Set<Long> mAllowedKeyIds;
|
||||||
private boolean mReturnMetadataOnly;
|
private boolean mDecryptMetadataOnly;
|
||||||
|
|
||||||
private PgpDecryptVerify(Builder builder) {
|
private PgpDecryptVerify(Builder builder) {
|
||||||
// private Constructor can only be called from Builder
|
// private Constructor can only be called from Builder
|
||||||
@@ -84,7 +84,7 @@ public class PgpDecryptVerify {
|
|||||||
this.mAllowSymmetricDecryption = builder.mAllowSymmetricDecryption;
|
this.mAllowSymmetricDecryption = builder.mAllowSymmetricDecryption;
|
||||||
this.mPassphrase = builder.mPassphrase;
|
this.mPassphrase = builder.mPassphrase;
|
||||||
this.mAllowedKeyIds = builder.mAllowedKeyIds;
|
this.mAllowedKeyIds = builder.mAllowedKeyIds;
|
||||||
this.mReturnMetadataOnly = builder.mReturnMetadataOnly;
|
this.mDecryptMetadataOnly = builder.mDecryptMetadataOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
@@ -99,7 +99,7 @@ public class PgpDecryptVerify {
|
|||||||
private boolean mAllowSymmetricDecryption = true;
|
private boolean mAllowSymmetricDecryption = true;
|
||||||
private String mPassphrase = null;
|
private String mPassphrase = null;
|
||||||
private Set<Long> mAllowedKeyIds = null;
|
private Set<Long> mAllowedKeyIds = null;
|
||||||
private boolean mReturnMetadataOnly = false;
|
private boolean mDecryptMetadataOnly = false;
|
||||||
|
|
||||||
public Builder(ProviderHelper providerHelper, PassphraseCache passphraseCache,
|
public Builder(ProviderHelper providerHelper, PassphraseCache passphraseCache,
|
||||||
InputData data, OutputStream outStream) {
|
InputData data, OutputStream outStream) {
|
||||||
@@ -137,8 +137,8 @@ public class PgpDecryptVerify {
|
|||||||
* If enabled, the actual decryption/verification of the content will not be executed.
|
* If enabled, the actual decryption/verification of the content will not be executed.
|
||||||
* The metadata only will be decrypted and returned.
|
* The metadata only will be decrypted and returned.
|
||||||
*/
|
*/
|
||||||
public Builder setReturnMetadataOnly(boolean returnMetadataOnly) {
|
public Builder setDecryptMetadataOnly(boolean decryptMetadataOnly) {
|
||||||
mReturnMetadataOnly = returnMetadataOnly;
|
mDecryptMetadataOnly = decryptMetadataOnly;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +470,7 @@ public class PgpDecryptVerify {
|
|||||||
Log.d(Constants.TAG, "metadata: " + metadata);
|
Log.d(Constants.TAG, "metadata: " + metadata);
|
||||||
|
|
||||||
// return here if we want to decrypt the metadata only
|
// return here if we want to decrypt the metadata only
|
||||||
if (mReturnMetadataOnly) {
|
if (mDecryptMetadataOnly) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.os.IBinder;
|
|||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
|
||||||
import org.openintents.openpgp.IOpenPgpService;
|
import org.openintents.openpgp.IOpenPgpService;
|
||||||
|
import org.openintents.openpgp.OpenPgpDecryptMetadata;
|
||||||
import org.openintents.openpgp.OpenPgpError;
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
@@ -326,7 +327,8 @@ public class OpenPgpService extends RemoteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Intent decryptAndVerifyImpl(Intent data, ParcelFileDescriptor input,
|
private Intent decryptAndVerifyImpl(Intent data, ParcelFileDescriptor input,
|
||||||
ParcelFileDescriptor output, Set<Long> allowedKeyIds) {
|
ParcelFileDescriptor output, Set<Long> allowedKeyIds,
|
||||||
|
boolean decryptMetadataOnly) {
|
||||||
try {
|
try {
|
||||||
// Get Input- and OutputStream from ParcelFileDescriptor
|
// Get Input- and OutputStream from ParcelFileDescriptor
|
||||||
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
|
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
|
||||||
@@ -353,7 +355,8 @@ public class OpenPgpService extends RemoteService {
|
|||||||
builder.setAllowSymmetricDecryption(false) // no support for symmetric encryption
|
builder.setAllowSymmetricDecryption(false) // no support for symmetric encryption
|
||||||
.setAllowedKeyIds(allowedKeyIds) // allow only private keys associated with
|
.setAllowedKeyIds(allowedKeyIds) // allow only private keys associated with
|
||||||
// accounts of this app
|
// accounts of this app
|
||||||
.setPassphrase(passphrase);
|
.setPassphrase(passphrase)
|
||||||
|
.setDecryptMetadataOnly(decryptMetadataOnly);
|
||||||
|
|
||||||
PgpDecryptVerifyResult decryptVerifyResult;
|
PgpDecryptVerifyResult decryptVerifyResult;
|
||||||
try {
|
try {
|
||||||
@@ -403,6 +406,11 @@ public class OpenPgpService extends RemoteService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpenPgpDecryptMetadata metadata = decryptVerifyResult.getDecryptMetadata();
|
||||||
|
if (metadata != null) {
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_METADATA, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
is.close();
|
is.close();
|
||||||
os.close();
|
os.close();
|
||||||
@@ -561,7 +569,13 @@ public class OpenPgpService extends RemoteService {
|
|||||||
Set<Long> allowedKeyIds =
|
Set<Long> allowedKeyIds =
|
||||||
mProviderHelper.getAllKeyIdsForApp(
|
mProviderHelper.getAllKeyIdsForApp(
|
||||||
ApiAccounts.buildBaseUri(currentPkg));
|
ApiAccounts.buildBaseUri(currentPkg));
|
||||||
return decryptAndVerifyImpl(data, input, output, allowedKeyIds);
|
return decryptAndVerifyImpl(data, input, output, allowedKeyIds, false);
|
||||||
|
} else if (OpenPgpApi.ACTION_DECRYPT_METADATA.equals(action)) {
|
||||||
|
String currentPkg = getCurrentCallingPackage();
|
||||||
|
Set<Long> allowedKeyIds =
|
||||||
|
mProviderHelper.getAllKeyIdsForApp(
|
||||||
|
ApiAccounts.buildBaseUri(currentPkg));
|
||||||
|
return decryptAndVerifyImpl(data, input, output, allowedKeyIds, true);
|
||||||
} else if (OpenPgpApi.ACTION_GET_KEY.equals(action)) {
|
} else if (OpenPgpApi.ACTION_GET_KEY.equals(action)) {
|
||||||
return getKeyImpl(data);
|
return getKeyImpl(data);
|
||||||
} else if (OpenPgpApi.ACTION_GET_KEY_IDS.equals(action)) {
|
} else if (OpenPgpApi.ACTION_GET_KEY_IDS.equals(action)) {
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ public class KeychainIntentService extends IntentService
|
|||||||
builder.setProgressable(this)
|
builder.setProgressable(this)
|
||||||
.setAllowSymmetricDecryption(true)
|
.setAllowSymmetricDecryption(true)
|
||||||
.setPassphrase(passphrase)
|
.setPassphrase(passphrase)
|
||||||
.setReturnMetadataOnly(true);
|
.setDecryptMetadataOnly(true);
|
||||||
|
|
||||||
PgpDecryptVerifyResult decryptVerifyResult = builder.build().execute();
|
PgpDecryptVerifyResult decryptVerifyResult = builder.build().execute();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user