diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index a8751bac0..b23662a6e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -34,6 +34,7 @@ import org.sufficientlysecure.keychain.nfc.NfcActivity; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; +import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpHelper; @@ -246,7 +247,7 @@ public class OpenPgpService extends RemoteService { // carefully: only set if timestamp exists Date nfcCreationDate = null; long nfcCreationTimestamp = data.getLongExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, 0); - if (nfcCreationTimestamp > 0) { + if (nfcCreationTimestamp != 0) { nfcCreationDate = new Date(nfcCreationTimestamp); } @@ -257,6 +258,11 @@ public class OpenPgpService extends RemoteService { long inputLength = is.available(); InputData inputData = new InputData(is, inputLength); + // Find the appropriate subkey to sign with + CachedPublicKeyRing signingRing = + new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId()); + long sigSubKeyId = signingRing.getSignId(); + // sign-only PgpSignEncrypt.Builder builder = new PgpSignEncrypt.Builder( new ProviderHelper(getContext()), @@ -276,6 +282,7 @@ public class OpenPgpService extends RemoteService { .setVersionHeader(PgpHelper.getVersionForHeader(this)) .setSignatureHashAlgorithm(accSettings.getHashAlgorithm()) .setSignatureMasterKeyId(accSettings.getKeyId()) + .setSignatureSubKeyId(sigSubKeyId) .setSignaturePassphrase(passphrase) .setNfcState(nfcSignedHash, nfcCreationDate); @@ -398,13 +405,19 @@ public class OpenPgpService extends RemoteService { // carefully: only set if timestamp exists Date nfcCreationDate = null; long nfcCreationTimestamp = data.getLongExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, 0); - if (nfcCreationTimestamp > 0) { + if (nfcCreationTimestamp != 0) { nfcCreationDate = new Date(nfcCreationTimestamp); } + // Find the appropriate subkey to sign with + CachedPublicKeyRing signingRing = + new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId()); + long sigSubKeyId = signingRing.getSignId(); + // sign and encrypt builder.setSignatureHashAlgorithm(accSettings.getHashAlgorithm()) .setSignatureMasterKeyId(accSettings.getKeyId()) + .setSignatureSubKeyId(sigSubKeyId) .setSignaturePassphrase(passphrase) .setNfcState(nfcSignedHash, nfcCreationDate); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java index dad1f19a8..fc206aaf5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java @@ -340,7 +340,7 @@ public class KeyFormattingUtils { public static final int STATE_UNAVAILABLE = 4; /** - * returns true if status has been set, if false no status! + * Sets status image based on constant */ public static void setStatusImage(Context context, ImageView statusView, int state) { switch (state) {