aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-10-04 14:11:51 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-10-04 15:19:43 +0200
commit0e0e3d8dd09deb2ff36d46ccceba08bb5c0967ce (patch)
treeac7eb05d3dd8880e3782a88f979273dc8b93231c /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
parentdcd22d981550bf18cf14362c313640409deaa1c7 (diff)
downloadopen-keychain-0e0e3d8dd09deb2ff36d46ccceba08bb5c0967ce.tar.gz
open-keychain-0e0e3d8dd09deb2ff36d46ccceba08bb5c0967ce.tar.bz2
open-keychain-0e0e3d8dd09deb2ff36d46ccceba08bb5c0967ce.zip
redesign certify action to work with parcel input and result
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java111
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java35
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java57
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java17
4 files changed, 196 insertions, 24 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
new file mode 100644
index 000000000..d2562d728
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sufficientlysecure.keychain.service;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+/**
+ * This class is a a transferable representation for a number of keyrings to
+ * be certified.
+ */
+public class CertifyActionsParcel implements Parcelable {
+
+ // the master key id to certify with
+ final public long mMasterKeyId;
+ public CertifyLevel mLevel;
+
+ public ArrayList<CertifyAction> mCertifyActions = new ArrayList<CertifyAction>();
+
+ public CertifyActionsParcel(long masterKeyId) {
+ mMasterKeyId = masterKeyId;
+ mLevel = CertifyLevel.DEFAULT;
+ }
+
+ public CertifyActionsParcel(Parcel source) {
+ mMasterKeyId = source.readLong();
+ // just like parcelables, this is meant for ad-hoc IPC only and is NOT portable!
+ mLevel = CertifyLevel.values()[source.readInt()];
+
+ mCertifyActions = (ArrayList<CertifyAction>) source.readSerializable();
+ }
+
+ public void add(CertifyAction action) {
+ mCertifyActions.add(action);
+ }
+
+ @Override
+ public void writeToParcel(Parcel destination, int flags) {
+ destination.writeLong(mMasterKeyId);
+ destination.writeInt(mLevel.ordinal());
+
+ destination.writeSerializable(mCertifyActions);
+ }
+
+ public static final Creator<CertifyActionsParcel> CREATOR = new Creator<CertifyActionsParcel>() {
+ public CertifyActionsParcel createFromParcel(final Parcel source) {
+ return new CertifyActionsParcel(source);
+ }
+
+ public CertifyActionsParcel[] newArray(final int size) {
+ return new CertifyActionsParcel[size];
+ }
+ };
+
+ // TODO make this parcelable
+ public static class CertifyAction implements Serializable {
+ final public long mMasterKeyId;
+ final public byte[] mFingerprint;
+
+ final public ArrayList<String> mUserIds;
+
+ public CertifyAction(long masterKeyId, byte[] fingerprint) {
+ this(masterKeyId, fingerprint, null);
+ }
+
+ public CertifyAction(long masterKeyId, byte[] fingerprint, ArrayList<String> userIds) {
+ mMasterKeyId = masterKeyId;
+ mFingerprint = fingerprint;
+ mUserIds = userIds;
+ }
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ String out = "mMasterKeyId: " + mMasterKeyId + "\n";
+ out += "mLevel: " + mLevel + "\n";
+ out += "mCertifyActions: " + mCertifyActions + "\n";
+
+ return out;
+ }
+
+ // All supported algorithms
+ public enum CertifyLevel {
+ DEFAULT, NONE, CASUAL, POSITIVE
+ }
+
+}
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 c131430cf..f5e6dedc2 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -29,7 +29,9 @@ import android.os.RemoteException;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.pgp.PgpCertifyOperation;
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
+import org.sufficientlysecure.keychain.service.results.CertifyResult;
import org.sufficientlysecure.keychain.util.FileHelper;
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
import org.sufficientlysecure.keychain.util.Preferences;
@@ -39,7 +41,6 @@ import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver;
import org.sufficientlysecure.keychain.keyimport.Keyserver;
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;
@@ -80,7 +81,6 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
-import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -183,10 +183,8 @@ public class KeychainIntentService extends IntentService implements Progressable
public static final String DOWNLOAD_KEY_SERVER = "query_key_server";
public static final String DOWNLOAD_KEY_LIST = "query_key_id";
- // sign key
- public static final String CERTIFY_KEY_MASTER_KEY_ID = "sign_key_master_key_id";
- public static final String CERTIFY_KEY_PUB_KEY_ID = "sign_key_pub_key_id";
- public static final String CERTIFY_KEY_UIDS = "sign_key_uids";
+ // certify key
+ public static final String CERTIFY_PARCEL = "certify_parcel";
// consolidate
public static final String CONSOLIDATE_RECOVERY = "consolidate_recovery";
@@ -258,30 +256,21 @@ public class KeychainIntentService extends IntentService implements Progressable
try {
/* Input */
- long masterKeyId = data.getLong(CERTIFY_KEY_MASTER_KEY_ID);
- long pubKeyId = data.getLong(CERTIFY_KEY_PUB_KEY_ID);
- ArrayList<String> userIds = data.getStringArrayList(CERTIFY_KEY_UIDS);
+ CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
/* Operation */
- String signaturePassphrase = PassphraseCacheService.getCachedPassphrase(this,
- masterKeyId, masterKeyId);
- if (signaturePassphrase == null) {
+ String passphrase = PassphraseCacheService.getCachedPassphrase(this,
+ // certification is always with the master key id, so use that one
+ parcel.mMasterKeyId, parcel.mMasterKeyId);
+ if (passphrase == null) {
throw new PgpGeneralException("Unable to obtain passphrase");
}
ProviderHelper providerHelper = new ProviderHelper(this);
- CanonicalizedPublicKeyRing publicRing = providerHelper.getCanonicalizedPublicKeyRing(pubKeyId);
- CanonicalizedSecretKeyRing secretKeyRing = providerHelper.getCanonicalizedSecretKeyRing(masterKeyId);
- CanonicalizedSecretKey certificationKey = secretKeyRing.getSecretKey();
- if (!certificationKey.unlock(signaturePassphrase)) {
- throw new PgpGeneralException("Error extracting key (bad passphrase?)");
- }
- // TODO: supply nfc stuff
- UncachedKeyRing newRing = certificationKey.certifyUserIds(publicRing, userIds, null, null);
+ PgpCertifyOperation op = new PgpCertifyOperation(providerHelper, mActionCanceled);
+ CertifyResult result = op.certify(parcel, passphrase);
- // store the signed key in our local cache
- providerHelper.savePublicKeyRing(newRing);
- sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
+ sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
} catch (Exception e) {
sendErrorToHandler(e);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java
new file mode 100644
index 000000000..cf54238ec
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sufficientlysecure.keychain.service.results;
+
+import android.os.Parcel;
+
+public class CertifyResult extends OperationResult {
+
+ int mCertifyOk, mCertifyError;
+
+ public CertifyResult(int result, OperationLog log) {
+ super(result, log);
+ }
+
+ public CertifyResult(int result, OperationLog log, int certifyOk, int certifyError) {
+ this(result, log);
+ mCertifyOk = certifyOk;
+ mCertifyError = certifyError;
+ }
+
+ /** Construct from a parcel - trivial because we have no extra data. */
+ public CertifyResult(Parcel source) {
+ super(source);
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ }
+
+ public static Creator<CertifyResult> CREATOR = new Creator<CertifyResult>() {
+ public CertifyResult createFromParcel(final Parcel source) {
+ return new CertifyResult(source);
+ }
+
+ public CertifyResult[] newArray(final int size) {
+ return new CertifyResult[size];
+ }
+ };
+
+}
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 29924ee5d..90e1d0037 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
@@ -517,8 +517,23 @@ public abstract class OperationResult implements Parcelable {
MSG_SE_SIGCRYPTING (LogLevel.DEBUG, R.string.msg_se_sigcrypting),
MSG_SE_SYMMETRIC (LogLevel.INFO, R.string.msg_se_symmetric),
- MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success),
+ MSG_CRT_CERTIFYING (LogLevel.DEBUG, R.string.msg_crt_certifying),
+ MSG_CRT_CERTIFY_ALL (LogLevel.DEBUG, R.string.msg_crt_certify_all),
+ MSG_CRT_CERTIFY_SOME (LogLevel.DEBUG, R.plurals.msg_crt_certify_some),
+ MSG_CRT_ERROR_MASTER_NOT_FOUND (LogLevel.ERROR, R.string.msg_crt_error_master_not_found),
+ MSG_CRT_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_crt_error_unlock),
+ MSG_CRT_FP_MISMATCH (LogLevel.WARN, R.string.msg_crt_fp_mismatch),
+ MSG_CRT (LogLevel.START, R.string.msg_crt),
+ MSG_CRT_MASTER_FETCH (LogLevel.DEBUG, R.string.msg_crt_master_fetch),
+ MSG_CRT_SAVE (LogLevel.DEBUG, R.string.msg_crt_save),
+ MSG_CRT_SAVING (LogLevel.DEBUG, R.string.msg_crt_saving),
MSG_CRT_SUCCESS (LogLevel.OK, R.string.msg_crt_success),
+ MSG_CRT_UNLOCK (LogLevel.DEBUG, R.string.msg_crt_unlock),
+ MSG_CRT_WARN_NOT_FOUND (LogLevel.WARN, R.string.msg_crt_warn_not_found),
+ MSG_CRT_WARN_CERT_FAILED (LogLevel.WARN, R.string.msg_crt_warn_cert_failed),
+ MSG_CRT_WARN_SAVE_FAILED (LogLevel.WARN, R.string.msg_crt_warn_save_failed),
+
+ MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success),
MSG_ACC_SAVED (LogLevel.INFO, R.string.api_settings_save_msg),