internal renaming, cleanup

This commit is contained in:
Dominik Schürmann 2014-02-21 02:40:44 +01:00
parent aaddd26b51
commit fb0816c126
5 changed files with 50 additions and 36 deletions

View File

@ -70,7 +70,7 @@ import java.util.Iterator;
/** /**
* This class uses a Builder pattern! * This class uses a Builder pattern!
*/ */
public class PgpOperationIncoming { public class PgpDecryptVerify {
private Context context; private Context context;
private InputData data; private InputData data;
private OutputStream outStream; private OutputStream outStream;
@ -79,7 +79,7 @@ public class PgpOperationIncoming {
boolean assumeSymmetric; boolean assumeSymmetric;
String passphrase; String passphrase;
private PgpOperationIncoming(Builder builder) { private PgpDecryptVerify(Builder builder) {
// private Constructor can only be called from Builder // private Constructor can only be called from Builder
this.context = builder.context; this.context = builder.context;
this.data = builder.data; this.data = builder.data;
@ -122,8 +122,8 @@ public class PgpOperationIncoming {
return this; return this;
} }
public PgpOperationIncoming build() { public PgpDecryptVerify build() {
return new PgpOperationIncoming(this); return new PgpDecryptVerify(this);
} }
} }
@ -177,9 +177,8 @@ public class PgpOperationIncoming {
* @throws PGPException * @throws PGPException
* @throws SignatureException * @throws SignatureException
*/ */
public Bundle decryptVerify() public Bundle execute()
throws IOException, PgpGeneralException, PGPException, SignatureException { throws IOException, PgpGeneralException, PGPException, SignatureException {
Bundle returnData = new Bundle();
// automatically works with ascii armor input and binary // automatically works with ascii armor input and binary
InputStream in = PGPUtil.getDecoderStream(data.getInputStream()); InputStream in = PGPUtil.getDecoderStream(data.getInputStream());
@ -191,14 +190,30 @@ public class PgpOperationIncoming {
if (aIn.isClearText()) { if (aIn.isClearText()) {
// a cleartext signature, verify it with the other method // a cleartext signature, verify it with the other method
return verifyCleartextSignature(aIn); return verifyCleartextSignature(aIn);
} else {
// go on...
} }
// else: ascii armored encryption! go on...
} }
return decryptVerify(in);
}
/**
* Decrypt and/or verifies binary or ascii armored pgp
*
* @param in
* @return
* @throws IOException
* @throws PgpGeneralException
* @throws PGPException
* @throws SignatureException
*/
private Bundle decryptVerify(InputStream in)
throws IOException, PgpGeneralException, PGPException, SignatureException {
Bundle returnData = new Bundle();
PGPObjectFactory pgpF = new PGPObjectFactory(in); PGPObjectFactory pgpF = new PGPObjectFactory(in);
PGPEncryptedDataList enc; PGPEncryptedDataList enc;
Object o = pgpF.nextObject(); Object o = pgpF.nextObject();
Log.d(Constants.TAG, "o: " + o.getClass().getName());
int currentProgress = 0; int currentProgress = 0;
updateProgress(R.string.progress_reading_data, currentProgress, 100); updateProgress(R.string.progress_reading_data, currentProgress, 100);

View File

@ -62,7 +62,7 @@ import java.util.Date;
/** /**
* This class uses a Builder pattern! * This class uses a Builder pattern!
*/ */
public class PgpOperationOutgoing { public class PgpSignEncrypt {
private Context context; private Context context;
private InputData data; private InputData data;
private OutputStream outStream; private OutputStream outStream;
@ -78,7 +78,7 @@ public class PgpOperationOutgoing {
private boolean signatureForceV3; private boolean signatureForceV3;
private String signaturePassphrase; private String signaturePassphrase;
private PgpOperationOutgoing(Builder builder) { private PgpSignEncrypt(Builder builder) {
// private Constructor can only be called from Builder // private Constructor can only be called from Builder
this.context = builder.context; this.context = builder.context;
this.data = builder.data; this.data = builder.data;
@ -170,8 +170,8 @@ public class PgpOperationOutgoing {
return this; return this;
} }
public PgpOperationOutgoing build() { public PgpSignEncrypt build() {
return new PgpOperationOutgoing(this); return new PgpSignEncrypt(this);
} }
} }
@ -197,7 +197,7 @@ public class PgpOperationOutgoing {
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
* @throws SignatureException * @throws SignatureException
*/ */
public void signEncrypt() public void execute()
throws IOException, PgpGeneralException, PGPException, NoSuchProviderException, throws IOException, PgpGeneralException, PGPException, NoSuchProviderException,
NoSuchAlgorithmException, SignatureException { NoSuchAlgorithmException, SignatureException {
@ -442,7 +442,7 @@ public class PgpOperationOutgoing {
updateProgress(R.string.progress_done, 100, 100); updateProgress(R.string.progress_done, 100, 100);
} }
// TODO: merge this into signEncrypt method! // TODO: merge this into execute method!
// TODO: allow binary input for this class // TODO: allow binary input for this class
public void generateSignature() public void generateSignature()
throws PgpGeneralException, PGPException, IOException, NoSuchAlgorithmException, throws PgpGeneralException, PGPException, IOException, NoSuchAlgorithmException,

View File

@ -43,11 +43,11 @@ import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.helper.OtherHelper; import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpImportExport; import org.sufficientlysecure.keychain.pgp.PgpImportExport;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.PgpOperationIncoming; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.pgp.PgpOperationOutgoing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.DataStream; import org.sufficientlysecure.keychain.provider.KeychainContract.DataStream;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -317,8 +317,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} }
/* Operation */ /* Operation */
PgpOperationOutgoing.Builder builder = PgpSignEncrypt.Builder builder =
new PgpOperationOutgoing.Builder(this, inputData, outStream); new PgpSignEncrypt.Builder(this, inputData, outStream);
builder.progress(this); builder.progress(this);
if (generateSignature) { if (generateSignature) {
@ -338,7 +338,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
.signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm()) .signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm())
.signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId)); .signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
builder.build().signEncrypt(); builder.build().execute();
} else { } else {
Log.d(Constants.TAG, "encrypt..."); Log.d(Constants.TAG, "encrypt...");
builder.enableAsciiArmorOutput(useAsciiArmor) builder.enableAsciiArmorOutput(useAsciiArmor)
@ -351,7 +351,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
.signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm()) .signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm())
.signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId)); .signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
builder.build().signEncrypt(); builder.build().execute();
} }
outStream.close(); outStream.close();
@ -480,13 +480,13 @@ public class KeychainIntentService extends IntentService implements ProgressDial
// verifyText and decrypt returning additional resultData values for the // verifyText and decrypt returning additional resultData values for the
// verification of signatures // verification of signatures
PgpOperationIncoming.Builder builder = new PgpOperationIncoming.Builder(this, inputData, outStream); PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, outStream);
builder.progress(this); builder.progress(this);
builder.assumeSymmetric(assumeSymmetricEncryption) builder.assumeSymmetric(assumeSymmetricEncryption)
.passphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId)); .passphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
resultData = builder.build().decryptVerify(); resultData = builder.build().execute();
outStream.close(); outStream.close();

