mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-25 16:01:52 -05:00
Add support for multiple input/output URIs to KeychainIntentService
This commit is contained in:
parent
93eae114ea
commit
51a4b0466b
@ -109,6 +109,9 @@ public class KeychainIntentService extends IntentService
|
|||||||
public static final int IO_BYTES = 1;
|
public static final int IO_BYTES = 1;
|
||||||
public static final int IO_FILE = 2; // This was misleadingly TARGET_URI before!
|
public static final int IO_FILE = 2; // This was misleadingly TARGET_URI before!
|
||||||
public static final int IO_URI = 3;
|
public static final int IO_URI = 3;
|
||||||
|
public static final int IO_URIS = 4;
|
||||||
|
|
||||||
|
public static final String SELECTED_URI = "selected_uri";
|
||||||
|
|
||||||
// encrypt
|
// encrypt
|
||||||
public static final String ENCRYPT_SIGNATURE_KEY_ID = "secret_key_id";
|
public static final String ENCRYPT_SIGNATURE_KEY_ID = "secret_key_id";
|
||||||
@ -118,8 +121,10 @@ public class KeychainIntentService extends IntentService
|
|||||||
public static final String ENCRYPT_MESSAGE_BYTES = "message_bytes";
|
public static final String ENCRYPT_MESSAGE_BYTES = "message_bytes";
|
||||||
public static final String ENCRYPT_INPUT_FILE = "input_file";
|
public static final String ENCRYPT_INPUT_FILE = "input_file";
|
||||||
public static final String ENCRYPT_INPUT_URI = "input_uri";
|
public static final String ENCRYPT_INPUT_URI = "input_uri";
|
||||||
|
public static final String ENCRYPT_INPUT_URIS = "input_uris";
|
||||||
public static final String ENCRYPT_OUTPUT_FILE = "output_file";
|
public static final String ENCRYPT_OUTPUT_FILE = "output_file";
|
||||||
public static final String ENCRYPT_OUTPUT_URI = "output_uri";
|
public static final String ENCRYPT_OUTPUT_URI = "output_uri";
|
||||||
|
public static final String ENCRYPT_OUTPUT_URIS = "output_uris";
|
||||||
public static final String ENCRYPT_SYMMETRIC_PASSPHRASE = "passphrase";
|
public static final String ENCRYPT_SYMMETRIC_PASSPHRASE = "passphrase";
|
||||||
|
|
||||||
// decrypt/verify
|
// decrypt/verify
|
||||||
@ -220,6 +225,7 @@ public class KeychainIntentService extends IntentService
|
|||||||
try {
|
try {
|
||||||
/* Input */
|
/* Input */
|
||||||
int source = data.get(SOURCE) != null ? data.getInt(SOURCE) : data.getInt(TARGET);
|
int source = data.get(SOURCE) != null ? data.getInt(SOURCE) : data.getInt(TARGET);
|
||||||
|
Bundle resultData = new Bundle();
|
||||||
|
|
||||||
long signatureKeyId = data.getLong(ENCRYPT_SIGNATURE_KEY_ID);
|
long signatureKeyId = data.getLong(ENCRYPT_SIGNATURE_KEY_ID);
|
||||||
String symmetricPassphrase = data.getString(ENCRYPT_SYMMETRIC_PASSPHRASE);
|
String symmetricPassphrase = data.getString(ENCRYPT_SYMMETRIC_PASSPHRASE);
|
||||||
@ -227,45 +233,49 @@ public class KeychainIntentService extends IntentService
|
|||||||
boolean useAsciiArmor = data.getBoolean(ENCRYPT_USE_ASCII_ARMOR);
|
boolean useAsciiArmor = data.getBoolean(ENCRYPT_USE_ASCII_ARMOR);
|
||||||
long encryptionKeyIds[] = data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS);
|
long encryptionKeyIds[] = data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS);
|
||||||
int compressionId = data.getInt(ENCRYPT_COMPRESSION_ID);
|
int compressionId = data.getInt(ENCRYPT_COMPRESSION_ID);
|
||||||
InputData inputData = createEncryptInputData(data);
|
int urisCount = data.containsKey(ENCRYPT_INPUT_URIS) ? data.getParcelableArrayList(ENCRYPT_INPUT_URIS).size() : 1;
|
||||||
OutputStream outStream = createCryptOutputStream(data);
|
for (int i = 0; i < urisCount; i++) {
|
||||||
|
data.putInt(SELECTED_URI, i);
|
||||||
|
InputData inputData = createEncryptInputData(data);
|
||||||
|
OutputStream outStream = createCryptOutputStream(data);
|
||||||
|
|
||||||
/* Operation */
|
/* Operation */
|
||||||
PgpSignEncrypt.Builder builder =
|
PgpSignEncrypt.Builder builder =
|
||||||
new PgpSignEncrypt.Builder(
|
new PgpSignEncrypt.Builder(
|
||||||
new ProviderHelper(this),
|
new ProviderHelper(this),
|
||||||
PgpHelper.getFullVersion(this),
|
PgpHelper.getFullVersion(this),
|
||||||
inputData, outStream);
|
inputData, outStream);
|
||||||
builder.setProgressable(this);
|
builder.setProgressable(this);
|
||||||
|
|
||||||
builder.setEnableAsciiArmorOutput(useAsciiArmor)
|
builder.setEnableAsciiArmorOutput(useAsciiArmor)
|
||||||
.setCompressionId(compressionId)
|
.setCompressionId(compressionId)
|
||||||
.setSymmetricEncryptionAlgorithm(
|
.setSymmetricEncryptionAlgorithm(
|
||||||
Preferences.getPreferences(this).getDefaultEncryptionAlgorithm())
|
Preferences.getPreferences(this).getDefaultEncryptionAlgorithm())
|
||||||
.setSignatureForceV3(Preferences.getPreferences(this).getForceV3Signatures())
|
.setSignatureForceV3(Preferences.getPreferences(this).getForceV3Signatures())
|
||||||
.setEncryptionMasterKeyIds(encryptionKeyIds)
|
.setEncryptionMasterKeyIds(encryptionKeyIds)
|
||||||
.setSymmetricPassphrase(symmetricPassphrase)
|
.setSymmetricPassphrase(symmetricPassphrase)
|
||||||
.setSignatureMasterKeyId(signatureKeyId)
|
.setSignatureMasterKeyId(signatureKeyId)
|
||||||
.setEncryptToSigner(true)
|
.setEncryptToSigner(true)
|
||||||
.setSignatureHashAlgorithm(
|
.setSignatureHashAlgorithm(
|
||||||
Preferences.getPreferences(this).getDefaultHashAlgorithm())
|
Preferences.getPreferences(this).getDefaultHashAlgorithm())
|
||||||
.setSignaturePassphrase(
|
.setSignaturePassphrase(
|
||||||
PassphraseCacheService.getCachedPassphrase(this, signatureKeyId));
|
PassphraseCacheService.getCachedPassphrase(this, signatureKeyId));
|
||||||
|
|
||||||
|
// this assumes that the bytes are cleartext (valid for current implementation!)
|
||||||
|
if (source == IO_BYTES) {
|
||||||
|
builder.setCleartextInput(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.build().execute();
|
||||||
|
|
||||||
|
outStream.close();
|
||||||
|
|
||||||
|
/* Output */
|
||||||
|
|
||||||
|
finalizeEncryptOutputStream(data, resultData, outStream);
|
||||||
|
|
||||||
// this assumes that the bytes are cleartext (valid for current implementation!)
|
|
||||||
if (source == IO_BYTES) {
|
|
||||||
builder.setCleartextInput(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.build().execute();
|
|
||||||
|
|
||||||
outStream.close();
|
|
||||||
|
|
||||||
/* Output */
|
|
||||||
|
|
||||||
Bundle resultData = new Bundle();
|
|
||||||
finalizeEncryptOutputStream(data, resultData, outStream);
|
|
||||||
|
|
||||||
OtherHelper.logDebugBundle(resultData, "resultData");
|
OtherHelper.logDebugBundle(resultData, "resultData");
|
||||||
|
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
|
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
|
||||||
@ -688,8 +698,13 @@ public class KeychainIntentService extends IntentService
|
|||||||
Uri providerUri = data.getParcelable(ENCRYPT_INPUT_URI);
|
Uri providerUri = data.getParcelable(ENCRYPT_INPUT_URI);
|
||||||
|
|
||||||
// InputStream
|
// InputStream
|
||||||
InputStream in = getContentResolver().openInputStream(providerUri);
|
return new InputData(getContentResolver().openInputStream(providerUri), 0);
|
||||||
return new InputData(in, 0);
|
|
||||||
|
case IO_URIS:
|
||||||
|
providerUri = data.<Uri>getParcelableArrayList(ENCRYPT_INPUT_URIS).get(data.getInt(SELECTED_URI));
|
||||||
|
|
||||||
|
// InputStream
|
||||||
|
return new InputData(getContentResolver().openInputStream(providerUri), 0);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new PgpGeneralException("No target choosen!");
|
throw new PgpGeneralException("No target choosen!");
|
||||||
@ -719,6 +734,11 @@ public class KeychainIntentService extends IntentService
|
|||||||
|
|
||||||
return getContentResolver().openOutputStream(providerUri);
|
return getContentResolver().openOutputStream(providerUri);
|
||||||
|
|
||||||
|
case IO_URIS:
|
||||||
|
providerUri = data.<Uri>getParcelableArrayList(ENCRYPT_OUTPUT_URIS).get(data.getInt(SELECTED_URI));
|
||||||
|
|
||||||
|
return getContentResolver().openOutputStream(providerUri);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new PgpGeneralException("No target choosen!");
|
throw new PgpGeneralException("No target choosen!");
|
||||||
}
|
}
|
||||||
@ -744,6 +764,7 @@ public class KeychainIntentService extends IntentService
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case IO_URI:
|
case IO_URI:
|
||||||
|
case IO_URIS:
|
||||||
// nothing, output was written, just send okay and verification bundle
|
// nothing, output was written, just send okay and verification bundle
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user