Fix sign via API

This commit is contained in:
Dominik Schürmann 2014-09-18 13:19:57 +02:00
parent 9586d6b9b8
commit 91e97d03a1
2 changed files with 16 additions and 3 deletions

View File

@ -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);
}

View File

@ -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) {