diff options
author | Alex Fong <alexfongg@gmail.com> | 2016-03-17 08:03:22 +0800 |
---|---|---|
committer | Alex Fong <alexfongg@gmail.com> | 2016-05-05 07:57:01 +0800 |
commit | dfcde9242d7b39bf1ab9f0b66fc5829fb0af0f8c (patch) | |
tree | b72f46cc2a07391282bc5828f1965d3ff8fe3420 /OpenKeychain/src/main | |
parent | b490be9c1c979fd4a75b5844fb68b0179bcfe598 (diff) | |
download | open-keychain-dfcde9242d7b39bf1ab9f0b66fc5829fb0af0f8c.tar.gz open-keychain-dfcde9242d7b39bf1ab9f0b66fc5829fb0af0f8c.tar.bz2 open-keychain-dfcde9242d7b39bf1ab9f0b66fc5829fb0af0f8c.zip |
Removed unrequired code, standardized terms used.
Diffstat (limited to 'OpenKeychain/src/main')
3 files changed, 15 insertions, 32 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PassphraseChangeOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PassphraseChangeOperation.java index fff4ef534..2904c9b5a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PassphraseChangeOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PassphraseChangeOperation.java @@ -8,24 +8,17 @@ import org.sufficientlysecure.keychain.operations.results.EditKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.PassphraseChangeParcel; -import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ProgressScaler; -import java.util.Iterator; -/** - * Created by alex on 3/14/16. - */ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangeParcel> { @@ -33,14 +26,6 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar super(context, providerHelper, progressable); } - /** - * Finds the first unstripped key & uses that for passphrase verification. - * Might bring in complications - * - * @param passphraseParcel primary input to the operation - * @param cryptoInput input that changes if user interaction is required - * @return the result of the operation - */ @NonNull public OperationResult execute(PassphraseChangeParcel passphraseParcel, CryptoInputParcel cryptoInput) { OperationResult.OperationLog log = new OperationResult.OperationLog(); @@ -55,7 +40,7 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar PgpEditKeyResult modifyResult; { PgpKeyOperation keyOperations = - new PgpKeyOperation(new ProgressScaler(mProgressable, 0, 70, 100), mCancelled); + new PgpKeyOperation(new ProgressScaler(mProgressable, 0, 70, 100)); try { log.add(OperationResult.LogType.MSG_ED_FETCHING, 1, @@ -63,10 +48,10 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar CanonicalizedSecretKeyRing secRing = mProviderHelper.getCanonicalizedSecretKeyRing(passphraseParcel.mMasterKeyId); - - modifyResult = keyOperations.modifyKeyRingPassword(secRing, cryptoInput, passphraseParcel); + modifyResult = keyOperations.modifyKeyRingPassphrase(secRing, cryptoInput, passphraseParcel); if (modifyResult.isPending()) { + // obtain original passphrase from user log.add(modifyResult, 1); return new EditKeyResult(log, modifyResult); } @@ -78,12 +63,6 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar log.add(modifyResult, 1); - // Check if the action was cancelled - if (checkCancelled()) { - log.add(OperationResult.LogType.MSG_OPERATION_CANCELLED, 0); - return new EditKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null); - } - if (!modifyResult.success()) { // error is already logged by modification return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index cd4d9e5bb..bfc48ccbe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -72,7 +72,6 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; -import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.PassphraseChangeParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -349,9 +348,9 @@ public class PgpKeyOperation { } - public PgpEditKeyResult modifyKeyRingPassword(CanonicalizedSecretKeyRing wsKR, - CryptoInputParcel cryptoInput, - PassphraseChangeParcel passphraseParcel) { + public PgpEditKeyResult modifyKeyRingPassphrase(CanonicalizedSecretKeyRing wsKR, + CryptoInputParcel cryptoInput, + PassphraseChangeParcel passphraseParcel) { OperationLog log = new OperationLog(); int indent = 0; @@ -1274,6 +1273,9 @@ public class PgpKeyOperation { } + + + /** This method returns true iff the provided keyring has a local direct key signature * with notation data. */ @@ -1306,7 +1308,7 @@ public class PgpKeyOperation { PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc, PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT) .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(newPassphrase.getCharArray()); - int keysModified = 0; + boolean keysModified = false; for (PGPSecretKey sKey : new IterableIterator<>(sKR.getSecretKeys())) { log.add(LogType.MSG_MF_PASSPHRASE_KEY, indent, @@ -1321,6 +1323,7 @@ public class PgpKeyOperation { } catch (PGPException e) { // if this is the master key, error! + // skipped when changing key passphrase if (sKey.getKeyID() == masterPublicKey.getKeyID() && !isDummy(sKey)) { log.add(LogType.MSG_MF_ERROR_PASSPHRASE_MASTER, indent+1); return null; @@ -1348,10 +1351,11 @@ public class PgpKeyOperation { } sKR = PGPSecretKeyRing.insertSecretKey(sKR, sKey); - keysModified++; + keysModified = true; } - if(keysModified == 0) { + if(!keysModified) { + // no passphrase is changed log.add(LogType.MSG_MF_ERROR_PASSPHRASES_UNCHANGED, indent+1); return null; } diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 0af027ec1..2a44307f8 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -1078,7 +1078,7 @@ <string name="msg_mf_error_null_expiry">"Expiry time cannot be "same as before" on subkey creation. This is a programming error, please file a bug report!"</string> <string name="msg_mf_error_noop">"Nothing to do!"</string> <string name="msg_mf_error_passphrase_master">"Fatal error decrypting master key! This is likely a programming error, please file a bug report!"</string> - <string name="msg_mf_error_passphrases_unchanged">"Error changing all passphrases!"</string> + <string name="msg_mf_error_passphrases_unchanged">"No password changed!"</string> <string name="msg_mf_error_pgp">"Internal OpenPGP error!"</string> <string name="msg_mf_error_sig">"Signature exception!"</string> <string name="msg_mf_error_sub_stripped">"Cannot modify stripped subkey %s!"</string> |