View File

@ -32,8 +32,8 @@ import org.openintents.openpgp.util.OpenPgpConstants;
import org.spongycastle.util.Arrays; import org.spongycastle.util.Arrays;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.pgp.PgpOperationOutgoing; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpOperationIncoming; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.PassphraseCacheService;
@ -162,13 +162,13 @@ public class OpenPgpService extends RemoteService {
InputData inputData = new InputData(is, inputLength); InputData inputData = new InputData(is, inputLength);
// sign-only // sign-only
PgpOperationOutgoing.Builder builder = new PgpOperationOutgoing.Builder(getContext(), inputData, os); PgpSignEncrypt.Builder builder = new PgpSignEncrypt.Builder(getContext(), inputData, os);
builder.enableAsciiArmorOutput(asciiArmor) builder.enableAsciiArmorOutput(asciiArmor)
.signatureHashAlgorithm(appSettings.getHashAlgorithm()) .signatureHashAlgorithm(appSettings.getHashAlgorithm())
.signatureForceV3(false) .signatureForceV3(false)
.signatureKeyId(appSettings.getKeyId()) .signatureKeyId(appSettings.getKeyId())
.signaturePassphrase(passphrase); .signaturePassphrase(passphrase);
builder.build().signEncrypt(); builder.build().execute();
} finally { } finally {
is.close(); is.close();
os.close(); os.close();
@ -227,7 +227,7 @@ public class OpenPgpService extends RemoteService {
long inputLength = is.available(); long inputLength = is.available();
InputData inputData = new InputData(is, inputLength); InputData inputData = new InputData(is, inputLength);
PgpOperationOutgoing.Builder builder = new PgpOperationOutgoing.Builder(getContext(), inputData, os); PgpSignEncrypt.Builder builder = new PgpSignEncrypt.Builder(getContext(), inputData, os);
builder.enableAsciiArmorOutput(asciiArmor) builder.enableAsciiArmorOutput(asciiArmor)
.compressionId(appSettings.getCompression()) .compressionId(appSettings.getCompression())
.symmetricEncryptionAlgorithm(appSettings.getEncryptionAlgorithm()) .symmetricEncryptionAlgorithm(appSettings.getEncryptionAlgorithm())
@ -257,7 +257,7 @@ public class OpenPgpService extends RemoteService {
builder.signatureKeyId(Id.key.none); builder.signatureKeyId(Id.key.none);
} }
// execute PGP operation! // execute PGP operation!
builder.build().signEncrypt(); builder.build().execute();
} finally { } finally {
is.close(); is.close();
os.close(); os.close();
@ -354,7 +354,7 @@ public class OpenPgpService extends RemoteService {
// inputStream2.reset(); // inputStream2.reset();
// } // }
// secretKeyId = Id.key.symmetric; // secretKeyId = Id.key.symmetric;
// if (!PgpOperationIncoming.hasSymmetricEncryption(this, inputStream2)) { // if (!PgpDecryptVerify.hasSymmetricEncryption(this, inputStream2)) {
// throw new PgpGeneralException( // throw new PgpGeneralException(
// getString(R.string.error_no_known_encryption_found)); // getString(R.string.error_no_known_encryption_found));
// } // }
@ -384,7 +384,7 @@ public class OpenPgpService extends RemoteService {
Bundle outputBundle; Bundle outputBundle;
PgpOperationIncoming.Builder builder = new PgpOperationIncoming.Builder(this, inputData, os); PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, os);
// if (signedOnly) { // if (signedOnly) {
// outputBundle = builder.build().verifyText(); // outputBundle = builder.build().verifyText();
@ -396,7 +396,7 @@ public class OpenPgpService extends RemoteService {
// pause stream when passphrase is missing and then resume??? // pause stream when passphrase is missing and then resume???
// TODO: this also decrypts with other secret keys without passphrase!!! // TODO: this also decrypts with other secret keys without passphrase!!!
outputBundle = builder.build().decryptVerify(); outputBundle = builder.build().execute();
// } // }
// outputStream.close(); // outputStream.close();
@ -425,7 +425,6 @@ public class OpenPgpService extends RemoteService {
signatureStatus = OpenPgpSignatureResult.SIGNATURE_UNKNOWN_PUB_KEY; signatureStatus = OpenPgpSignatureResult.SIGNATURE_UNKNOWN_PUB_KEY;
} }
// TODO: signed only?!?!?!
sigResult = new OpenPgpSignatureResult(signatureStatus, signatureUserId, sigResult = new OpenPgpSignatureResult(signatureStatus, signatureUserId,
signatureOnly, signatureKeyId); signatureOnly, signatureKeyId);
} }

