Merge branch 'master' into backup-api
Conflicts: OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java extern/openpgp-api-lib
This commit is contained in:
@@ -50,7 +50,6 @@ import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
|
||||
@@ -41,9 +41,9 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
@@ -84,7 +84,7 @@ public class CertifyOperationTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L));
|
||||
parcel.mAddUserIds.add("derp");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(mKeyPhrase1));
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||
@@ -108,7 +108,7 @@ public class CertifyOperationTest {
|
||||
parcel.mAddUserAttribute.add(
|
||||
WrappedUserAttribute.fromSubpacket(random.nextInt(100)+1, uatdata));
|
||||
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase2);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(mKeyPhrase2));
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||
|
||||
@@ -31,6 +31,8 @@ import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -40,8 +42,6 @@ import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowLog;
|
||||
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
|
||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
@@ -57,9 +57,9 @@ import org.sufficientlysecure.keychain.pgp.WrappedSignature;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
|
||||
import org.sufficientlysecure.keychain.service.BackupKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
@@ -106,7 +106,7 @@ public class ExportTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L));
|
||||
parcel.mAddUserIds.add("snips");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(mKeyPhrase1));
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
assertTrue("initial test key creation must succeed", result.success());
|
||||
@@ -124,13 +124,14 @@ public class ExportTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L));
|
||||
parcel.mAddUserIds.add("snails");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(null, new Passphrase("1234"));
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase("1234")));
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
assertTrue("initial test key creation must succeed", result.success());
|
||||
Assert.assertNotNull("initial test key creation must succeed", result.getRing());
|
||||
|
||||
mStaticRing2 = result.getRing();
|
||||
mStaticRing2 = UncachedKeyRing.forTestingOnlyAddDummyLocalSignature(mStaticRing2, "1234");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,10 +45,10 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
@@ -80,7 +80,7 @@ public class PromoteKeyOperationTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L));
|
||||
parcel.mAddUserIds.add("derp");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(mKeyPhrase1));
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||
|
||||
@@ -54,9 +54,9 @@ import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType;
|
||||
@@ -103,7 +103,7 @@ public class PgpEncryptDecryptTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L));
|
||||
parcel.mAddUserIds.add("bloom");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(mKeyPhrase1));
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||
@@ -121,7 +121,7 @@ public class PgpEncryptDecryptTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L));
|
||||
parcel.mAddUserIds.add("belle");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase2);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(mKeyPhrase2));
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||
|
||||
@@ -45,10 +45,9 @@ import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
|
||||
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.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
@@ -110,7 +109,7 @@ public class PgpKeyOperationTest {
|
||||
parcel.mAddUserAttribute.add(uat);
|
||||
}
|
||||
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
@@ -150,7 +149,7 @@ public class PgpKeyOperationTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.RSA, new Random().nextInt(256)+255, null, KeyFlags.CERTIFY_OTHER, 0L));
|
||||
parcel.mAddUserIds.add("shy");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
|
||||
assertFailure("creating ring with < 2048 bit keysize should fail", parcel,
|
||||
LogType.MSG_CR_ERROR_KEYSIZE_2048);
|
||||
@@ -161,7 +160,7 @@ public class PgpKeyOperationTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ELGAMAL, 2048, null, KeyFlags.CERTIFY_OTHER, 0L));
|
||||
parcel.mAddUserIds.add("shy");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
|
||||
assertFailure("creating ring with ElGamal master key should fail", parcel,
|
||||
LogType.MSG_CR_ERROR_FLAGS_ELGAMAL);
|
||||
@@ -172,7 +171,7 @@ public class PgpKeyOperationTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDSA, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.CERTIFY_OTHER, null));
|
||||
parcel.mAddUserIds.add("lotus");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
|
||||
assertFailure("creating master key with null expiry should fail", parcel,
|
||||
LogType.MSG_CR_ERROR_NULL_EXPIRY);
|
||||
@@ -183,7 +182,7 @@ public class PgpKeyOperationTest {
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDSA, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.SIGN_DATA, 0L));
|
||||
parcel.mAddUserIds.add("shy");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
|
||||
assertFailure("creating ring with non-certifying master key should fail", parcel,
|
||||
LogType.MSG_CR_ERROR_NO_CERTIFY);
|
||||
@@ -193,7 +192,7 @@ public class PgpKeyOperationTest {
|
||||
parcel.reset();
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ECDSA, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.CERTIFY_OTHER, 0L));
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
|
||||
assertFailure("creating ring without user ids should fail", parcel,
|
||||
LogType.MSG_CR_ERROR_NO_USER_ID);
|
||||
@@ -202,7 +201,7 @@ public class PgpKeyOperationTest {
|
||||
{
|
||||
parcel.reset();
|
||||
parcel.mAddUserIds.add("shy");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
|
||||
assertFailure("creating ring with no master key should fail", parcel,
|
||||
LogType.MSG_CR_ERROR_NO_MASTER);
|
||||
@@ -842,7 +841,7 @@ public class PgpKeyOperationTest {
|
||||
|
||||
parcelKey.mAddUserIds.add("yubikey");
|
||||
|
||||
parcelKey.mNewUnlock = new ChangeUnlockParcel(passphrase);
|
||||
parcelKey.setNewUnlock(new ChangeUnlockParcel(passphrase));
|
||||
PgpKeyOperation opSecurityToken = new PgpKeyOperation(null);
|
||||
|
||||
PgpEditKeyResult resultSecurityToken = opSecurityToken.createSecretKeyRing(parcelKey);
|
||||
@@ -877,7 +876,7 @@ public class PgpKeyOperationTest {
|
||||
|
||||
long keyId = KeyringTestingHelper.getSubkeyId(ringSecurityToken, 1);
|
||||
|
||||
{ // moveKeyToSecurityToken should return a pending NFC_MOVE_KEY_TO_CARD result when presented with the RSA-2048
|
||||
{ // moveKeyToSecurityToken should return a pending SECURITY_TOKEN_MOVE_KEY_TO_CARD result when presented with the RSA-2048
|
||||
// key, and then make key divert-to-card when it gets a serial in the cryptoInputParcel.
|
||||
parcelSecurityToken.reset();
|
||||
parcelSecurityToken.mChangeSubKeys.add(new SubkeyChange(keyId, false, true));
|
||||
@@ -887,8 +886,8 @@ public class PgpKeyOperationTest {
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcelSecurityToken);
|
||||
Assert.assertTrue("moveKeyToSecurityToken operation should be pending", result.isPending());
|
||||
Assert.assertEquals("required input should be RequiredInputType.NFC_MOVE_KEY_TO_CARD",
|
||||
result.getRequiredInputParcel().mType, RequiredInputType.NFC_MOVE_KEY_TO_CARD);
|
||||
Assert.assertEquals("required input should be RequiredInputType.SECURITY_TOKEN_MOVE_KEY_TO_CARD",
|
||||
result.getRequiredInputParcel().mType, RequiredInputType.SECURITY_TOKEN_MOVE_KEY_TO_CARD);
|
||||
|
||||
// Create a cryptoInputParcel that matches what the SecurityTokenOperationActivity would return.
|
||||
byte[] keyIdBytes = new byte[8];
|
||||
@@ -921,8 +920,8 @@ public class PgpKeyOperationTest {
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcelSecurityToken);
|
||||
Assert.assertTrue("moveKeyToSecurityToken operation should be pending", result.isPending());
|
||||
Assert.assertEquals("required input should be RequiredInputType.NFC_SIGN",
|
||||
RequiredInputType.NFC_SIGN, result.getRequiredInputParcel().mType);
|
||||
Assert.assertEquals("required input should be RequiredInputType.SECURITY_TOKEN_SIGN",
|
||||
RequiredInputType.SECURITY_TOKEN_SIGN, result.getRequiredInputParcel().mType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1157,7 +1156,7 @@ public class PgpKeyOperationTest {
|
||||
public void testPassphraseChange() throws Exception {
|
||||
|
||||
// change passphrase to empty
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(new Passphrase());
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase()));
|
||||
// note that canonicalization here necessarily strips the empty notation packet
|
||||
UncachedKeyRing modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB, cryptoInput);
|
||||
|
||||
@@ -1172,7 +1171,7 @@ public class PgpKeyOperationTest {
|
||||
// modify keyring, change to non-empty passphrase
|
||||
Passphrase otherPassphrase = TestingUtils.genPassphrase(true);
|
||||
CryptoInputParcel otherCryptoInput = new CryptoInputParcel(otherPassphrase);
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(otherPassphrase);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(otherPassphrase));
|
||||
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB,
|
||||
new CryptoInputParcel(new Date(), new Passphrase()));
|
||||
|
||||
@@ -1198,7 +1197,7 @@ public class PgpKeyOperationTest {
|
||||
PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag);
|
||||
|
||||
Passphrase otherPassphrase2 = TestingUtils.genPassphrase(true);
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(otherPassphrase2);
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(otherPassphrase2));
|
||||
{
|
||||
// if we replace a secret key with one without passphrase
|
||||
modified = KeyringTestingHelper.removePacket(modified, sKeyNoPassphrase.position);
|
||||
@@ -1232,47 +1231,7 @@ public class PgpKeyOperationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnlockPin() throws Exception {
|
||||
|
||||
Passphrase pin = new Passphrase("5235125");
|
||||
|
||||
// change passphrase to a pin type
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(null, pin);
|
||||
UncachedKeyRing modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB);
|
||||
|
||||
Assert.assertEquals("exactly three packets should have been added (the secret keys + notation packet)",
|
||||
3, onlyA.size());
|
||||
Assert.assertEquals("exactly four packets should have been added (the secret keys + notation packet)",
|
||||
4, onlyB.size());
|
||||
|
||||
RawPacket dkSig = onlyB.get(1);
|
||||
Assert.assertEquals("second modified packet should be notation data",
|
||||
PacketTags.SIGNATURE, dkSig.tag);
|
||||
|
||||
// check that notation data contains pin
|
||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
||||
modified.getEncoded(), false, 0);
|
||||
Assert.assertEquals("secret key type should be 'pin' after this",
|
||||
SecretKeyType.PIN,
|
||||
secretRing.getSecretKey().getSecretKeyTypeSuperExpensive());
|
||||
|
||||
// need to sleep for a sec, so the timestamp changes for notation data
|
||||
Thread.sleep(1000);
|
||||
|
||||
{
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(new Passphrase("phrayse"), null);
|
||||
applyModificationWithChecks(parcel, modified, onlyA, onlyB, new CryptoInputParcel(pin), true, false);
|
||||
|
||||
Assert.assertEquals("exactly four packets should have been removed (the secret keys + notation packet)",
|
||||
4, onlyA.size());
|
||||
Assert.assertEquals("exactly three packets should have been added (no more notation packet)",
|
||||
3, onlyB.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestricted () throws Exception {
|
||||
public void testRestricted() throws Exception {
|
||||
|
||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
|
||||
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = WorkaroundBuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
|
||||
public class KeyRingTest {
|
||||
public class SplitUserIdTest {
|
||||
|
||||
@Test
|
||||
public void splitCompleteUserIdShouldReturnAll3Components() throws Exception {
|
||||
@@ -49,9 +49,40 @@ public class KeyRingTest {
|
||||
@Test
|
||||
public void splitUserIdWithAllButEmailShouldReturnNameAndComment() throws Exception {
|
||||
KeyRing.UserId info = KeyRing.splitUserId("Max Mustermann (this is a comment)");
|
||||
Assert.assertEquals(info.name, "Max Mustermann");
|
||||
Assert.assertEquals(info.comment, "this is a comment");
|
||||
Assert.assertEquals("Max Mustermann", info.name);
|
||||
Assert.assertEquals("this is a comment", info.comment);
|
||||
Assert.assertNull(info.email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitUserIdWithCommentAndEmailShouldReturnCommentAndEmail() throws Exception {
|
||||
KeyRing.UserId info = KeyRing.splitUserId(" (this is a comment) <max@example.com>");
|
||||
Assert.assertNull(info.name);
|
||||
Assert.assertEquals("this is a comment", info.comment);
|
||||
Assert.assertEquals("max@example.com", info.email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitUserIdWithEmailShouldReturnEmail() throws Exception {
|
||||
KeyRing.UserId info = KeyRing.splitUserId("max@example.com");
|
||||
Assert.assertNull(info.name);
|
||||
Assert.assertNull(info.comment);
|
||||
Assert.assertEquals("max@example.com", info.email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitUserIdWithNameShouldReturnName() throws Exception {
|
||||
KeyRing.UserId info = KeyRing.splitUserId("Max Mustermann");
|
||||
Assert.assertEquals("Max Mustermann", info.name);
|
||||
Assert.assertNull(info.comment);
|
||||
Assert.assertNull(info.email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitUserIdWithCommentShouldReturnComment() throws Exception {
|
||||
KeyRing.UserId info = KeyRing.splitUserId(" (this is a comment)");
|
||||
Assert.assertNull(info.name);
|
||||
Assert.assertEquals("this is a comment", info.comment);
|
||||
Assert.assertNull(info.email);
|
||||
}
|
||||
}
|
||||
@@ -58,11 +58,11 @@ import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;
|
||||
@@ -117,7 +117,7 @@ public class UncachedKeyringCanonicalizeTest {
|
||||
}
|
||||
|
||||
// passphrase is tested in PgpKeyOperationTest, just use empty here
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(new Passphrase());
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase()));
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
|
||||
@@ -41,9 +41,9 @@ import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpCertifyOperation.PgpCertifyResult;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;
|
||||
@@ -114,7 +114,7 @@ public class UncachedKeyringMergeTest {
|
||||
}
|
||||
|
||||
// passphrase is tested in PgpKeyOperationTest, just use empty here
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(new Passphrase());
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase()));
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
|
||||
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
||||
@@ -131,7 +131,7 @@ public class UncachedKeyringMergeTest {
|
||||
|
||||
parcel.mAddUserIds.add("shy");
|
||||
// passphrase is tested in PgpKeyOperationTest, just use empty here
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(new Passphrase());
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase()));
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
|
||||
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
||||
|
||||
@@ -34,9 +34,9 @@ import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
|
||||
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -78,7 +78,7 @@ public class UncachedKeyringTest {
|
||||
parcel.mAddUserAttribute.add(uat);
|
||||
}
|
||||
// passphrase is tested in PgpKeyOperationTest, just use empty here
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(new Passphrase());
|
||||
parcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase()));
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
|
||||
Reference in New Issue
Block a user