mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
cleanup
This commit is contained in:
parent
1710f4416f
commit
a5e33097a6
@ -191,13 +191,9 @@ public class PgpOperationOutgoing {
|
|||||||
throws IOException, PgpGeneralException, PGPException, NoSuchProviderException,
|
throws IOException, PgpGeneralException, PGPException, NoSuchProviderException,
|
||||||
NoSuchAlgorithmException, SignatureException {
|
NoSuchAlgorithmException, SignatureException {
|
||||||
|
|
||||||
if (encryptionKeyIds == null) {
|
|
||||||
encryptionKeyIds = new long[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean enableSignature = signatureKeyId != Id.key.none;
|
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;
|
int signatureType;
|
||||||
if (enableAsciiArmorOutput && enableSignature && !enableEncryption && !enableCompression) {
|
if (enableAsciiArmorOutput && enableSignature && !enableEncryption && !enableCompression) {
|
||||||
@ -208,7 +204,6 @@ public class PgpOperationOutgoing {
|
|||||||
|
|
||||||
ArmoredOutputStream armorOut = null;
|
ArmoredOutputStream armorOut = null;
|
||||||
OutputStream out;
|
OutputStream out;
|
||||||
OutputStream encryptionOut = null;
|
|
||||||
if (enableAsciiArmorOutput) {
|
if (enableAsciiArmorOutput) {
|
||||||
armorOut = new ArmoredOutputStream(outStream);
|
armorOut = new ArmoredOutputStream(outStream);
|
||||||
armorOut.setHeader("Version", PgpHelper.getFullVersion(context));
|
armorOut.setHeader("Version", PgpHelper.getFullVersion(context));
|
||||||
@ -217,7 +212,7 @@ public class PgpOperationOutgoing {
|
|||||||
out = outStream;
|
out = outStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get keys for signature generation for later usage */
|
||||||
PGPSecretKey signingKey = null;
|
PGPSecretKey signingKey = null;
|
||||||
PGPSecretKeyRing signingKeyRing = null;
|
PGPSecretKeyRing signingKeyRing = null;
|
||||||
PGPPrivateKey signaturePrivateKey = null;
|
PGPPrivateKey signaturePrivateKey = null;
|
||||||
@ -245,7 +240,8 @@ public class PgpOperationOutgoing {
|
|||||||
}
|
}
|
||||||
updateProgress(R.string.progress_preparing_streams, 5, 100);
|
updateProgress(R.string.progress_preparing_streams, 5, 100);
|
||||||
|
|
||||||
// encrypt and compress input file content
|
/* Initialize PGPEncryptedDataGenerator for later usage */
|
||||||
|
PGPEncryptedDataGenerator cPk = null;
|
||||||
if (enableEncryption) {
|
if (enableEncryption) {
|
||||||
// has Integrity packet enabled!
|
// has Integrity packet enabled!
|
||||||
JcePGPDataEncryptorBuilder encryptorBuilder =
|
JcePGPDataEncryptorBuilder encryptorBuilder =
|
||||||
@ -253,7 +249,7 @@ public class PgpOperationOutgoing {
|
|||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME)
|
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME)
|
||||||
.setWithIntegrityPacket(true);
|
.setWithIntegrityPacket(true);
|
||||||
|
|
||||||
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(encryptorBuilder);
|
cPk = new PGPEncryptedDataGenerator(encryptorBuilder);
|
||||||
|
|
||||||
if (encryptionKeyIds.length == 0) {
|
if (encryptionKeyIds.length == 0) {
|
||||||
// Symmetric encryption
|
// Symmetric encryption
|
||||||
@ -267,16 +263,15 @@ public class PgpOperationOutgoing {
|
|||||||
for (long id : encryptionKeyIds) {
|
for (long id : encryptionKeyIds) {
|
||||||
PGPPublicKey key = PgpKeyHelper.getEncryptPublicKey(context, id);
|
PGPPublicKey key = PgpKeyHelper.getEncryptPublicKey(context, id);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
|
|
||||||
JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator =
|
JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator =
|
||||||
new JcePublicKeyKeyEncryptionMethodGenerator(key);
|
new JcePublicKeyKeyEncryptionMethodGenerator(key);
|
||||||
cPk.addMethod(pubKeyEncryptionGenerator);
|
cPk.addMethod(pubKeyEncryptionGenerator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
encryptionOut = cPk.open(out, new byte[1 << 16]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialize signature generator object for later usage */
|
||||||
PGPSignatureGenerator signatureGenerator = null;
|
PGPSignatureGenerator signatureGenerator = null;
|
||||||
PGPV3SignatureGenerator signatureV3Generator = null;
|
PGPV3SignatureGenerator signatureV3Generator = null;
|
||||||
if (enableSignature) {
|
if (enableSignature) {
|
||||||
@ -303,7 +298,10 @@ public class PgpOperationOutgoing {
|
|||||||
|
|
||||||
PGPCompressedDataGenerator compressGen = null;
|
PGPCompressedDataGenerator compressGen = null;
|
||||||
OutputStream pOut;
|
OutputStream pOut;
|
||||||
|
OutputStream encryptionOut = null;
|
||||||
if (enableEncryption) {
|
if (enableEncryption) {
|
||||||
|
encryptionOut = cPk.open(out, new byte[1 << 16]);
|
||||||
|
|
||||||
BCPGOutputStream bcpgOut;
|
BCPGOutputStream bcpgOut;
|
||||||
if (enableCompression) {
|
if (enableCompression) {
|
||||||
compressGen = new PGPCompressedDataGenerator(compressionId);
|
compressGen = new PGPCompressedDataGenerator(compressionId);
|
||||||
|
@ -136,11 +136,11 @@ public class OpenPgpService extends RemoteService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: asciiArmor?!
|
|
||||||
private Bundle signImpl(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output,
|
private Bundle signImpl(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output,
|
||||||
AppSettings appSettings) {
|
AppSettings appSettings) {
|
||||||
try {
|
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
|
// get passphrase from cache, if key has "no" passphrase, this returns an empty String
|
||||||
String passphrase;
|
String passphrase;
|
||||||
if (params.containsKey(OpenPgpConstants.PARAMS_PASSPHRASE)) {
|
if (params.containsKey(OpenPgpConstants.PARAMS_PASSPHRASE)) {
|
||||||
@ -163,7 +163,7 @@ public class OpenPgpService extends RemoteService {
|
|||||||
|
|
||||||
// sign-only
|
// sign-only
|
||||||
PgpOperationOutgoing.Builder builder = new PgpOperationOutgoing.Builder(getContext(), inputData, os);
|
PgpOperationOutgoing.Builder builder = new PgpOperationOutgoing.Builder(getContext(), inputData, os);
|
||||||
builder.enableAsciiArmorOutput(true)
|
builder.enableAsciiArmorOutput(asciiArmor)
|
||||||
.signatureHashAlgorithm(appSettings.getHashAlgorithm())
|
.signatureHashAlgorithm(appSettings.getHashAlgorithm())
|
||||||
.signatureForceV3(false)
|
.signatureForceV3(false)
|
||||||
.signatureKeyId(appSettings.getKeyId())
|
.signatureKeyId(appSettings.getKeyId())
|
||||||
@ -190,7 +190,7 @@ public class OpenPgpService extends RemoteService {
|
|||||||
ParcelFileDescriptor output, AppSettings appSettings,
|
ParcelFileDescriptor output, AppSettings appSettings,
|
||||||
boolean sign) {
|
boolean sign) {
|
||||||
try {
|
try {
|
||||||
boolean asciiArmor = params.getBoolean(OpenPgpConstants.PARAMS_REQUEST_ASCII_ARMOR, false);
|
boolean asciiArmor = params.getBoolean(OpenPgpConstants.PARAMS_REQUEST_ASCII_ARMOR, true);
|
||||||
|
|
||||||
long[] keyIds;
|
long[] keyIds;
|
||||||
if (params.containsKey(OpenPgpConstants.PARAMS_KEY_IDS)) {
|
if (params.containsKey(OpenPgpConstants.PARAMS_KEY_IDS)) {
|
||||||
@ -231,8 +231,6 @@ public class OpenPgpService extends RemoteService {
|
|||||||
builder.enableAsciiArmorOutput(asciiArmor)
|
builder.enableAsciiArmorOutput(asciiArmor)
|
||||||
.compressionId(appSettings.getCompression())
|
.compressionId(appSettings.getCompression())
|
||||||
.symmetricEncryptionAlgorithm(appSettings.getEncryptionAlgorithm())
|
.symmetricEncryptionAlgorithm(appSettings.getEncryptionAlgorithm())
|
||||||
.signatureHashAlgorithm(appSettings.getHashAlgorithm())
|
|
||||||
.signatureForceV3(false)
|
|
||||||
.encryptionKeyIds(keyIds);
|
.encryptionKeyIds(keyIds);
|
||||||
|
|
||||||
if (sign) {
|
if (sign) {
|
||||||
@ -250,7 +248,9 @@ public class OpenPgpService extends RemoteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sign and encrypt
|
// sign and encrypt
|
||||||
builder.signatureKeyId(appSettings.getKeyId())
|
builder.signatureHashAlgorithm(appSettings.getHashAlgorithm())
|
||||||
|
.signatureForceV3(false)
|
||||||
|
.signatureKeyId(appSettings.getKeyId())
|
||||||
.signaturePassphrase(passphrase);
|
.signaturePassphrase(passphrase);
|
||||||
} else {
|
} else {
|
||||||
// encrypt only
|
// encrypt only
|
||||||
|
Loading…
Reference in New Issue
Block a user