aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-10-12 19:22:34 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-10-12 19:22:34 +0200
commitb47412eb1e2b983f803e6227ea5d07fdead9fe5a (patch)
tree39e8f98f500f052396e3a34dcce358a96cf8a899 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java
parent93aefaca8ef4a7c47c5822a49e9144e037da0d9d (diff)
downloadopen-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/CertifyOperation.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java147
1 files changed, 147 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java
new file mode 100644
index 000000000..d27221c20
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java
@@ -0,0 +1,147 @@
+package org.sufficientlysecure.keychain.operations;
+
+import android.content.Context;
+
+import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
+import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
+import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
+import org.sufficientlysecure.keychain.pgp.Progressable;
+import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
+import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
+import org.sufficientlysecure.keychain.provider.ProviderHelper;
+import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
+import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
+import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
+import org.sufficientlysecure.keychain.operations.results.CertifyResult;
+import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
+import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
+import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
+import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
+
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class CertifyOperation extends BaseOperation {
+
+ public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) {
+ super(context, providerHelper, progressable, cancelled);
+ }
+
+ public CertifyResult certify(CertifyActionsParcel parcel) {
+
+ OperationLog log = new OperationLog();
+ log.add(LogType.MSG_CRT, 0);
+
+ // 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);
+ log.add(LogType.MSG_CRT_UNLOCK, 1);
+ certificationKey = secretKeyRing.getSecretKey();
+ if (!certificationKey.unlock(passphrase)) {
+ log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2);
+ return new CertifyResult(CertifyResult.RESULT_ERROR, log);
+ }
+ } catch (PgpGeneralException e) {
+ log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2);
+ return new CertifyResult(CertifyResult.RESULT_ERROR, log);
+ } 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>();
+
+ log.add(LogType.MSG_CRT_CERTIFYING, 1);
+
+ int certifyOk = 0, certifyError = 0;
+
+ // Work through all requested certifications
+ for (CertifyAction action : parcel.mCertifyActions) {
+
+ // Check if we were cancelled
+ if (checkCancelled()) {
+ log.add(LogType.MSG_OPERATION_CANCELLED, 0);
+ return new CertifyResult(CertifyResult.RESULT_CANCELLED, log);
+ }
+
+ try {
+
+ if (action.mUserIds == null) {
+ log.add(LogType.MSG_CRT_CERTIFY_ALL, 2,
+ KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId));
+ } else {
+ log.add(LogType.MSG_CRT_CERTIFY_SOME, 2, action.mUserIds.size(),
+ KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId));
+ }
+
+ CanonicalizedPublicKeyRing publicRing =
+ 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);
+ }
+
+ }
+
+ log.add(LogType.MSG_CRT_SAVING, 1);
+
+ // Check if we were cancelled
+ if (checkCancelled()) {
+ log.add(LogType.MSG_OPERATION_CANCELLED, 0);
+ return new CertifyResult(CertifyResult.RESULT_CANCELLED, log);
+ }
+
+ // Write all certified keys into the database
+ for (UncachedKeyRing certifiedKey : certifiedKeys) {
+
+ // Check if we were cancelled
+ if (checkCancelled()) {
+ log.add(LogType.MSG_OPERATION_CANCELLED, 0);
+ return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError);
+ }
+
+ log.add(LogType.MSG_CRT_SAVE, 2,
+ KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId()));
+ // store the signed key in our local cache
+ mProviderHelper.clearLog();
+ SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey);
+
+ if (result.success()) {
+ certifyOk += 1;
+ } else {
+ log.add(LogType.MSG_CRT_WARN_SAVE_FAILED, 3);
+ }
+
+ log.add(result, 2);
+
+ }
+
+ if (certifyOk == 0) {
+ log.add(LogType.MSG_CRT_ERROR_NOTHING, 0);
+ return new CertifyResult(CertifyResult.RESULT_ERROR, log, certifyOk, certifyError);
+ }
+
+ log.add(LogType.MSG_CRT_SUCCESS, 0);
+ return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError);
+
+ }
+
+}