migrated promote op to KeychainNewService
This commit is contained in:
@@ -32,6 +32,8 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
|
||||
@@ -45,14 +47,20 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
* without secret key material, using a GNU_DUMMY s2k type.
|
||||
*
|
||||
*/
|
||||
public class PromoteKeyOperation extends BaseOperation {
|
||||
public class PromoteKeyOperation extends BaseOperation<PromoteKeyringParcel> {
|
||||
|
||||
public PromoteKeyOperation(Context context, ProviderHelper providerHelper,
|
||||
Progressable progressable, AtomicBoolean cancelled) {
|
||||
super(context, providerHelper, progressable, cancelled);
|
||||
}
|
||||
|
||||
public PromoteKeyResult execute(long masterKeyId, byte[] cardAid, long[] subKeyIds) {
|
||||
@Override
|
||||
public PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel,
|
||||
CryptoInputParcel cryptoInputParcel) {
|
||||
// Input
|
||||
long masterKeyId = promoteKeyringParcel.mKeyRingId;
|
||||
byte[] cardAid = promoteKeyringParcel.mCardAid;
|
||||
long[] subKeyIds = promoteKeyringParcel.mSubKeyIds;
|
||||
|
||||
OperationLog log = new OperationLog();
|
||||
log.add(LogType.MSG_PR, 0);
|
||||
|
||||
@@ -104,9 +104,11 @@ public class KeychainNewService extends Service implements Progressable {
|
||||
} else if (inputParcel instanceof CertifyAction) {
|
||||
op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis,
|
||||
mActionCanceled);
|
||||
} else if (inputParcel instanceof DeleteKeyringParcel){
|
||||
Log.e("PHILIP", "delete in KeychainNewService");
|
||||
} else if (inputParcel instanceof DeleteKeyringParcel) {
|
||||
op = new DeleteOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||
} else if (inputParcel instanceof PromoteKeyringParcel){
|
||||
op = new PromoteKeyOperation(outerThis, new ProviderHelper(outerThis),
|
||||
outerThis, mActionCanceled);
|
||||
} else if (inputParcel instanceof ImportKeyringParcel
|
||||
|| inputParcel instanceof ExportKeyringParcel){
|
||||
op = new ImportExportOperation(outerThis, new ProviderHelper(outerThis),
|
||||
@@ -114,10 +116,8 @@ public class KeychainNewService extends Service implements Progressable {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
Log.e("PHILIP", "exec in KeychainNewService");
|
||||
@SuppressWarnings("unchecked") // this is unchecked, we make sure it's the correct op above!
|
||||
OperationResult result = op.execute(inputParcel, cryptoInput);
|
||||
Log.e("PHILIP", "result in KeychainNewService" + result);
|
||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||
|
||||
}
|
||||
|
||||
@@ -87,8 +87,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
|
||||
public static final String ACTION_VERIFY_KEYBASE_PROOF = Constants.INTENT_PREFIX + "VERIFY_KEYBASE_PROOF";
|
||||
|
||||
public static final String ACTION_PROMOTE_KEYRING = Constants.INTENT_PREFIX + "PROMOTE_KEYRING";
|
||||
|
||||
public static final String ACTION_CONSOLIDATE = Constants.INTENT_PREFIX + "CONSOLIDATE";
|
||||
|
||||
public static final String ACTION_CANCEL = Constants.INTENT_PREFIX + "CANCEL";
|
||||
@@ -99,11 +97,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
public static final String KEYBASE_REQUIRED_FINGERPRINT = "keybase_required_fingerprint";
|
||||
public static final String KEYBASE_PROOF = "keybase_proof";
|
||||
|
||||
// promote key
|
||||
public static final String PROMOTE_MASTER_KEY_ID = "promote_master_key_id";
|
||||
public static final String PROMOTE_CARD_AID = "promote_card_aid";
|
||||
public static final String PROMOTE_SUBKEY_IDS = "promote_fingerprints";
|
||||
|
||||
// consolidate
|
||||
public static final String CONSOLIDATE_RECOVERY = "consolidate_recovery";
|
||||
|
||||
@@ -271,24 +264,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION_PROMOTE_KEYRING: {
|
||||
|
||||
// Input
|
||||
long keyRingId = data.getLong(PROMOTE_MASTER_KEY_ID);
|
||||
byte[] cardAid = data.getByteArray(PROMOTE_CARD_AID);
|
||||
long[] subKeyIds = data.getLongArray(PROMOTE_SUBKEY_IDS);
|
||||
|
||||
// Operation
|
||||
PromoteKeyOperation op = new PromoteKeyOperation(
|
||||
KeychainService.this, providerHelper, KeychainService.this,
|
||||
mActionCanceled);
|
||||
PromoteKeyResult result = op.execute(keyRingId, cardAid, subKeyIds);
|
||||
|
||||
// Result
|
||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class PromoteKeyringParcel implements Parcelable {
|
||||
|
||||
public long mKeyRingId;
|
||||
public byte[] mCardAid;
|
||||
public long[] mSubKeyIds;
|
||||
|
||||
public PromoteKeyringParcel(long keyRingId, byte[] cardAid, long[] subKeyIds) {
|
||||
mKeyRingId = keyRingId;
|
||||
mCardAid = cardAid;
|
||||
mSubKeyIds = subKeyIds;
|
||||
}
|
||||
|
||||
protected PromoteKeyringParcel(Parcel in) {
|
||||
mKeyRingId = in.readLong();
|
||||
mCardAid = in.createByteArray();
|
||||
mSubKeyIds = in.createLongArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(mKeyRingId);
|
||||
dest.writeByteArray(mCardAid);
|
||||
dest.writeLongArray(mSubKeyIds);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<PromoteKeyringParcel> CREATOR = new Parcelable.Creator<PromoteKeyringParcel>() {
|
||||
@Override
|
||||
public PromoteKeyringParcel createFromParcel(Parcel in) {
|
||||
return new PromoteKeyringParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PromoteKeyringParcel[] newArray(int size) {
|
||||
return new PromoteKeyringParcel[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -44,11 +44,14 @@ import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
|
||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
|
||||
|
||||
public class ViewKeyYubiKeyFragment extends Fragment
|
||||
public class ViewKeyYubiKeyFragment
|
||||
extends CryptoOperationFragment<PromoteKeyringParcel, PromoteKeyResult>
|
||||
implements LoaderCallbacks<Cursor> {
|
||||
|
||||
public static final String ARG_MASTER_KEY_ID = "master_key_id";
|
||||
@@ -60,6 +63,8 @@ public class ViewKeyYubiKeyFragment extends Fragment
|
||||
private String mUserId;
|
||||
private byte[] mCardAid;
|
||||
private long mMasterKeyId;
|
||||
private long[] mSubKeyIds;
|
||||
|
||||
private Button vButton;
|
||||
private TextView vStatus;
|
||||
|
||||
@@ -127,50 +132,15 @@ public class ViewKeyYubiKeyFragment extends Fragment
|
||||
}
|
||||
|
||||
public void promoteToSecretKey() {
|
||||
|
||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
// handle messages by standard KeychainIntentServiceHandler first
|
||||
super.handleMessage(message);
|
||||
|
||||
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||
// get returned data bundle
|
||||
Bundle returnData = message.getData();
|
||||
|
||||
PromoteKeyResult result =
|
||||
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
|
||||
|
||||
result.createNotify(getActivity()).show();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Send all information needed to service to decrypt in other thread
|
||||
Intent intent = new Intent(getActivity(), KeychainService.class);
|
||||
|
||||
// fill values for this action
|
||||
|
||||
intent.setAction(KeychainService.ACTION_PROMOTE_KEYRING);
|
||||
|
||||
Bundle data = new Bundle();
|
||||
data.putLong(KeychainService.PROMOTE_MASTER_KEY_ID, mMasterKeyId);
|
||||
data.putByteArray(KeychainService.PROMOTE_CARD_AID, mCardAid);
|
||||
long[] subKeyIds = new long[mFingerprints.length];
|
||||
for (int i = 0; i < subKeyIds.length; i++) {
|
||||
subKeyIds[i] = KeyFormattingUtils.getKeyIdFromFingerprint(mFingerprints[i]);
|
||||
}
|
||||
data.putLongArray(KeychainService.PROMOTE_SUBKEY_IDS, subKeyIds);
|
||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(saveHandler);
|
||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||
|
||||
// start service with intent
|
||||
getActivity().startService(intent);
|
||||
// mMasterKeyId and mCardAid are already set
|
||||
mSubKeyIds = subKeyIds;
|
||||
|
||||
cryptoOperation();
|
||||
}
|
||||
|
||||
public static final String[] PROJECTION = new String[]{
|
||||
@@ -240,4 +210,14 @@ public class ViewKeyYubiKeyFragment extends Fragment
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PromoteKeyringParcel createOperationInput() {
|
||||
return new PromoteKeyringParcel(mMasterKeyId, mCardAid, mSubKeyIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCryptoOperationResult(PromoteKeyResult result) {
|
||||
result.createNotify(getActivity()).show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user