mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
encapsulate high level edit key into new operation class
This commit is contained in:
parent
5057ea1744
commit
320f7d35ef
@ -27,10 +27,9 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.shadows.ShadowLog;
|
import org.robolectric.shadows.ShadowLog;
|
||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
|
||||||
@ -79,7 +78,7 @@ public class ExportTest {
|
|||||||
parcel.mAddUserIds.add("snips");
|
parcel.mAddUserIds.add("snips");
|
||||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||||
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
||||||
|
|
||||||
@ -97,7 +96,7 @@ public class ExportTest {
|
|||||||
parcel.mAddUserIds.add("snails");
|
parcel.mAddUserIds.add("snails");
|
||||||
parcel.mNewUnlock = new ChangeUnlockParcel(null, "1234");
|
parcel.mNewUnlock = new ChangeUnlockParcel(null, "1234");
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||||
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
||||||
|
|
||||||
|
@ -28,13 +28,13 @@ import org.robolectric.shadows.ShadowLog;
|
|||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.spongycastle.openpgp.PGPEncryptedData;
|
import org.spongycastle.openpgp.PGPEncryptedData;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt.Builder;
|
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt.Builder;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
||||||
@ -80,7 +80,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
parcel.mAddUserIds.add("bloom");
|
parcel.mAddUserIds.add("bloom");
|
||||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||||
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
parcel.mAddUserIds.add("belle");
|
parcel.mAddUserIds.add("belle");
|
||||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase2);
|
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase2);
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||||
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import org.spongycastle.jce.provider.BouncyCastleProvider;
|
|||||||
import org.spongycastle.openpgp.PGPSignature;
|
import org.spongycastle.openpgp.PGPSignature;
|
||||||
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.EditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||||
@ -96,7 +96,7 @@ public class PgpKeyOperationTest {
|
|||||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||||
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
||||||
|
|
||||||
@ -962,7 +962,7 @@ public class PgpKeyOperationTest {
|
|||||||
// we should still be able to modify it (and change its passphrase) without errors
|
// we should still be able to modify it (and change its passphrase) without errors
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0);
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0);
|
||||||
EditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, otherPassphrase);
|
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, otherPassphrase);
|
||||||
Assert.assertTrue("key modification must succeed", result.success());
|
Assert.assertTrue("key modification must succeed", result.success());
|
||||||
Assert.assertFalse("log must not contain a warning",
|
Assert.assertFalse("log must not contain a warning",
|
||||||
result.getLog().containsWarnings());
|
result.getLog().containsWarnings());
|
||||||
@ -978,7 +978,7 @@ public class PgpKeyOperationTest {
|
|||||||
|
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0);
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0);
|
||||||
EditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, otherPassphrase2);
|
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, otherPassphrase2);
|
||||||
Assert.assertTrue("key modification must succeed", result.success());
|
Assert.assertTrue("key modification must succeed", result.success());
|
||||||
Assert.assertTrue("log must contain a failed passphrase change warning",
|
Assert.assertTrue("log must contain a failed passphrase change warning",
|
||||||
result.getLog().containsType(LogType.MSG_MF_PASSPHRASE_FAIL));
|
result.getLog().containsType(LogType.MSG_MF_PASSPHRASE_FAIL));
|
||||||
@ -1056,7 +1056,7 @@ public class PgpKeyOperationTest {
|
|||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
|
||||||
|
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
EditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
|
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
|
||||||
Assert.assertTrue("key modification must succeed", result.success());
|
Assert.assertTrue("key modification must succeed", result.success());
|
||||||
UncachedKeyRing rawModified = result.getRing();
|
UncachedKeyRing rawModified = result.getRing();
|
||||||
Assert.assertNotNull("key modification must not return null", rawModified);
|
Assert.assertNotNull("key modification must not return null", rawModified);
|
||||||
@ -1113,7 +1113,7 @@ public class PgpKeyOperationTest {
|
|||||||
|
|
||||||
private void assertFailure(String reason, SaveKeyringParcel parcel, LogType expected) {
|
private void assertFailure(String reason, SaveKeyringParcel parcel, LogType expected) {
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
|
|
||||||
Assert.assertFalse(reason, result.success());
|
Assert.assertFalse(reason, result.success());
|
||||||
Assert.assertNull(reason, result.getRing());
|
Assert.assertNull(reason, result.getRing());
|
||||||
@ -1127,7 +1127,7 @@ public class PgpKeyOperationTest {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
|
||||||
EditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
|
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
|
||||||
|
|
||||||
Assert.assertFalse(reason, result.success());
|
Assert.assertFalse(reason, result.success());
|
||||||
Assert.assertNull(reason, result.getRing());
|
Assert.assertNull(reason, result.getRing());
|
||||||
@ -1141,7 +1141,7 @@ public class PgpKeyOperationTest {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
|
||||||
EditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
|
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
|
||||||
|
|
||||||
Assert.assertFalse(reason, result.success());
|
Assert.assertFalse(reason, result.success());
|
||||||
Assert.assertNull(reason, result.getRing());
|
Assert.assertNull(reason, result.getRing());
|
||||||
@ -1152,7 +1152,7 @@ public class PgpKeyOperationTest {
|
|||||||
|
|
||||||
private UncachedKeyRing assertCreateSuccess(String reason, SaveKeyringParcel parcel) {
|
private UncachedKeyRing assertCreateSuccess(String reason, SaveKeyringParcel parcel) {
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
|
|
||||||
Assert.assertTrue(reason, result.success());
|
Assert.assertTrue(reason, result.success());
|
||||||
Assert.assertNotNull(reason, result.getRing());
|
Assert.assertNotNull(reason, result.getRing());
|
||||||
|
@ -53,7 +53,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
|
|||||||
import org.spongycastle.util.Strings;
|
import org.spongycastle.util.Strings;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||||
@ -108,7 +108,7 @@ public class UncachedKeyringCanonicalizeTest {
|
|||||||
parcel.mNewUnlock = new ChangeUnlockParcel("");
|
parcel.mNewUnlock = new ChangeUnlockParcel("");
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||||
staticRing = result.getRing();
|
staticRing = result.getRing();
|
||||||
Assert.assertNotNull("initial test key creation must succeed", staticRing);
|
Assert.assertNotNull("initial test key creation must succeed", staticRing);
|
||||||
|
@ -33,7 +33,7 @@ import org.spongycastle.bcpg.sig.KeyFlags;
|
|||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.spongycastle.util.Strings;
|
import org.spongycastle.util.Strings;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||||
@ -103,7 +103,7 @@ public class UncachedKeyringMergeTest {
|
|||||||
|
|
||||||
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
staticRingA = result.getRing();
|
staticRingA = result.getRing();
|
||||||
staticRingA = staticRingA.canonicalize(new OperationLog(), 0).getUncachedKeyRing();
|
staticRingA = staticRingA.canonicalize(new OperationLog(), 0).getUncachedKeyRing();
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ public class UncachedKeyringMergeTest {
|
|||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
|
|
||||||
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
staticRingB = result.getRing();
|
staticRingB = result.getRing();
|
||||||
staticRingB = staticRingB.canonicalize(new OperationLog(), 0).getUncachedKeyRing();
|
staticRingB = staticRingB.canonicalize(new OperationLog(), 0).getUncachedKeyRing();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.shadows.ShadowLog;
|
import org.robolectric.shadows.ShadowLog;
|
||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
@ -63,7 +63,7 @@ public class UncachedKeyringTest {
|
|||||||
parcel.mNewUnlock = new ChangeUnlockParcel("");
|
parcel.mNewUnlock = new ChangeUnlockParcel("");
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
|
|
||||||
EditKeyResult result = op.createSecretKeyRing(parcel);
|
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||||
staticRing = result.getRing();
|
staticRing = result.getRing();
|
||||||
staticPubRing = staticRing.extractPublicKeyRing();
|
staticPubRing = staticRing.extractPublicKeyRing();
|
||||||
|
|
||||||
|
@ -0,0 +1,132 @@
|
|||||||
|
package org.sufficientlysecure.keychain.operations;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
|
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.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||||
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
||||||
|
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||||
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/** An operation which implements a high level key edit operation.
|
||||||
|
*
|
||||||
|
* This operation provides a higher level interface to the edit and
|
||||||
|
* create key operations in PgpKeyOperation. It takes care of fetching
|
||||||
|
* and saving the key before and after the operation.
|
||||||
|
*
|
||||||
|
* @see CertifyActionsParcel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EditKeyOperation extends BaseOperation {
|
||||||
|
|
||||||
|
public EditKeyOperation(Context context, ProviderHelper providerHelper,
|
||||||
|
Progressable progressable, AtomicBoolean cancelled) {
|
||||||
|
super(context, providerHelper, progressable, cancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditKeyResult execute(SaveKeyringParcel saveParcel, String passphrase) {
|
||||||
|
|
||||||
|
OperationLog log = new OperationLog();
|
||||||
|
log.add(LogType.MSG_ED, 0);
|
||||||
|
|
||||||
|
if (saveParcel == null) {
|
||||||
|
log.add(LogType.MSG_ED_ERROR_NO_PARCEL, 1);
|
||||||
|
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform actual modification (or creation)
|
||||||
|
PgpEditKeyResult modifyResult;
|
||||||
|
{
|
||||||
|
PgpKeyOperation keyOperations =
|
||||||
|
new PgpKeyOperation(new ProgressScaler(mProgressable, 10, 60, 100), mCancelled);
|
||||||
|
|
||||||
|
// If a key id is specified, fetch and edit
|
||||||
|
if (saveParcel.mMasterKeyId != null) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
log.add(LogType.MSG_ED_FETCHING, 1,
|
||||||
|
KeyFormattingUtils.convertKeyIdToHex(saveParcel.mMasterKeyId));
|
||||||
|
CanonicalizedSecretKeyRing secRing =
|
||||||
|
mProviderHelper.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId);
|
||||||
|
|
||||||
|
modifyResult = keyOperations.modifySecretKeyRing(secRing, saveParcel, passphrase);
|
||||||
|
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
log.add(LogType.MSG_ED_ERROR_KEY_NOT_FOUND, 2);
|
||||||
|
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// otherwise, create new one
|
||||||
|
modifyResult = keyOperations.createSecretKeyRing(saveParcel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the result to the log
|
||||||
|
log.add(modifyResult, 1);
|
||||||
|
|
||||||
|
// Check if the action was cancelled
|
||||||
|
if (checkCancelled()) {
|
||||||
|
log.add(LogType.MSG_OPERATION_CANCELLED, 0);
|
||||||
|
return new EditKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the edit operation didn't succeed, exit here
|
||||||
|
if (!modifyResult.success()) {
|
||||||
|
// error is already logged by modification
|
||||||
|
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cannot cancel from here on out!
|
||||||
|
mProgressable.setPreventCancel();
|
||||||
|
|
||||||
|
// It's a success, so this must be non-null now
|
||||||
|
UncachedKeyRing ring = modifyResult.getRing();
|
||||||
|
|
||||||
|
// Save the new keyring.
|
||||||
|
SaveKeyringResult saveResult = mProviderHelper
|
||||||
|
.saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100));
|
||||||
|
log.add(saveResult, 1);
|
||||||
|
|
||||||
|
// If the save operation didn't succeed, exit here
|
||||||
|
if (!saveResult.success()) {
|
||||||
|
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is a new passphrase - cache it
|
||||||
|
if (saveParcel.mNewUnlock != null) {
|
||||||
|
log.add(LogType.MSG_ED_CACHING_NEW, 1);
|
||||||
|
PassphraseCacheService.addCachedPassphrase(mContext,
|
||||||
|
ring.getMasterKeyId(),
|
||||||
|
ring.getMasterKeyId(),
|
||||||
|
saveParcel.mNewUnlock.mNewPassphrase != null
|
||||||
|
? saveParcel.mNewUnlock.mNewPassphrase
|
||||||
|
: saveParcel.mNewUnlock.mNewPin,
|
||||||
|
ring.getPublicKey().getPrimaryUserIdWithFallback());
|
||||||
|
}
|
||||||
|
|
||||||
|
updateProgress(R.string.progress_done, 100, 100);
|
||||||
|
|
||||||
|
// make sure new data is synced into contacts
|
||||||
|
ContactSyncAdapterService.requestSync();
|
||||||
|
|
||||||
|
log.add(LogType.MSG_ED_SUCCESS, 0);
|
||||||
|
return new EditKeyResult(EditKeyResult.RESULT_OK, log, ring.getMasterKeyId());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -20,34 +20,24 @@ package org.sufficientlysecure.keychain.operations.results;
|
|||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
|
||||||
|
|
||||||
public class EditKeyResult extends OperationResult {
|
public class EditKeyResult extends OperationResult {
|
||||||
|
|
||||||
private transient UncachedKeyRing mRing;
|
public final Long mMasterKeyId;
|
||||||
public final long mRingMasterKeyId;
|
|
||||||
|
|
||||||
public EditKeyResult(int result, OperationLog log,
|
public EditKeyResult(int result, OperationLog log, Long masterKeyId) {
|
||||||
UncachedKeyRing ring) {
|
|
||||||
super(result, log);
|
super(result, log);
|
||||||
mRing = ring;
|
mMasterKeyId = masterKeyId;
|
||||||
mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UncachedKeyRing getRing() {
|
|
||||||
return mRing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditKeyResult(Parcel source) {
|
public EditKeyResult(Parcel source) {
|
||||||
super(source);
|
super(source);
|
||||||
mRingMasterKeyId = source.readLong();
|
mMasterKeyId = source.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
super.writeToParcel(dest, flags);
|
super.writeToParcel(dest, flags);
|
||||||
dest.writeLong(mRingMasterKeyId);
|
dest.writeLong(mMasterKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Creator<EditKeyResult> CREATOR = new Creator<EditKeyResult>() {
|
public static Creator<EditKeyResult> CREATOR = new Creator<EditKeyResult>() {
|
||||||
|
@ -508,6 +508,14 @@ public abstract class OperationResult implements Parcelable {
|
|||||||
MSG_CON_WARN_DELETE_PUBLIC (LogLevel.WARN, R.string.msg_con_warn_delete_public),
|
MSG_CON_WARN_DELETE_PUBLIC (LogLevel.WARN, R.string.msg_con_warn_delete_public),
|
||||||
MSG_CON_WARN_DELETE_SECRET (LogLevel.WARN, R.string.msg_con_warn_delete_secret),
|
MSG_CON_WARN_DELETE_SECRET (LogLevel.WARN, R.string.msg_con_warn_delete_secret),
|
||||||
|
|
||||||
|
// edit key (higher level operation than modify)
|
||||||
|
MSG_ED (LogLevel.START, R.string.msg_ed),
|
||||||
|
MSG_ED_CACHING_NEW (LogLevel.DEBUG, R.string.msg_ed_caching_new),
|
||||||
|
MSG_ED_ERROR_NO_PARCEL (LogLevel.ERROR, R.string.msg_ed_error_no_parcel),
|
||||||
|
MSG_ED_ERROR_KEY_NOT_FOUND (LogLevel.ERROR, R.string.msg_ed_error_key_not_found),
|
||||||
|
MSG_ED_FETCHING (LogLevel.DEBUG, R.string.msg_ed_fetching),
|
||||||
|
MSG_ED_SUCCESS (LogLevel.OK, R.string.msg_ed_success),
|
||||||
|
|
||||||
// messages used in UI code
|
// messages used in UI code
|
||||||
MSG_EK_ERROR_DIVERT (LogLevel.ERROR, R.string.msg_ek_error_divert),
|
MSG_EK_ERROR_DIVERT (LogLevel.ERROR, R.string.msg_ek_error_divert),
|
||||||
MSG_EK_ERROR_DUMMY (LogLevel.ERROR, R.string.msg_ek_error_dummy),
|
MSG_EK_ERROR_DUMMY (LogLevel.ERROR, R.string.msg_ek_error_dummy),
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.operations.results;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
|
|
||||||
|
public class PgpEditKeyResult extends OperationResult {
|
||||||
|
|
||||||
|
private transient UncachedKeyRing mRing;
|
||||||
|
public final long mRingMasterKeyId;
|
||||||
|
|
||||||
|
public PgpEditKeyResult(int result, OperationLog log,
|
||||||
|
UncachedKeyRing ring) {
|
||||||
|
super(result, log);
|
||||||
|
mRing = ring;
|
||||||
|
mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UncachedKeyRing getRing() {
|
||||||
|
return mRing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PgpEditKeyResult(Parcel source) {
|
||||||
|
super(source);
|
||||||
|
mRingMasterKeyId = source.readLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
super.writeToParcel(dest, flags);
|
||||||
|
dest.writeLong(mRingMasterKeyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Creator<PgpEditKeyResult> CREATOR = new Creator<PgpEditKeyResult>() {
|
||||||
|
public PgpEditKeyResult createFromParcel(final Parcel source) {
|
||||||
|
return new PgpEditKeyResult(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PgpEditKeyResult[] newArray(final int size) {
|
||||||
|
return new PgpEditKeyResult[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -34,7 +34,6 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
|
|||||||
import org.spongycastle.openpgp.PGPSignature;
|
import org.spongycastle.openpgp.PGPSignature;
|
||||||
import org.spongycastle.openpgp.PGPSignatureGenerator;
|
import org.spongycastle.openpgp.PGPSignatureGenerator;
|
||||||
import org.spongycastle.openpgp.PGPSignatureSubpacketGenerator;
|
import org.spongycastle.openpgp.PGPSignatureSubpacketGenerator;
|
||||||
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
|
|
||||||
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
|
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||||
import org.spongycastle.openpgp.operator.PBESecretKeyEncryptor;
|
import org.spongycastle.openpgp.operator.PBESecretKeyEncryptor;
|
||||||
import org.spongycastle.openpgp.operator.PGPContentSignerBuilder;
|
import org.spongycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||||
@ -50,7 +49,7 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
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.EditKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||||
@ -302,7 +301,7 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditKeyResult createSecretKeyRing(SaveKeyringParcel saveParcel) {
|
public PgpEditKeyResult createSecretKeyRing(SaveKeyringParcel saveParcel) {
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
int indent = 0;
|
int indent = 0;
|
||||||
@ -315,23 +314,23 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
if (saveParcel.mAddSubKeys.isEmpty()) {
|
if (saveParcel.mAddSubKeys.isEmpty()) {
|
||||||
log.add(LogType.MSG_CR_ERROR_NO_MASTER, indent);
|
log.add(LogType.MSG_CR_ERROR_NO_MASTER, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveParcel.mAddUserIds.isEmpty()) {
|
if (saveParcel.mAddUserIds.isEmpty()) {
|
||||||
log.add(LogType.MSG_CR_ERROR_NO_USER_ID, indent);
|
log.add(LogType.MSG_CR_ERROR_NO_USER_ID, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
SubkeyAdd add = saveParcel.mAddSubKeys.remove(0);
|
SubkeyAdd add = saveParcel.mAddSubKeys.remove(0);
|
||||||
if ((add.mFlags & KeyFlags.CERTIFY_OTHER) != KeyFlags.CERTIFY_OTHER) {
|
if ((add.mFlags & KeyFlags.CERTIFY_OTHER) != KeyFlags.CERTIFY_OTHER) {
|
||||||
log.add(LogType.MSG_CR_ERROR_NO_CERTIFY, indent);
|
log.add(LogType.MSG_CR_ERROR_NO_CERTIFY, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add.mExpiry == null) {
|
if (add.mExpiry == null) {
|
||||||
log.add(LogType.MSG_CR_ERROR_NULL_EXPIRY, indent);
|
log.add(LogType.MSG_CR_ERROR_NULL_EXPIRY, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
subProgressPush(10, 30);
|
subProgressPush(10, 30);
|
||||||
@ -340,7 +339,7 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
// return null if this failed (an error will already have been logged by createKey)
|
// return null if this failed (an error will already have been logged by createKey)
|
||||||
if (keyPair == null) {
|
if (keyPair == null) {
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
progress(R.string.progress_building_master_key, 40);
|
progress(R.string.progress_building_master_key, 40);
|
||||||
@ -367,10 +366,10 @@ public class PgpKeyOperation {
|
|||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
log.add(LogType.MSG_CR_ERROR_INTERNAL_PGP, indent);
|
log.add(LogType.MSG_CR_ERROR_INTERNAL_PGP, indent);
|
||||||
Log.e(Constants.TAG, "pgp error encoding key", e);
|
Log.e(Constants.TAG, "pgp error encoding key", e);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "io error encoding key", e);
|
Log.e(Constants.TAG, "io error encoding key", e);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -390,7 +389,7 @@ public class PgpKeyOperation {
|
|||||||
* handling of errors should be done in UI code!
|
* handling of errors should be done in UI code!
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public EditKeyResult modifySecretKeyRing(CanonicalizedSecretKeyRing wsKR, SaveKeyringParcel saveParcel,
|
public PgpEditKeyResult modifySecretKeyRing(CanonicalizedSecretKeyRing wsKR, SaveKeyringParcel saveParcel,
|
||||||
String passphrase) {
|
String passphrase) {
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
@ -415,7 +414,7 @@ public class PgpKeyOperation {
|
|||||||
// Make sure this is called with a proper SaveKeyringParcel
|
// Make sure this is called with a proper SaveKeyringParcel
|
||||||
if (saveParcel.mMasterKeyId == null || saveParcel.mMasterKeyId != wsKR.getMasterKeyId()) {
|
if (saveParcel.mMasterKeyId == null || saveParcel.mMasterKeyId != wsKR.getMasterKeyId()) {
|
||||||
log.add(LogType.MSG_MF_ERROR_KEYID, indent);
|
log.add(LogType.MSG_MF_ERROR_KEYID, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We work on bouncycastle object level here
|
// We work on bouncycastle object level here
|
||||||
@ -426,7 +425,7 @@ public class PgpKeyOperation {
|
|||||||
if (saveParcel.mFingerprint == null || !Arrays.equals(saveParcel.mFingerprint,
|
if (saveParcel.mFingerprint == null || !Arrays.equals(saveParcel.mFingerprint,
|
||||||
masterSecretKey.getPublicKey().getFingerprint())) {
|
masterSecretKey.getPublicKey().getFingerprint())) {
|
||||||
log.add(LogType.MSG_MF_ERROR_FINGERPRINT, indent);
|
log.add(LogType.MSG_MF_ERROR_FINGERPRINT, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read masterKeyFlags, and use the same as before.
|
// read masterKeyFlags, and use the same as before.
|
||||||
@ -440,7 +439,7 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private EditKeyResult internal(PGPSecretKeyRing sKR, PGPSecretKey masterSecretKey,
|
private PgpEditKeyResult internal(PGPSecretKeyRing sKR, PGPSecretKey masterSecretKey,
|
||||||
int masterKeyFlags, long masterKeyExpiry,
|
int masterKeyFlags, long masterKeyExpiry,
|
||||||
SaveKeyringParcel saveParcel, String passphrase,
|
SaveKeyringParcel saveParcel, String passphrase,
|
||||||
OperationLog log) {
|
OperationLog log) {
|
||||||
@ -462,7 +461,7 @@ public class PgpKeyOperation {
|
|||||||
masterPrivateKey = masterSecretKey.extractPrivateKey(keyDecryptor);
|
masterPrivateKey = masterSecretKey.extractPrivateKey(keyDecryptor);
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
log.add(LogType.MSG_MF_UNLOCK_ERROR, indent + 1);
|
log.add(LogType.MSG_MF_UNLOCK_ERROR, indent + 1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +470,7 @@ public class PgpKeyOperation {
|
|||||||
// Check if we were cancelled
|
// Check if we were cancelled
|
||||||
if (checkCancelled()) {
|
if (checkCancelled()) {
|
||||||
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // work on master secret key
|
{ // work on master secret key
|
||||||
@ -488,7 +487,7 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
if (userId.equals("")) {
|
if (userId.equals("")) {
|
||||||
log.add(LogType.MSG_MF_UID_ERROR_EMPTY, indent + 1);
|
log.add(LogType.MSG_MF_UID_ERROR_EMPTY, indent + 1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this operation supersedes all previous binding and revocation certificates,
|
// this operation supersedes all previous binding and revocation certificates,
|
||||||
@ -500,7 +499,7 @@ public class PgpKeyOperation {
|
|||||||
if (cert.getKeyID() != masterPublicKey.getKeyID()) {
|
if (cert.getKeyID() != masterPublicKey.getKeyID()) {
|
||||||
// foreign certificate?! error error error
|
// foreign certificate?! error error error
|
||||||
log.add(LogType.MSG_MF_ERROR_INTEGRITY, indent);
|
log.add(LogType.MSG_MF_ERROR_INTEGRITY, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
if (cert.getSignatureType() == PGPSignature.CERTIFICATION_REVOCATION
|
if (cert.getSignatureType() == PGPSignature.CERTIFICATION_REVOCATION
|
||||||
|| cert.getSignatureType() == PGPSignature.NO_CERTIFICATION
|
|| cert.getSignatureType() == PGPSignature.NO_CERTIFICATION
|
||||||
@ -542,7 +541,7 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
log.add(LogType.MSG_MF_ERROR_NOEXIST_REVOKE, indent);
|
log.add(LogType.MSG_MF_ERROR_NOEXIST_REVOKE, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// a duplicate revocation will be removed during canonicalization, so no need to
|
// a duplicate revocation will be removed during canonicalization, so no need to
|
||||||
@ -573,7 +572,7 @@ public class PgpKeyOperation {
|
|||||||
if (cert.getKeyID() != masterPublicKey.getKeyID()) {
|
if (cert.getKeyID() != masterPublicKey.getKeyID()) {
|
||||||
// foreign certificate?! error error error
|
// foreign certificate?! error error error
|
||||||
log.add(LogType.MSG_MF_ERROR_INTEGRITY, indent);
|
log.add(LogType.MSG_MF_ERROR_INTEGRITY, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
// we know from canonicalization that if there is any revocation here, it
|
// we know from canonicalization that if there is any revocation here, it
|
||||||
// is valid and not superseded by a newer certification.
|
// is valid and not superseded by a newer certification.
|
||||||
@ -594,7 +593,7 @@ public class PgpKeyOperation {
|
|||||||
if (currentCert == null) {
|
if (currentCert == null) {
|
||||||
// no certificate found?! error error error
|
// no certificate found?! error error error
|
||||||
log.add(LogType.MSG_MF_ERROR_INTEGRITY, indent);
|
log.add(LogType.MSG_MF_ERROR_INTEGRITY, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we definitely should not update certifications of revoked keys, so just leave it.
|
// we definitely should not update certifications of revoked keys, so just leave it.
|
||||||
@ -602,7 +601,7 @@ public class PgpKeyOperation {
|
|||||||
// revoked user ids cannot be primary!
|
// revoked user ids cannot be primary!
|
||||||
if (userId.equals(saveParcel.mChangePrimaryUserId)) {
|
if (userId.equals(saveParcel.mChangePrimaryUserId)) {
|
||||||
log.add(LogType.MSG_MF_ERROR_REVOKED_PRIMARY, indent);
|
log.add(LogType.MSG_MF_ERROR_REVOKED_PRIMARY, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -651,7 +650,7 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
log.add(LogType.MSG_MF_ERROR_NOEXIST_PRIMARY, indent);
|
log.add(LogType.MSG_MF_ERROR_NOEXIST_PRIMARY, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -667,7 +666,7 @@ public class PgpKeyOperation {
|
|||||||
// Check if we were cancelled - again
|
// Check if we were cancelled - again
|
||||||
if (checkCancelled()) {
|
if (checkCancelled()) {
|
||||||
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4a. For each subkey change, generate new subkey binding certificate
|
// 4a. For each subkey change, generate new subkey binding certificate
|
||||||
@ -683,7 +682,7 @@ public class PgpKeyOperation {
|
|||||||
if (sKey == null) {
|
if (sKey == null) {
|
||||||
log.add(LogType.MSG_MF_ERROR_SUBKEY_MISSING,
|
log.add(LogType.MSG_MF_ERROR_SUBKEY_MISSING,
|
||||||
indent + 1, KeyFormattingUtils.convertKeyIdToHex(change.mKeyId));
|
indent + 1, KeyFormattingUtils.convertKeyIdToHex(change.mKeyId));
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// expiry must not be in the past
|
// expiry must not be in the past
|
||||||
@ -691,7 +690,7 @@ public class PgpKeyOperation {
|
|||||||
new Date(change.mExpiry*1000).before(new Date())) {
|
new Date(change.mExpiry*1000).before(new Date())) {
|
||||||
log.add(LogType.MSG_MF_ERROR_PAST_EXPIRY,
|
log.add(LogType.MSG_MF_ERROR_PAST_EXPIRY,
|
||||||
indent + 1, KeyFormattingUtils.convertKeyIdToHex(change.mKeyId));
|
indent + 1, KeyFormattingUtils.convertKeyIdToHex(change.mKeyId));
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this is the master key, update uid certificates instead
|
// if this is the master key, update uid certificates instead
|
||||||
@ -701,7 +700,7 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
if ((flags & KeyFlags.CERTIFY_OTHER) != KeyFlags.CERTIFY_OTHER) {
|
if ((flags & KeyFlags.CERTIFY_OTHER) != KeyFlags.CERTIFY_OTHER) {
|
||||||
log.add(LogType.MSG_MF_ERROR_NO_CERTIFY, indent + 1);
|
log.add(LogType.MSG_MF_ERROR_NO_CERTIFY, indent + 1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
PGPPublicKey pKey =
|
PGPPublicKey pKey =
|
||||||
@ -709,7 +708,7 @@ public class PgpKeyOperation {
|
|||||||
flags, expiry, indent, log);
|
flags, expiry, indent, log);
|
||||||
if (pKey == null) {
|
if (pKey == null) {
|
||||||
// error log entry has already been added by updateMasterCertificates itself
|
// error log entry has already been added by updateMasterCertificates itself
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
masterSecretKey = PGPSecretKey.replacePublicKey(sKey, pKey);
|
masterSecretKey = PGPSecretKey.replacePublicKey(sKey, pKey);
|
||||||
masterPublicKey = pKey;
|
masterPublicKey = pKey;
|
||||||
@ -764,7 +763,7 @@ public class PgpKeyOperation {
|
|||||||
if (sKey == null) {
|
if (sKey == null) {
|
||||||
log.add(LogType.MSG_MF_ERROR_SUBKEY_MISSING,
|
log.add(LogType.MSG_MF_ERROR_SUBKEY_MISSING,
|
||||||
indent+1, KeyFormattingUtils.convertKeyIdToHex(revocation));
|
indent+1, KeyFormattingUtils.convertKeyIdToHex(revocation));
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
PGPPublicKey pKey = sKey.getPublicKey();
|
PGPPublicKey pKey = sKey.getPublicKey();
|
||||||
|
|
||||||
@ -789,7 +788,7 @@ public class PgpKeyOperation {
|
|||||||
if (sKey == null) {
|
if (sKey == null) {
|
||||||
log.add(LogType.MSG_MF_ERROR_SUBKEY_MISSING,
|
log.add(LogType.MSG_MF_ERROR_SUBKEY_MISSING,
|
||||||
indent+1, KeyFormattingUtils.convertKeyIdToHex(strip));
|
indent+1, KeyFormattingUtils.convertKeyIdToHex(strip));
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IT'S DANGEROUS~
|
// IT'S DANGEROUS~
|
||||||
@ -807,7 +806,7 @@ public class PgpKeyOperation {
|
|||||||
// Check if we were cancelled - again. This operation is expensive so we do it each loop.
|
// Check if we were cancelled - again. This operation is expensive so we do it each loop.
|
||||||
if (checkCancelled()) {
|
if (checkCancelled()) {
|
||||||
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
progress(R.string.progress_modify_subkeyadd, (i-1) * (100 / saveParcel.mAddSubKeys.size()));
|
progress(R.string.progress_modify_subkeyadd, (i-1) * (100 / saveParcel.mAddSubKeys.size()));
|
||||||
@ -817,12 +816,12 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
if (add.mExpiry == null) {
|
if (add.mExpiry == null) {
|
||||||
log.add(LogType.MSG_MF_ERROR_NULL_EXPIRY, indent +1);
|
log.add(LogType.MSG_MF_ERROR_NULL_EXPIRY, indent +1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add.mExpiry > 0L && new Date(add.mExpiry*1000).before(new Date())) {
|
if (add.mExpiry > 0L && new Date(add.mExpiry*1000).before(new Date())) {
|
||||||
log.add(LogType.MSG_MF_ERROR_PAST_EXPIRY, indent +1);
|
log.add(LogType.MSG_MF_ERROR_PAST_EXPIRY, indent +1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate a new secret key (privkey only for now)
|
// generate a new secret key (privkey only for now)
|
||||||
@ -834,7 +833,7 @@ public class PgpKeyOperation {
|
|||||||
subProgressPop();
|
subProgressPop();
|
||||||
if (keyPair == null) {
|
if (keyPair == null) {
|
||||||
log.add(LogType.MSG_MF_ERROR_PGP, indent +1);
|
log.add(LogType.MSG_MF_ERROR_PGP, indent +1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add subkey binding signature (making this a sub rather than master key)
|
// add subkey binding signature (making this a sub rather than master key)
|
||||||
@ -869,7 +868,7 @@ public class PgpKeyOperation {
|
|||||||
// Check if we were cancelled - again. This operation is expensive so we do it each loop.
|
// Check if we were cancelled - again. This operation is expensive so we do it each loop.
|
||||||
if (checkCancelled()) {
|
if (checkCancelled()) {
|
||||||
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
log.add(LogType.MSG_OPERATION_CANCELLED, indent);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. If requested, change passphrase
|
// 6. If requested, change passphrase
|
||||||
@ -882,7 +881,7 @@ public class PgpKeyOperation {
|
|||||||
passphrase, saveParcel.mNewUnlock, log, indent);
|
passphrase, saveParcel.mNewUnlock, log, indent);
|
||||||
if (sKR == null) {
|
if (sKR == null) {
|
||||||
// The error has been logged above, just return a bad state
|
// The error has been logged above, just return a bad state
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
indent -= 1;
|
indent -= 1;
|
||||||
@ -891,20 +890,20 @@ public class PgpKeyOperation {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "encountered IOException while modifying key", e);
|
Log.e(Constants.TAG, "encountered IOException while modifying key", e);
|
||||||
log.add(LogType.MSG_MF_ERROR_ENCODE, indent+1);
|
log.add(LogType.MSG_MF_ERROR_ENCODE, indent+1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
Log.e(Constants.TAG, "encountered pgp error while modifying key", e);
|
Log.e(Constants.TAG, "encountered pgp error while modifying key", e);
|
||||||
log.add(LogType.MSG_MF_ERROR_PGP, indent+1);
|
log.add(LogType.MSG_MF_ERROR_PGP, indent+1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
} catch (SignatureException e) {
|
} catch (SignatureException e) {
|
||||||
Log.e(Constants.TAG, "encountered SignatureException while modifying key", e);
|
Log.e(Constants.TAG, "encountered SignatureException while modifying key", e);
|
||||||
log.add(LogType.MSG_MF_ERROR_SIG, indent+1);
|
log.add(LogType.MSG_MF_ERROR_SIG, indent+1);
|
||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
progress(R.string.progress_done, 100);
|
progress(R.string.progress_done, 100);
|
||||||
log.add(LogType.MSG_MF_SUCCESS, indent);
|
log.add(LogType.MSG_MF_SUCCESS, indent);
|
||||||
return new EditKeyResult(OperationResult.RESULT_OK, log, new UncachedKeyRing(sKR));
|
return new PgpEditKeyResult(OperationResult.RESULT_OK, log, new UncachedKeyRing(sKR));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,11 +27,13 @@ import android.os.Messenger;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.operations.CertifyOperation;
|
import org.sufficientlysecure.keychain.operations.CertifyOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.DeleteOperation;
|
import org.sufficientlysecure.keychain.operations.DeleteOperation;
|
||||||
|
import org.sufficientlysecure.keychain.operations.EditKeyOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||||
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
@ -41,31 +43,23 @@ import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
|||||||
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
|
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
|
||||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||||
import org.sufficientlysecure.keychain.operations.ImportExportOperation;
|
import org.sufficientlysecure.keychain.operations.ImportExportOperation;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
|
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
|
||||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
|
||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
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.ConsolidateResult;
|
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -342,83 +336,16 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
|
|
||||||
} else if (ACTION_EDIT_KEYRING.equals(action)) {
|
} else if (ACTION_EDIT_KEYRING.equals(action)) {
|
||||||
|
|
||||||
try {
|
// Input
|
||||||
/* Input */
|
SaveKeyringParcel saveParcel = data.getParcelable(EDIT_KEYRING_PARCEL);
|
||||||
SaveKeyringParcel saveParcel = data.getParcelable(EDIT_KEYRING_PARCEL);
|
String passphrase = data.getString(EDIT_KEYRING_PASSPHRASE);
|
||||||
if (saveParcel == null) {
|
|
||||||
Log.e(Constants.TAG, "bug: missing save_keyring_parcel in data!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Operation */
|
// Operation
|
||||||
PgpKeyOperation keyOperations =
|
EditKeyOperation op = new EditKeyOperation(this, providerHelper, this, mActionCanceled);
|
||||||
new PgpKeyOperation(new ProgressScaler(this, 10, 60, 100), mActionCanceled);
|
EditKeyResult result = op.execute(saveParcel, passphrase);
|
||||||
EditKeyResult modifyResult;
|
|
||||||
|
|
||||||
if (saveParcel.mMasterKeyId != null) {
|
// Result
|
||||||
String passphrase = data.getString(EDIT_KEYRING_PASSPHRASE);
|
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
|
||||||
CanonicalizedSecretKeyRing secRing =
|
|
||||||
new ProviderHelper(this).getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId);
|
|
||||||
|
|
||||||
modifyResult = keyOperations.modifySecretKeyRing(secRing, saveParcel, passphrase);
|
|
||||||
} else {
|
|
||||||
modifyResult = keyOperations.createSecretKeyRing(saveParcel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the edit operation didn't succeed, exit here
|
|
||||||
if (!modifyResult.success()) {
|
|
||||||
// always return SaveKeyringResult, so create one out of the EditKeyResult
|
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, modifyResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UncachedKeyRing ring = modifyResult.getRing();
|
|
||||||
|
|
||||||
// Check if the action was cancelled
|
|
||||||
if (mActionCanceled.get()) {
|
|
||||||
OperationLog log = modifyResult.getLog();
|
|
||||||
// If it wasn't added before, add log entry
|
|
||||||
if (!modifyResult.cancelled()) {
|
|
||||||
log.add(LogType.MSG_OPERATION_CANCELLED, 0);
|
|
||||||
}
|
|
||||||
// If so, just stop without saving
|
|
||||||
modifyResult = new EditKeyResult(
|
|
||||||
EditKeyResult.RESULT_CANCELLED, log, null);
|
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, modifyResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the keyring. The ProviderHelper is initialized with the previous log
|
|
||||||
SaveKeyringResult saveResult = new ProviderHelper(this, modifyResult.getLog())
|
|
||||||
.saveSecretKeyRing(ring, new ProgressScaler(this, 60, 95, 100));
|
|
||||||
|
|
||||||
// If the edit operation didn't succeed, exit here
|
|
||||||
if (!saveResult.success()) {
|
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cache new passphrase
|
|
||||||
if (saveParcel.mNewUnlock != null) {
|
|
||||||
PassphraseCacheService.addCachedPassphrase(this,
|
|
||||||
ring.getMasterKeyId(),
|
|
||||||
ring.getMasterKeyId(),
|
|
||||||
saveParcel.mNewUnlock.mNewPassphrase != null
|
|
||||||
? saveParcel.mNewUnlock.mNewPassphrase
|
|
||||||
: saveParcel.mNewUnlock.mNewPin,
|
|
||||||
ring.getPublicKey().getPrimaryUserIdWithFallback());
|
|
||||||
}
|
|
||||||
|
|
||||||
setProgress(R.string.progress_done, 100, 100);
|
|
||||||
|
|
||||||
// make sure new data is synced into contacts
|
|
||||||
ContactSyncAdapterService.requestSync();
|
|
||||||
|
|
||||||
/* Output */
|
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult);
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendErrorToHandler(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (ACTION_EXPORT_KEYRING.equals(action)) {
|
} else if (ACTION_EXPORT_KEYRING.equals(action)) {
|
||||||
|
|
||||||
@ -430,7 +357,6 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
boolean exportAll = data.getBoolean(EXPORT_ALL);
|
boolean exportAll = data.getBoolean(EXPORT_ALL);
|
||||||
long[] masterKeyIds = exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
|
long[] masterKeyIds = exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
|
||||||
|
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(this, new ProviderHelper(this), this);
|
ImportExportOperation importExportOperation = new ImportExportOperation(this, new ProviderHelper(this), this);
|
||||||
ExportResult result;
|
ExportResult result;
|
||||||
|
@ -34,6 +34,7 @@ import android.widget.TextView;
|
|||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
@ -190,14 +191,14 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
if (returnData == null) {
|
if (returnData == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final SaveKeyringResult result =
|
final EditKeyResult result =
|
||||||
returnData.getParcelable(OperationResult.EXTRA_RESULT);
|
returnData.getParcelable(OperationResult.EXTRA_RESULT);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
Log.e(Constants.TAG, "result == null");
|
Log.e(Constants.TAG, "result == null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mUploadCheckbox.isChecked()) {
|
if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) {
|
||||||
// result will be displayed after upload
|
// result will be displayed after upload
|
||||||
uploadKey(result);
|
uploadKey(result);
|
||||||
} else {
|
} else {
|
||||||
@ -227,7 +228,8 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadKey(final SaveKeyringResult saveKeyResult) {
|
// TODO move into EditKeyOperation
|
||||||
|
private void uploadKey(final EditKeyResult saveKeyResult) {
|
||||||
// Send all information needed to service to upload key in other thread
|
// Send all information needed to service to upload key in other thread
|
||||||
final Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
final Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
||||||
|
|
||||||
@ -235,7 +237,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
|
|
||||||
// set data uri as path to keyring
|
// set data uri as path to keyring
|
||||||
Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(
|
Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(
|
||||||
saveKeyResult.mRingMasterKeyId);
|
saveKeyResult.mMasterKeyId);
|
||||||
intent.setData(blobUri);
|
intent.setData(blobUri);
|
||||||
|
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
|
@ -859,6 +859,14 @@
|
|||||||
<string name="msg_con_warn_delete_public">"Exception deleting public cache file"</string>
|
<string name="msg_con_warn_delete_public">"Exception deleting public cache file"</string>
|
||||||
<string name="msg_con_warn_delete_secret">"Exception deleting secret cache file"</string>
|
<string name="msg_con_warn_delete_secret">"Exception deleting secret cache file"</string>
|
||||||
|
|
||||||
|
<!-- Edit Key (higher level than modify) -->
|
||||||
|
<string name="msg_ed">"Performing key operation"</string>
|
||||||
|
<string name="msg_ed_caching_new">"Caching new passphrase"</string>
|
||||||
|
<string name="msg_ed_error_no_parcel">"Missing SaveKeyringParcel! (this is a bug, please report)"</string>
|
||||||
|
<string name="msg_ed_error_key_not_found">"Key not found!"</string>
|
||||||
|
<string name="msg_ed_fetching">"Fetching key to modify (%s)"</string>
|
||||||
|
<string name="msg_ed_success">"Key operation successful"</string>
|
||||||
|
|
||||||
<!-- Other messages used in OperationLogs -->
|
<!-- Other messages used in OperationLogs -->
|
||||||
<string name="msg_ek_error_divert">"Editing of NFC keys is not (yet) supported!"</string>
|
<string name="msg_ek_error_divert">"Editing of NFC keys is not (yet) supported!"</string>
|
||||||
<string name="msg_ek_error_dummy">"Cannot edit keyring with stripped master key!"</string>
|
<string name="msg_ek_error_dummy">"Cannot edit keyring with stripped master key!"</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user