mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-15 21:35:05 -05:00
fix more unit tests (syntax)
This commit is contained in:
parent
3fce6d8a12
commit
e00ce86de9
@ -46,6 +46,7 @@ import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyActio
|
|||||||
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;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
@ -152,8 +153,8 @@ public class CertifyOperationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCertifyId() throws Exception {
|
public void testCertifyId() throws Exception {
|
||||||
CertifyOperation op = operationWithFakePassphraseCache(
|
CertifyOperation op = new CertifyOperation(Robolectric.application,
|
||||||
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(), mKeyPhrase1);
|
new ProviderHelper(Robolectric.application), null, null);
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application)
|
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application)
|
||||||
@ -165,7 +166,7 @@ public class CertifyOperationTest {
|
|||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, new CryptoInputParcel(mKeyPhrase1), null);
|
||||||
|
|
||||||
Assert.assertTrue("certification must succeed", result.success());
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
|
|
||||||
@ -180,8 +181,8 @@ public class CertifyOperationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCertifyAttribute() throws Exception {
|
public void testCertifyAttribute() throws Exception {
|
||||||
CertifyOperation op = operationWithFakePassphraseCache(
|
CertifyOperation op = new CertifyOperation(Robolectric.application,
|
||||||
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(), mKeyPhrase1);
|
new ProviderHelper(Robolectric.application), null, null);
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application)
|
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application)
|
||||||
@ -193,7 +194,7 @@ public class CertifyOperationTest {
|
|||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), null,
|
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), null,
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserAttributes()));
|
mStaticRing2.getPublicKey().getUnorderedUserAttributes()));
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, new CryptoInputParcel(mKeyPhrase1), null);
|
||||||
|
|
||||||
Assert.assertTrue("certification must succeed", result.success());
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
|
|
||||||
@ -209,14 +210,14 @@ public class CertifyOperationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCertifySelf() throws Exception {
|
public void testCertifySelf() throws Exception {
|
||||||
CertifyOperation op = operationWithFakePassphraseCache(
|
CertifyOperation op = new CertifyOperation(Robolectric.application,
|
||||||
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(), mKeyPhrase1);
|
new ProviderHelper(Robolectric.application), null, null);
|
||||||
|
|
||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
||||||
|
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, new CryptoInputParcel(mKeyPhrase1), null);
|
||||||
|
|
||||||
Assert.assertFalse("certification with itself must fail!", result.success());
|
Assert.assertFalse("certification with itself must fail!", result.success());
|
||||||
Assert.assertTrue("error msg must be about self certification",
|
Assert.assertTrue("error msg must be about self certification",
|
||||||
@ -226,7 +227,8 @@ public class CertifyOperationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCertifyNonexistent() throws Exception {
|
public void testCertifyNonexistent() throws Exception {
|
||||||
|
|
||||||
CertifyOperation op = operationWithFakePassphraseCache(null, null, mKeyPhrase1);
|
CertifyOperation op = new CertifyOperation(Robolectric.application,
|
||||||
|
new ProviderHelper(Robolectric.application), null, null);
|
||||||
|
|
||||||
{
|
{
|
||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
@ -234,7 +236,7 @@ public class CertifyOperationTest {
|
|||||||
uids.add("nonexistent");
|
uids.add("nonexistent");
|
||||||
actions.add(new CertifyAction(1234L, uids));
|
actions.add(new CertifyAction(1234L, uids));
|
||||||
|
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, new CryptoInputParcel(mKeyPhrase1), null);
|
||||||
|
|
||||||
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
||||||
Assert.assertTrue("must contain error msg about not found",
|
Assert.assertTrue("must contain error msg about not found",
|
||||||
@ -246,7 +248,7 @@ public class CertifyOperationTest {
|
|||||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
||||||
|
|
||||||
CertifyResult result = op.certify(actions, null);
|
CertifyResult result = op.certify(actions, new CryptoInputParcel(mKeyPhrase1), null);
|
||||||
|
|
||||||
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
||||||
Assert.assertTrue("must contain error msg about not found",
|
Assert.assertTrue("must contain error msg about not found",
|
||||||
@ -255,29 +257,4 @@ public class CertifyOperationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CertifyOperation operationWithFakePassphraseCache(
|
|
||||||
final Long checkMasterKeyId, final Long checkSubKeyId, final Passphrase passphrase) {
|
|
||||||
|
|
||||||
return new CertifyOperation(Robolectric.application,
|
|
||||||
new ProviderHelper(Robolectric.application),
|
|
||||||
null, null) {
|
|
||||||
@Override
|
|
||||||
public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId)
|
|
||||||
throws NoSecretKeyException {
|
|
||||||
if (checkMasterKeyId != null) {
|
|
||||||
Assert.assertEquals("requested passphrase should be for expected master key id",
|
|
||||||
(long) checkMasterKeyId, masterKeyId);
|
|
||||||
}
|
|
||||||
if (checkSubKeyId != null) {
|
|
||||||
Assert.assertEquals("requested passphrase should be for expected sub key id",
|
|
||||||
(long) checkSubKeyId, subKeyId);
|
|
||||||
}
|
|
||||||
if (passphrase == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return passphrase;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpSignEncryptInputParcel b = new setSignatureTimestamp();
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel();
|
||||||
b.setSymmetricPassphrase(mPassphrase);
|
b.setSymmetricPassphrase(mPassphrase);
|
||||||
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
|
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
new ProviderHelper(Robolectric.application), null);
|
new ProviderHelper(Robolectric.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
PgpSignEncryptInputParcel b = new setSignatureTimestamp();
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel();
|
||||||
|
|
||||||
b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() });
|
b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() });
|
||||||
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
|
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
|
||||||
@ -303,7 +303,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpSignEncryptInputParcel b = new setSignatureTimestamp();
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel();
|
||||||
b.setEncryptionMasterKeyIds(new long[] {
|
b.setEncryptionMasterKeyIds(new long[] {
|
||||||
mStaticRing1.getMasterKeyId(),
|
mStaticRing1.getMasterKeyId(),
|
||||||
mStaticRing2.getMasterKeyId()
|
mStaticRing2.getMasterKeyId()
|
||||||
@ -395,7 +395,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
new ProviderHelper(Robolectric.application), null);
|
new ProviderHelper(Robolectric.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
PgpSignEncryptInputParcel b = new setSignatureTimestamp();
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel();
|
||||||
|
|
||||||
b.setEncryptionMasterKeyIds(new long[] {
|
b.setEncryptionMasterKeyIds(new long[] {
|
||||||
mStaticRing1.getMasterKeyId(),
|
mStaticRing1.getMasterKeyId(),
|
||||||
@ -477,7 +477,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
new ProviderHelper(Robolectric.application), null);
|
new ProviderHelper(Robolectric.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
PgpSignEncryptInputParcel b = new setSignatureTimestamp();
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel();
|
||||||
|
|
||||||
b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() });
|
b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() });
|
||||||
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
|
b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
|
||||||
|
@ -59,6 +59,7 @@ import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
|||||||
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.service.SaveKeyringParcel.ChangeUnlockParcel;
|
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;
|
||||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;
|
import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
@ -549,7 +550,10 @@ public class UncachedKeyringCanonicalizeTest {
|
|||||||
CanonicalizedSecretKey masterSecretKey = canonicalized.getSecretKey();
|
CanonicalizedSecretKey masterSecretKey = canonicalized.getSecretKey();
|
||||||
masterSecretKey.unlock(new Passphrase());
|
masterSecretKey.unlock(new Passphrase());
|
||||||
PGPPublicKey masterPublicKey = masterSecretKey.getPublicKey();
|
PGPPublicKey masterPublicKey = masterSecretKey.getPublicKey();
|
||||||
|
CryptoInputParcel cryptoInput = new CryptoInputParcel();
|
||||||
PGPSignature cert = PgpKeyOperation.generateSubkeyBindingSignature(
|
PGPSignature cert = PgpKeyOperation.generateSubkeyBindingSignature(
|
||||||
|
PgpKeyOperation.getSignatureGenerator(masterSecretKey.getSecretKey(), cryptoInput),
|
||||||
|
cryptoInput.getSignatureTime(),
|
||||||
masterPublicKey, masterSecretKey.getPrivateKey(), masterSecretKey.getPrivateKey(),
|
masterPublicKey, masterSecretKey.getPrivateKey(), masterSecretKey.getPrivateKey(),
|
||||||
masterPublicKey, masterSecretKey.getKeyUsage(), 0);
|
masterPublicKey, masterSecretKey.getKeyUsage(), 0);
|
||||||
PGPPublicKey subPubKey = PGPPublicKey.addSubkeyBindingCertification(masterPublicKey, cert);
|
PGPPublicKey subPubKey = PGPPublicKey.addSubkeyBindingCertification(masterPublicKey, cert);
|
||||||
|
@ -35,9 +35,12 @@ 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.PgpEditKeyResult;
|
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.pgp.PgpCertifyOperation.PgpCertifyResult;
|
||||||
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||||
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;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
|
||||||
import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;
|
import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
@ -46,6 +49,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@ -186,11 +190,11 @@ public class UncachedKeyringMergeTest {
|
|||||||
|
|
||||||
parcel.reset();
|
parcel.reset();
|
||||||
parcel.mAddUserIds.add("flim");
|
parcel.mAddUserIds.add("flim");
|
||||||
modifiedA = op.modifySecretKeyRing(secretRing, parcel, new Passphrase()).getRing();
|
modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(), parcel).getRing();
|
||||||
|
|
||||||
parcel.reset();
|
parcel.reset();
|
||||||
parcel.mAddUserIds.add("flam");
|
parcel.mAddUserIds.add("flam");
|
||||||
modifiedB = op.modifySecretKeyRing(secretRing, parcel, new Passphrase()).getRing();
|
modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(), parcel).getRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // merge A into base
|
{ // merge A into base
|
||||||
@ -227,8 +231,8 @@ public class UncachedKeyringMergeTest {
|
|||||||
parcel.reset();
|
parcel.reset();
|
||||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||||
Algorithm.RSA, 1024, null, KeyFlags.SIGN_DATA, 0L));
|
Algorithm.RSA, 1024, null, KeyFlags.SIGN_DATA, 0L));
|
||||||
modifiedA = op.modifySecretKeyRing(secretRing, parcel, new Passphrase()).getRing();
|
modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(), parcel).getRing();
|
||||||
modifiedB = op.modifySecretKeyRing(secretRing, parcel, new Passphrase()).getRing();
|
modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(), parcel).getRing();
|
||||||
|
|
||||||
subKeyIdA = KeyringTestingHelper.getSubkeyId(modifiedA, 2);
|
subKeyIdA = KeyringTestingHelper.getSubkeyId(modifiedA, 2);
|
||||||
subKeyIdB = KeyringTestingHelper.getSubkeyId(modifiedB, 2);
|
subKeyIdB = KeyringTestingHelper.getSubkeyId(modifiedB, 2);
|
||||||
@ -269,7 +273,7 @@ public class UncachedKeyringMergeTest {
|
|||||||
parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(ringA, 1));
|
parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(ringA, 1));
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
||||||
ringA.getEncoded(), false, 0);
|
ringA.getEncoded(), false, 0);
|
||||||
modified = op.modifySecretKeyRing(secretRing, parcel, new Passphrase()).getRing();
|
modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(), parcel).getRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -295,8 +299,13 @@ public class UncachedKeyringMergeTest {
|
|||||||
CanonicalizedSecretKey secretKey = new CanonicalizedSecretKeyRing(
|
CanonicalizedSecretKey secretKey = new CanonicalizedSecretKeyRing(
|
||||||
ringB.getEncoded(), false, 0).getSecretKey();
|
ringB.getEncoded(), false, 0).getSecretKey();
|
||||||
secretKey.unlock(new Passphrase());
|
secretKey.unlock(new Passphrase());
|
||||||
|
PgpCertifyOperation op = new PgpCertifyOperation();
|
||||||
|
CertifyAction action = new CertifyAction(pubRing.getMasterKeyId(), publicRing.getPublicKey().getUnorderedUserIds());
|
||||||
// sign all user ids
|
// sign all user ids
|
||||||
modified = secretKey.certifyUserIds(publicRing, publicRing.getPublicKey().getUnorderedUserIds(), null, null);
|
PgpCertifyResult result = op.certify(secretKey, publicRing, new OperationLog(), 0, action, null, new Date());
|
||||||
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
|
Assert.assertNotNull("certification must yield result", result.getCertifiedRing());
|
||||||
|
modified = result.getCertifiedRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -363,7 +372,7 @@ public class UncachedKeyringMergeTest {
|
|||||||
|
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
||||||
ringA.getEncoded(), false, 0);
|
ringA.getEncoded(), false, 0);
|
||||||
modified = op.modifySecretKeyRing(secretRing, parcel, new Passphrase()).getRing();
|
modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(), parcel).getRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -39,6 +39,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException
|
|||||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.NfcSignOperationsBuilder;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.NfcSignOperationsBuilder;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
@ -63,7 +64,7 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
super(context, providerHelper, progressable, cancelled);
|
super(context, providerHelper, progressable, cancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CertifyResult certify(CertifyActionsParcel parcel, String keyServerUri) {
|
public CertifyResult certify(CertifyActionsParcel parcel, CryptoInputParcel cryptoInput, String keyServerUri) {
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
log.add(LogType.MSG_CRT, 0);
|
log.add(LogType.MSG_CRT, 0);
|
||||||
@ -78,13 +79,13 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
log.add(LogType.MSG_CRT_UNLOCK, 1);
|
log.add(LogType.MSG_CRT_UNLOCK, 1);
|
||||||
certificationKey = secretKeyRing.getSecretKey();
|
certificationKey = secretKeyRing.getSecretKey();
|
||||||
|
|
||||||
if (!parcel.mCryptoInput.hasPassphrase()) {
|
if (!cryptoInput.hasPassphrase()) {
|
||||||
return new CertifyResult(log, RequiredInputParcel.createRequiredPassphrase(
|
return new CertifyResult(log, RequiredInputParcel.createRequiredPassphrase(
|
||||||
certificationKey.getKeyId(), null));
|
certificationKey.getKeyId(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// certification is always with the master key id, so use that one
|
// certification is always with the master key id, so use that one
|
||||||
Passphrase passphrase = parcel.mCryptoInput.getPassphrase();
|
Passphrase passphrase = cryptoInput.getPassphrase();
|
||||||
|
|
||||||
if (!certificationKey.unlock(passphrase)) {
|
if (!certificationKey.unlock(passphrase)) {
|
||||||
log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2);
|
log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2);
|
||||||
@ -104,7 +105,7 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
|
|
||||||
int certifyOk = 0, certifyError = 0, uploadOk = 0, uploadError = 0;
|
int certifyOk = 0, certifyError = 0, uploadOk = 0, uploadError = 0;
|
||||||
|
|
||||||
NfcSignOperationsBuilder allRequiredInput = new NfcSignOperationsBuilder(parcel.mCryptoInput.getSignatureTime());
|
NfcSignOperationsBuilder allRequiredInput = new NfcSignOperationsBuilder(cryptoInput.getSignatureTime());
|
||||||
|
|
||||||
// Work through all requested certifications
|
// Work through all requested certifications
|
||||||
for (CertifyAction action : parcel.mCertifyActions) {
|
for (CertifyAction action : parcel.mCertifyActions) {
|
||||||
@ -128,7 +129,7 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
|
|
||||||
PgpCertifyOperation op = new PgpCertifyOperation();
|
PgpCertifyOperation op = new PgpCertifyOperation();
|
||||||
PgpCertifyResult result = op.certify(certificationKey, publicRing,
|
PgpCertifyResult result = op.certify(certificationKey, publicRing,
|
||||||
log, 2, action, parcel.getSignatureData(), parcel.mCryptoInput.getSignatureTime());
|
log, 2, action, cryptoInput.getCryptoData(), cryptoInput.getSignatureTime());
|
||||||
|
|
||||||
if (!result.success()) {
|
if (!result.success()) {
|
||||||
certifyError += 1;
|
certifyError += 1;
|
||||||
|
@ -292,4 +292,9 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
|||||||
return mPrivateKey;
|
return mPrivateKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK, for TESTING ONLY!!
|
||||||
|
PGPSecretKey getSecretKey() {
|
||||||
|
return mSecretKey;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1283,7 +1283,7 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PGPSignatureGenerator getSignatureGenerator(
|
static PGPSignatureGenerator getSignatureGenerator(
|
||||||
PGPSecretKey secretKey, CryptoInputParcel cryptoInput) {
|
PGPSecretKey secretKey, CryptoInputParcel cryptoInput) {
|
||||||
|
|
||||||
PGPContentSignerBuilder builder;
|
PGPContentSignerBuilder builder;
|
||||||
|
@ -42,17 +42,14 @@ public class CertifyActionsParcel implements Parcelable {
|
|||||||
public CertifyLevel mLevel;
|
public CertifyLevel mLevel;
|
||||||
|
|
||||||
public ArrayList<CertifyAction> mCertifyActions = new ArrayList<>();
|
public ArrayList<CertifyAction> mCertifyActions = new ArrayList<>();
|
||||||
public CryptoInputParcel mCryptoInput;
|
|
||||||
|
|
||||||
public CertifyActionsParcel(CryptoInputParcel cryptoInput, long masterKeyId) {
|
public CertifyActionsParcel(long masterKeyId) {
|
||||||
mMasterKeyId = masterKeyId;
|
mMasterKeyId = masterKeyId;
|
||||||
mCryptoInput = cryptoInput != null ? cryptoInput : new CryptoInputParcel(new Date());
|
|
||||||
mLevel = CertifyLevel.DEFAULT;
|
mLevel = CertifyLevel.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CertifyActionsParcel(Parcel source) {
|
public CertifyActionsParcel(Parcel source) {
|
||||||
mMasterKeyId = source.readLong();
|
mMasterKeyId = source.readLong();
|
||||||
mCryptoInput = source.readParcelable(CertifyActionsParcel.class.getClassLoader());
|
|
||||||
// just like parcelables, this is meant for ad-hoc IPC only and is NOT portable!
|
// just like parcelables, this is meant for ad-hoc IPC only and is NOT portable!
|
||||||
mLevel = CertifyLevel.values()[source.readInt()];
|
mLevel = CertifyLevel.values()[source.readInt()];
|
||||||
|
|
||||||
@ -66,16 +63,11 @@ public class CertifyActionsParcel implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel destination, int flags) {
|
public void writeToParcel(Parcel destination, int flags) {
|
||||||
destination.writeLong(mMasterKeyId);
|
destination.writeLong(mMasterKeyId);
|
||||||
destination.writeParcelable(mCryptoInput, 0);
|
|
||||||
destination.writeInt(mLevel.ordinal());
|
destination.writeInt(mLevel.ordinal());
|
||||||
|
|
||||||
destination.writeSerializable(mCertifyActions);
|
destination.writeSerializable(mCertifyActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<ByteBuffer, byte[]> getSignatureData() {
|
|
||||||
return mCryptoInput.getCryptoData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Creator<CertifyActionsParcel> CREATOR = new Creator<CertifyActionsParcel>() {
|
public static final Creator<CertifyActionsParcel> CREATOR = new Creator<CertifyActionsParcel>() {
|
||||||
public CertifyActionsParcel createFromParcel(final Parcel source) {
|
public CertifyActionsParcel createFromParcel(final Parcel source) {
|
||||||
return new CertifyActionsParcel(source);
|
return new CertifyActionsParcel(source);
|
||||||
|
@ -254,11 +254,12 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
|
|
||||||
// Input
|
// Input
|
||||||
CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
|
CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
|
||||||
|
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
|
String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
CertifyOperation op = new CertifyOperation(this, providerHelper, this, mActionCanceled);
|
CertifyOperation op = new CertifyOperation(this, providerHelper, this, mActionCanceled);
|
||||||
CertifyResult result = op.certify(parcel, keyServerUri);
|
CertifyResult result = op.certify(parcel, cryptoInput, keyServerUri);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
@ -321,9 +321,10 @@ public class CertifyKeyFragment extends CryptoOperationFragment
|
|||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
{
|
{
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
CertifyActionsParcel parcel = new CertifyActionsParcel(cryptoInput, mSignMasterKeyId);
|
CertifyActionsParcel parcel = new CertifyActionsParcel(mSignMasterKeyId);
|
||||||
parcel.mCertifyActions.addAll(certifyActions);
|
parcel.mCertifyActions.addAll(certifyActions);
|
||||||
|
|
||||||
|
data.putParcelable(KeychainIntentService.EXTRA_CRYPTO_INPUT, cryptoInput);
|
||||||
data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel);
|
data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel);
|
||||||
if (mUploadKeyCheckbox.isChecked()) {
|
if (mUploadKeyCheckbox.isChecked()) {
|
||||||
String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver();
|
String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver();
|
||||||
|
Loading…
Reference in New Issue
Block a user