View File

@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.helper.FileHelper; import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.PgpOperationIncoming; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.exception.NoAsymmetricEncryptionException; import org.sufficientlysecure.keychain.pgp.exception.NoAsymmetricEncryptionException;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -85,7 +85,7 @@ public class DecryptActivity extends DrawerActivity {
private boolean mReturnResult = false; private boolean mReturnResult = false;
// TODO: replace signed only checks with something more intelligent // TODO: replace signed only checks with something more intelligent
// PgpOperationIncoming should handle all automatically!!! // PgpDecryptVerify should handle all automatically!!!
private boolean mSignedOnly = false; private boolean mSignedOnly = false;
private boolean mAssumeSymmetricEncryption = false; private boolean mAssumeSymmetricEncryption = false;
@ -549,7 +549,7 @@ public class DecryptActivity extends DrawerActivity {
inStream.reset(); inStream.reset();
} }
mSecretKeyId = Id.key.symmetric; mSecretKeyId = Id.key.symmetric;
if (!PgpOperationIncoming.hasSymmetricEncryption(this, inStream)) { if (!PgpDecryptVerify.hasSymmetricEncryption(this, inStream)) {
throw new PgpGeneralException( throw new PgpGeneralException(
getString(R.string.error_no_known_encryption_found)); getString(R.string.error_no_known_encryption_found));
} }