This commit is contained in:
Dominik Schürmann 2014-02-19 10:47:13 +01:00
parent 1710f4416f
commit a5e33097a6
2 changed files with 17 additions and 19 deletions

View File

@ -191,13 +191,9 @@ public class PgpOperationOutgoing {
throws IOException, PgpGeneralException, PGPException, NoSuchProviderException,
NoSuchAlgorithmException, SignatureException {
if (encryptionKeyIds == null) {
encryptionKeyIds = new long[0];
}
boolean enableSignature = signatureKeyId != Id.key.none;
boolean enableCompression = compressionId != Id.choice.compression.none;
boolean enableEncryption = encryptionKeyIds.length != 0 || encryptionPassphrase != null;
boolean enableEncryption = (encryptionKeyIds.length != 0 || encryptionPassphrase != null);
boolean enableCompression = (enableEncryption && compressionId != Id.choice.compression.none);
int signatureType;
if (enableAsciiArmorOutput && enableSignature && !enableEncryption && !enableCompression) {
@ -208,7 +204,6 @@ public class PgpOperationOutgoing {
ArmoredOutputStream armorOut = null;
OutputStream out;
OutputStream encryptionOut = null;
if (enableAsciiArmorOutput) {
armorOut = new ArmoredOutputStream(outStream);
armorOut.setHeader("Version", PgpHelper.getFullVersion(context));
@ -217,7 +212,7 @@ public class PgpOperationOutgoing {
out = outStream;
}
/* Get keys for signature generation for later usage */
PGPSecretKey signingKey = null;
PGPSecretKeyRing signingKeyRing = null;
PGPPrivateKey signaturePrivateKey = null;
@ -245,7 +240,8 @@ public class PgpOperationOutgoing {
}
updateProgress(R.string.progress_preparing_streams, 5, 100);
// encrypt and compress input file content
/* Initialize PGPEncryptedDataGenerator for later usage */
PGPEncryptedDataGenerator cPk = null;
if (enableEncryption) {
// has Integrity packet enabled!
JcePGPDataEncryptorBuilder encryptorBuilder =
@ -253,7 +249,7 @@ public class PgpOperationOutgoing {
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME)
.setWithIntegrityPacket(true);
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(encryptorBuilder);
cPk = new PGPEncryptedDataGenerator(encryptorBuilder);
if (encryptionKeyIds.length == 0) {
// Symmetric encryption
@ -267,16 +263,15 @@ public class PgpOperationOutgoing {
for (long id : encryptionKeyIds) {
PGPPublicKey key = PgpKeyHelper.getEncryptPublicKey(context, id);
if (key != null) {
JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator =
new JcePublicKeyKeyEncryptionMethodGenerator(key);
cPk.addMethod(pubKeyEncryptionGenerator);
}
}
}
encryptionOut = cPk.open(out, new byte[1 << 16]);
}
/* Initialize signature generator object for later usage */
PGPSignatureGenerator signatureGenerator = null;
PGPV3SignatureGenerator signatureV3Generator = null;
if (enableSignature) {
@ -303,7 +298,10 @@ public class PgpOperationOutgoing {
PGPCompressedDataGenerator compressGen = null;
OutputStream pOut;
OutputStream encryptionOut = null;
if (enableEncryption) {
encryptionOut = cPk.open(out, new byte[1 << 16]);
BCPGOutputStream bcpgOut;
if (enableCompression) {
compressGen = new PGPCompressedDataGenerator(compressionId);

View File

@ -136,11 +136,11 @@ public class OpenPgpService extends RemoteService {
return result;
}
// TODO: asciiArmor?!
private Bundle signImpl(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output,
AppSettings appSettings) {
try {
boolean asciiArmor = params.getBoolean(OpenPgpConstants.PARAMS_REQUEST_ASCII_ARMOR, true);
// get passphrase from cache, if key has "no" passphrase, this returns an empty String
String passphrase;
if (params.containsKey(OpenPgpConstants.PARAMS_PASSPHRASE)) {
@ -163,7 +163,7 @@ public class OpenPgpService extends RemoteService {
// sign-only
PgpOperationOutgoing.Builder builder = new PgpOperationOutgoing.Builder(getContext(), inputData, os);
builder.enableAsciiArmorOutput(true)
builder.enableAsciiArmorOutput(asciiArmor)
.signatureHashAlgorithm(appSettings.getHashAlgorithm())
.signatureForceV3(false)
.signatureKeyId(appSettings.getKeyId())
@ -190,7 +190,7 @@ public class OpenPgpService extends RemoteService {
ParcelFileDescriptor output, AppSettings appSettings,
boolean sign) {
try {
boolean asciiArmor = params.getBoolean(OpenPgpConstants.PARAMS_REQUEST_ASCII_ARMOR, false);
boolean asciiArmor = params.getBoolean(OpenPgpConstants.PARAMS_REQUEST_ASCII_ARMOR, true);
long[] keyIds;
if (params.containsKey(OpenPgpConstants.PARAMS_KEY_IDS)) {
@ -231,8 +231,6 @@ public class OpenPgpService extends RemoteService {
builder.enableAsciiArmorOutput(asciiArmor)
.compressionId(appSettings.getCompression())
.symmetricEncryptionAlgorithm(appSettings.getEncryptionAlgorithm())
.signatureHashAlgorithm(appSettings.getHashAlgorithm())
.signatureForceV3(false)
.encryptionKeyIds(keyIds);
if (sign) {
@ -250,7 +248,9 @@ public class OpenPgpService extends RemoteService {
}
// sign and encrypt
builder.signatureKeyId(appSettings.getKeyId())
builder.signatureHashAlgorithm(appSettings.getHashAlgorithm())
.signatureForceV3(false)
.signatureKeyId(appSettings.getKeyId())
.signaturePassphrase(passphrase);
} else {
// encrypt only