redesign certify action to work with parcel input and result

This commit is contained in:
Vincent Breitmoser
2014-10-04 14:11:51 +02:00
parent dcd22d9815
commit 0e0e3d8dd0
10 changed files with 389 additions and 43 deletions

View File

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

View File

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

View File

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

View File

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