diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-09-17 13:45:16 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-09-17 13:45:16 +0200 |
commit | d686c55a0a86ef845795fc03a8a5de44b5fe73cc (patch) | |
tree | d5bb8dfe1d451b392c8c88a3fa8b14b1dd43db1e /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service | |
parent | 3defd194aaa79309c0a0921a63c5ab157081325c (diff) | |
download | open-keychain-d686c55a0a86ef845795fc03a8a5de44b5fe73cc.tar.gz open-keychain-d686c55a0a86ef845795fc03a8a5de44b5fe73cc.tar.bz2 open-keychain-d686c55a0a86ef845795fc03a8a5de44b5fe73cc.zip |
Work on new result handling (WIP)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
4 files changed, 37 insertions, 14 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 19248dfa3..9d06fe22a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -40,6 +40,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; +import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpHelper; @@ -269,6 +270,17 @@ public class KeychainIntentService extends IntentService implements Progressable /* Operation */ PgpSignEncrypt.Builder builder = new PgpSignEncrypt.Builder( new ProviderHelper(this), + new PassphraseCacheInterface() { + @Override + public String getCachedPassphrase(long masterKeyId) throws PassphraseCacheInterface.NoSecretKeyException { + try { + return PassphraseCacheService.getCachedPassphrase( + KeychainIntentService.this, masterKeyId); + } catch (PassphraseCacheService.KeyNotFoundException e) { + throw new PassphraseCacheInterface.NoSecretKeyException(); + } + } + }, inputData, outStream ); builder.setProgressable(this) @@ -342,14 +354,14 @@ public class KeychainIntentService extends IntentService implements Progressable // verification of signatures PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder( new ProviderHelper(this), - new PgpDecryptVerify.PassphraseCache() { + new PassphraseCacheInterface() { @Override - public String getCachedPassphrase(long masterKeyId) { + public String getCachedPassphrase(long masterKeyId) throws PassphraseCacheInterface.NoSecretKeyException { try { return PassphraseCacheService.getCachedPassphrase( KeychainIntentService.this, masterKeyId); } catch (PassphraseCacheService.KeyNotFoundException e) { - return null; + throw new PassphraseCacheInterface.NoSecretKeyException(); } } }, @@ -390,14 +402,14 @@ public class KeychainIntentService extends IntentService implements Progressable // verification of signatures PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder( new ProviderHelper(this), - new PgpDecryptVerify.PassphraseCache() { + new PassphraseCacheInterface() { @Override - public String getCachedPassphrase(long masterKeyId) throws PgpDecryptVerify.NoSecretKeyException { + public String getCachedPassphrase(long masterKeyId) throws PassphraseCacheInterface.NoSecretKeyException { try { return PassphraseCacheService.getCachedPassphrase( KeychainIntentService.this, masterKeyId); } catch (PassphraseCacheService.KeyNotFoundException e) { - throw new PgpDecryptVerify.NoSecretKeyException(); + throw new PassphraseCacheInterface.NoSecretKeyException(); } } }, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java index 18533ffe6..2113c1ab1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java @@ -26,12 +26,12 @@ import org.openintents.openpgp.OpenPgpSignatureResult; public class DecryptVerifyResult extends OperationResult { // the fourth bit indicates a "data pending" result! (it's also a form of non-success) - public static final int RESULT_PENDING = RESULT_ERROR +8; + public static final int RESULT_PENDING = RESULT_ERROR + 8; // fifth to sixth bit in addition indicate specific type of pending - public static final int RESULT_PENDING_ASYM_PASSPHRASE = RESULT_PENDING +16; - public static final int RESULT_PENDING_SYM_PASSPHRASE = RESULT_PENDING +32; - public static final int RESULT_PENDING_NFC = RESULT_PENDING +48; + public static final int RESULT_PENDING_ASYM_PASSPHRASE = RESULT_PENDING + 16; + public static final int RESULT_PENDING_SYM_PASSPHRASE = RESULT_PENDING + 32; + public static final int RESULT_PENDING_NFC = RESULT_PENDING + 48; long mKeyIdPassphraseNeeded; byte[] mNfcSessionKey; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java index 39946a026..714f8d9cf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java @@ -475,7 +475,6 @@ public abstract class OperationResult implements Parcelable { MSG_SE_ERROR_SIGN_KEY(LogLevel.ERROR, R.string.msg_se_error_sign_key), MSG_SE_ERROR_KEY_SIGN (LogLevel.ERROR, R.string.msg_se_error_key_sign), MSG_SE_ERROR_NFC (LogLevel.ERROR, R.string.msg_se_error_nfc), - MSG_SE_ERROR_NO_PASSPHRASE (LogLevel.ERROR, R.string.msg_se_error_no_passphrase), MSG_SE_ERROR_PGP (LogLevel.ERROR, R.string.msg_se_error_pgp), MSG_SE_ERROR_SIG (LogLevel.ERROR, R.string.msg_se_error_sig), MSG_SE_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_se_error_unlock), @@ -484,6 +483,7 @@ public abstract class OperationResult implements Parcelable { MSG_SE_KEY_WARN (LogLevel.WARN, R.string.msg_se_key_warn), MSG_SE_OK (LogLevel.OK, R.string.msg_se_ok), MSG_SE_PENDING_NFC (LogLevel.INFO, R.string.msg_se_pending_nfc), + MSG_SE_PENDING_PASSPHRASE (LogLevel.INFO, R.string.msg_se_pending_passphrase), MSG_SE (LogLevel.DEBUG, R.string.msg_se), MSG_SE_SIGNING (LogLevel.DEBUG, R.string.msg_se_signing), MSG_SE_SIGCRYPTING (LogLevel.DEBUG, R.string.msg_se_sigcrypting), diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java index 9d492e545..e4e843e83 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java @@ -24,15 +24,26 @@ import java.util.Date; public class SignEncryptResult extends OperationResult { // the fourth bit indicates a "data pending" result! (it's also a form of non-success) - public static final int RESULT_PENDING = RESULT_ERROR +8; + public static final int RESULT_PENDING = RESULT_ERROR + 8; // fifth to sixth bit in addition indicate specific type of pending - public static final int RESULT_PENDING_NFC = RESULT_PENDING +16; + public static final int RESULT_PENDING_PASSPHRASE = RESULT_PENDING + 16; + public static final int RESULT_PENDING_NFC = RESULT_PENDING + 32; + + long mKeyIdPassphraseNeeded; byte[] mNfcHash; int mNfcAlgo; Date mNfcTimestamp; + public long getKeyIdPassphraseNeeded() { + return mKeyIdPassphraseNeeded; + } + + public void setKeyIdPassphraseNeeded(long keyIdPassphraseNeeded) { + mKeyIdPassphraseNeeded = keyIdPassphraseNeeded; + } + public void setNfcData(byte[] sessionKey, int nfcAlgo, Date nfcTimestamp) { mNfcHash = sessionKey; mNfcAlgo = nfcAlgo; @@ -52,7 +63,7 @@ public class SignEncryptResult extends OperationResult { } public boolean isPending() { - return (mResult & RESULT_PENDING) != 0; + return (mResult & RESULT_PENDING) == RESULT_PENDING; } public SignEncryptResult(int result, OperationLog log) { |