Merge pull request #2226 from open-keychain/multi-passphrase

Handle decryption with multiple candidate keys
This commit is contained in:
Vincent Breitmoser
2018-01-12 15:10:25 +01:00
committed by GitHub
10 changed files with 262 additions and 172 deletions

View File

@@ -175,7 +175,7 @@ public class AuthenticationOperationTest {
.createAuthenticationParcel(authData.build(), challenge);
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel();
inputParcel = inputParcel.withPassphrase(mKeyPhrase);
inputParcel = inputParcel.withPassphrase(mKeyPhrase, authSubKeyId);
AuthenticationResult result = op.execute(authData.build(), inputParcel, authenticationParcel);
@@ -221,7 +221,7 @@ public class AuthenticationOperationTest {
.createAuthenticationParcel(authData.build(), challenge);
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel();
inputParcel = inputParcel.withPassphrase(mKeyPhrase);
inputParcel = inputParcel.withPassphrase(mKeyPhrase, authSubKeyId);
AuthenticationResult result = op.execute(authData.build(), inputParcel, authenticationParcel);
@@ -267,7 +267,7 @@ public class AuthenticationOperationTest {
.createAuthenticationParcel(authData.build(), challenge);
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel();
inputParcel = inputParcel.withPassphrase(mKeyPhrase);
inputParcel = inputParcel.withPassphrase(mKeyPhrase, authSubKeyId);
AuthenticationResult result = op.execute(authData.build(), inputParcel, authenticationParcel);
@@ -315,7 +315,7 @@ public class AuthenticationOperationTest {
.createAuthenticationParcel(authData.build(), challenge);
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel();
inputParcel = inputParcel.withPassphrase(mKeyPhrase);
inputParcel = inputParcel.withPassphrase(mKeyPhrase, authSubKeyId);
AuthenticationResult result = op.execute(authData.build(), inputParcel, authenticationParcel);
@@ -364,7 +364,7 @@ public class AuthenticationOperationTest {
.createAuthenticationParcel(authData.build(), challenge);
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel();
inputParcel = inputParcel.withPassphrase(mKeyPhrase);
inputParcel = inputParcel.withPassphrase(mKeyPhrase, authSubKeyId);
AuthenticationResult result = op.execute(authData.build(), inputParcel, authenticationParcel);
@@ -387,7 +387,7 @@ public class AuthenticationOperationTest {
.createAuthenticationParcel(authData.build(), challenge);
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel();
inputParcel = inputParcel.withPassphrase(mKeyPhrase);
inputParcel = inputParcel.withPassphrase(mKeyPhrase, authSubKeyId);
AuthenticationResult result = op.execute(authData.build(), inputParcel, authenticationParcel);

View File

@@ -58,6 +58,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType;
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;
@@ -1064,6 +1065,25 @@ public class PgpEncryptDecryptTest {
Assert.assertEquals(1024, encryptionKeySecurityProblem.bitStrength);
}
@Test
public void testDecryptForTwoKeys() throws Exception {
InputStream in = getResourceAsStream("/test-ciphertexts/two_keys.asc");
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
RequiredInputParcel requiredInputParcel = result.getRequiredInputParcel();
Assert.assertNotNull(requiredInputParcel);
Assert.assertEquals(3, requiredInputParcel.getMasterKeyIds().length);
Assert.assertEquals(mStaticRing1.getMasterKeyId(), requiredInputParcel.getMasterKeyIds()[0]);
Assert.assertEquals(mStaticRing1.getMasterKeyId(), requiredInputParcel.getMasterKeyIds()[1]);
Assert.assertEquals(mStaticRing2.getMasterKeyId(), requiredInputParcel.getMasterKeyIds()[2]);
}
private PgpDecryptVerifyOperation operationWithFakePassphraseCache(
final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) {