diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-10-12 19:22:34 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-10-12 19:22:34 +0200 |
commit | b47412eb1e2b983f803e6227ea5d07fdead9fe5a (patch) | |
tree | 39e8f98f500f052396e3a34dcce358a96cf8a899 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations | |
parent | 93aefaca8ef4a7c47c5822a49e9144e037da0d9d (diff) | |
download | open-keychain-b47412eb1e2b983f803e6227ea5d07fdead9fe5a.tar.gz open-keychain-b47412eb1e2b983f803e6227ea5d07fdead9fe5a.tar.bz2 open-keychain-b47412eb1e2b983f803e6227ea5d07fdead9fe5a.zip |
CertifyOperation is not a Pgp- operation
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java | 25 | ||||
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PgpCertifyOperation.java) | 26 |
2 files changed, 38 insertions, 13 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java index 01889ed82..09d7a0063 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java @@ -2,12 +2,15 @@ package org.sufficientlysecure.keychain.operations; import android.content.Context; +import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.service.PassphraseCacheService; import java.util.concurrent.atomic.AtomicBoolean; -public class BaseOperation { +public class BaseOperation implements PassphraseCacheInterface { final public Context mContext; final public Progressable mProgressable; @@ -52,4 +55,24 @@ public class BaseOperation { return mCancelled != null && mCancelled.get(); } + @Override + public String getCachedPassphrase(long subKeyId) throws NoSecretKeyException { + try { + long masterKeyId = mProviderHelper.getMasterKeyId(subKeyId); + return getCachedPassphrase(masterKeyId, subKeyId); + } catch (NotFoundException e) { + throw new PassphraseCacheInterface.NoSecretKeyException(); + } + } + + @Override + public String getCachedPassphrase(long masterKeyId, long subKeyId) throws NoSecretKeyException { + try { + return PassphraseCacheService.getCachedPassphrase( + mContext, masterKeyId, subKeyId); + } catch (PassphraseCacheService.KeyNotFoundException e) { + throw new PassphraseCacheInterface.NoSecretKeyException(); + } + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PgpCertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java index 845326791..d27221c20 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PgpCertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -2,8 +2,6 @@ package org.sufficientlysecure.keychain.operations; import android.content.Context; -import org.spongycastle.openpgp.PGPException; -import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; @@ -19,18 +17,17 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; -import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; -public class PgpCertifyOperation extends BaseOperation { +public class CertifyOperation extends BaseOperation { - public PgpCertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { + public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { super(context, providerHelper, progressable, cancelled); } - public CertifyResult certify(CertifyActionsParcel parcel, String passphrase) { + public CertifyResult certify(CertifyActionsParcel parcel) { OperationLog log = new OperationLog(); log.add(LogType.MSG_CRT, 0); @@ -38,6 +35,10 @@ public class PgpCertifyOperation extends BaseOperation { // Retrieve and unlock secret key CanonicalizedSecretKey certificationKey; try { + + // certification is always with the master key id, so use that one + String passphrase = getCachedPassphrase(parcel.mMasterKeyId, parcel.mMasterKeyId); + log.add(LogType.MSG_CRT_MASTER_FETCH, 1); CanonicalizedSecretKeyRing secretKeyRing = mProviderHelper.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); @@ -53,6 +54,9 @@ public class PgpCertifyOperation extends BaseOperation { } catch (NotFoundException e) { log.add(LogType.MSG_CRT_ERROR_MASTER_NOT_FOUND, 2); return new CertifyResult(CertifyResult.RESULT_ERROR, log); + } catch (NoSecretKeyException e) { + log.add(LogType.MSG_CRT_ERROR_MASTER_NOT_FOUND, 2); + return new CertifyResult(CertifyResult.RESULT_ERROR, log); } ArrayList<UncachedKeyRing> certifiedKeys = new ArrayList<UncachedKeyRing>(); @@ -84,15 +88,15 @@ public class PgpCertifyOperation extends BaseOperation { mProviderHelper.getCanonicalizedPublicKeyRing(action.mMasterKeyId); UncachedKeyRing certifiedKey = certificationKey.certifyUserIds(publicRing, action.mUserIds, null, null); + if (certifiedKey == null) { + certifyError += 1; + log.add(LogType.MSG_CRT_WARN_CERT_FAILED, 3); + } certifiedKeys.add(certifiedKey); } catch (NotFoundException e) { certifyError += 1; log.add(LogType.MSG_CRT_WARN_NOT_FOUND, 3); - } catch (PGPException e) { - certifyError += 1; - log.add(LogType.MSG_CRT_WARN_CERT_FAILED, 3); - Log.e(Constants.TAG, "Encountered PGPException during certification", e); } } @@ -128,8 +132,6 @@ public class PgpCertifyOperation extends BaseOperation { log.add(result, 2); - // TODO do something with import results - } if (certifyOk == 0) { |