Removed unrequired code, standardized terms used.
This commit is contained in:
@@ -8,24 +8,17 @@ import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
||||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseChangeParcel;
|
import org.sufficientlysecure.keychain.service.PassphraseChangeParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by alex on 3/14/16.
|
|
||||||
*/
|
|
||||||
public class PassphraseChangeOperation extends BaseOperation<PassphraseChangeParcel> {
|
public class PassphraseChangeOperation extends BaseOperation<PassphraseChangeParcel> {
|
||||||
|
|
||||||
|
|
||||||
@@ -33,14 +26,6 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar
|
|||||||
super(context, providerHelper, progressable);
|
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
|
@NonNull
|
||||||
public OperationResult execute(PassphraseChangeParcel passphraseParcel, CryptoInputParcel cryptoInput) {
|
public OperationResult execute(PassphraseChangeParcel passphraseParcel, CryptoInputParcel cryptoInput) {
|
||||||
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
||||||
@@ -55,7 +40,7 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar
|
|||||||
PgpEditKeyResult modifyResult;
|
PgpEditKeyResult modifyResult;
|
||||||
{
|
{
|
||||||
PgpKeyOperation keyOperations =
|
PgpKeyOperation keyOperations =
|
||||||
new PgpKeyOperation(new ProgressScaler(mProgressable, 0, 70, 100), mCancelled);
|
new PgpKeyOperation(new ProgressScaler(mProgressable, 0, 70, 100));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.add(OperationResult.LogType.MSG_ED_FETCHING, 1,
|
log.add(OperationResult.LogType.MSG_ED_FETCHING, 1,
|
||||||
@@ -63,10 +48,10 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar
|
|||||||
|
|
||||||
CanonicalizedSecretKeyRing secRing =
|
CanonicalizedSecretKeyRing secRing =
|
||||||
mProviderHelper.getCanonicalizedSecretKeyRing(passphraseParcel.mMasterKeyId);
|
mProviderHelper.getCanonicalizedSecretKeyRing(passphraseParcel.mMasterKeyId);
|
||||||
|
modifyResult = keyOperations.modifyKeyRingPassphrase(secRing, cryptoInput, passphraseParcel);
|
||||||
modifyResult = keyOperations.modifyKeyRingPassword(secRing, cryptoInput, passphraseParcel);
|
|
||||||
|
|
||||||
if (modifyResult.isPending()) {
|
if (modifyResult.isPending()) {
|
||||||
|
// obtain original passphrase from user
|
||||||
log.add(modifyResult, 1);
|
log.add(modifyResult, 1);
|
||||||
return new EditKeyResult(log, modifyResult);
|
return new EditKeyResult(log, modifyResult);
|
||||||
}
|
}
|
||||||
@@ -78,12 +63,6 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar
|
|||||||
|
|
||||||
log.add(modifyResult, 1);
|
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()) {
|
if (!modifyResult.success()) {
|
||||||
// error is already logged by modification
|
// error is already logged by modification
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||||
|
|||||||
@@ -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.LogType;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseChangeParcel;
|
import org.sufficientlysecure.keychain.service.PassphraseChangeParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
@@ -349,9 +348,9 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public PgpEditKeyResult modifyKeyRingPassword(CanonicalizedSecretKeyRing wsKR,
|
public PgpEditKeyResult modifyKeyRingPassphrase(CanonicalizedSecretKeyRing wsKR,
|
||||||
CryptoInputParcel cryptoInput,
|
CryptoInputParcel cryptoInput,
|
||||||
PassphraseChangeParcel passphraseParcel) {
|
PassphraseChangeParcel passphraseParcel) {
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
int indent = 0;
|
int indent = 0;
|
||||||
@@ -1274,6 +1273,9 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** This method returns true iff the provided keyring has a local direct key signature
|
/** This method returns true iff the provided keyring has a local direct key signature
|
||||||
* with notation data.
|
* with notation data.
|
||||||
*/
|
*/
|
||||||
@@ -1306,7 +1308,7 @@ public class PgpKeyOperation {
|
|||||||
PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc,
|
PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc,
|
||||||
PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT)
|
PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT)
|
||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(newPassphrase.getCharArray());
|
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(newPassphrase.getCharArray());
|
||||||
int keysModified = 0;
|
boolean keysModified = false;
|
||||||
|
|
||||||
for (PGPSecretKey sKey : new IterableIterator<>(sKR.getSecretKeys())) {
|
for (PGPSecretKey sKey : new IterableIterator<>(sKR.getSecretKeys())) {
|
||||||
log.add(LogType.MSG_MF_PASSPHRASE_KEY, indent,
|
log.add(LogType.MSG_MF_PASSPHRASE_KEY, indent,
|
||||||
@@ -1321,6 +1323,7 @@ public class PgpKeyOperation {
|
|||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
|
|
||||||
// if this is the master key, error!
|
// if this is the master key, error!
|
||||||
|
// skipped when changing key passphrase
|
||||||
if (sKey.getKeyID() == masterPublicKey.getKeyID() && !isDummy(sKey)) {
|
if (sKey.getKeyID() == masterPublicKey.getKeyID() && !isDummy(sKey)) {
|
||||||
log.add(LogType.MSG_MF_ERROR_PASSPHRASE_MASTER, indent+1);
|
log.add(LogType.MSG_MF_ERROR_PASSPHRASE_MASTER, indent+1);
|
||||||
return null;
|
return null;
|
||||||
@@ -1348,10 +1351,11 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sKR = PGPSecretKeyRing.insertSecretKey(sKR, sKey);
|
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);
|
log.add(LogType.MSG_MF_ERROR_PASSPHRASES_UNCHANGED, indent+1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_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_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_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_pgp">"Internal OpenPGP error!"</string>
|
||||||
<string name="msg_mf_error_sig">"Signature exception!"</string>
|
<string name="msg_mf_error_sig">"Signature exception!"</string>
|
||||||
<string name="msg_mf_error_sub_stripped">"Cannot modify stripped subkey %s!"</string>
|
<string name="msg_mf_error_sub_stripped">"Cannot modify stripped subkey %s!"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user