don't sign in opportunistic mode if sign-only isn't supported

This commit is contained in:
Vincent Breitmoser 2016-10-31 06:09:54 +01:00
parent 98286fd7fb
commit c7a637f21b
4 changed files with 20 additions and 2 deletions

View file

@ -19,6 +19,7 @@ public class ComposeCryptoStatus {
private CryptoProviderState cryptoProviderState;
private CryptoMode cryptoMode;
private boolean cryptoSupportSignOnly;
private boolean allKeysAvailable;
private boolean allKeysVerified;
private boolean hasRecipients;
@ -99,6 +100,10 @@ public class ComposeCryptoStatus {
return cryptoMode == CryptoMode.OPPORTUNISTIC;
}
public boolean isOpportunisticSignOnly() {
return cryptoSupportSignOnly;
}
public boolean isSigningEnabled() {
return cryptoMode != CryptoMode.DISABLE && signingKeyId != null;
}
@ -123,6 +128,7 @@ public class ComposeCryptoStatus {
private Long selfEncryptKeyId;
private List<Recipient> recipients;
private Boolean enablePgpInline;
private Boolean cryptoSupportSignOnly;
public ComposeCryptoStatusBuilder setCryptoProviderState(CryptoProviderState cryptoProviderState) {
this.cryptoProviderState = cryptoProviderState;
@ -134,6 +140,11 @@ public class ComposeCryptoStatus {
return this;
}
public ComposeCryptoStatusBuilder setCryptoSupportSignOnly(boolean cryptoSupportSignOnly) {
this.cryptoSupportSignOnly = cryptoSupportSignOnly;
return this;
}
public ComposeCryptoStatusBuilder setSigningKeyId(long signingKeyId) {
this.signingKeyId = signingKeyId;
return this;
@ -167,6 +178,9 @@ public class ComposeCryptoStatus {
if (enablePgpInline == null) {
throw new AssertionError("enablePgpInline must be set!");
}
if (cryptoSupportSignOnly == null) {
throw new AssertionError("supportSignOnly must be set!");
}
ArrayList<String> recipientAddresses = new ArrayList<>();
boolean allKeysAvailable = true;
@ -187,6 +201,7 @@ public class ComposeCryptoStatus {
ComposeCryptoStatus result = new ComposeCryptoStatus();
result.cryptoProviderState = cryptoProviderState;
result.cryptoMode = cryptoMode;
result.cryptoSupportSignOnly = cryptoSupportSignOnly;
result.recipientAddresses = recipientAddresses.toArray(new String[0]);
result.allKeysAvailable = allKeysAvailable;
result.allKeysVerified = allKeysVerified;

View file

@ -354,6 +354,7 @@ public class RecipientPresenter implements PermissionPingCallback {
ComposeCryptoStatusBuilder builder = new ComposeCryptoStatusBuilder()
.setCryptoProviderState(cryptoProviderState)
.setCryptoMode(currentCryptoMode)
.setCryptoSupportSignOnly(account.getCryptoSupportSignOnly())
.setEnablePgpInline(cryptoEnablePgpInline)
.setRecipients(getAllRecipients());

View file

@ -128,7 +128,8 @@ public class PgpMessageBuilder extends MessageBuilder {
return;
}
if (opportunisticSkipEncryption && !opportunisticSecondPass) {
boolean shouldSignOnly = cryptoStatus.isOpportunisticSignOnly();
if (opportunisticSkipEncryption && shouldSignOnly && !opportunisticSecondPass) {
opportunisticSecondPass = true;
startOrContinueBuildMessage(null);
return;

View file

@ -412,7 +412,8 @@ public class PgpMessageBuilderTest {
.setSigningKeyId(TEST_SIGN_KEY_ID)
.setSelfEncryptId(TEST_SELF_ENCRYPT_KEY_ID)
.setRecipients(new ArrayList<Recipient>())
.setCryptoProviderState(CryptoProviderState.OK);
.setCryptoProviderState(CryptoProviderState.OK)
.setCryptoSupportSignOnly(true);
}
private static PgpMessageBuilder createDefaultPgpMessageBuilder(OpenPgpApi openPgpApi) {