added export and upload to KeychainNewService
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class ExportKeyringParcel extends ImportExportParcel implements Parcelable {
|
||||
public String mKeyserver;
|
||||
public Uri mCanonicalizedPublicKeyringUri;
|
||||
|
||||
public boolean mExportSecret;
|
||||
public long mMasterKeyIds[];
|
||||
public String mOutputFile;
|
||||
public Uri mOutputUri;
|
||||
public ExportType mExportType;
|
||||
|
||||
public enum ExportType {
|
||||
UPLOAD_KEYSERVER,
|
||||
EXPORT_FILE,
|
||||
EXPORT_URI
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(String keyserver, Uri keyringUri) {
|
||||
mExportType = ExportType.UPLOAD_KEYSERVER;
|
||||
mKeyserver = keyserver;
|
||||
mCanonicalizedPublicKeyringUri = keyringUri;
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, String outputFile) {
|
||||
mExportType = ExportType.EXPORT_FILE;
|
||||
mMasterKeyIds = masterKeyIds;
|
||||
mExportSecret = exportSecret;
|
||||
mOutputFile = outputFile;
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
||||
mExportType = ExportType.EXPORT_URI;
|
||||
mMasterKeyIds = masterKeyIds;
|
||||
mExportSecret = exportSecret;
|
||||
mOutputUri = outputUri;
|
||||
}
|
||||
|
||||
protected ExportKeyringParcel(Parcel in) {
|
||||
mKeyserver = in.readString();
|
||||
mCanonicalizedPublicKeyringUri = (Uri) in.readValue(Uri.class.getClassLoader());
|
||||
mExportSecret = in.readByte() != 0x00;
|
||||
mOutputFile = in.readString();
|
||||
mOutputUri = (Uri) in.readValue(Uri.class.getClassLoader());
|
||||
mExportType = (ExportType) in.readValue(ExportType.class.getClassLoader());
|
||||
mMasterKeyIds = in.createLongArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(mKeyserver);
|
||||
dest.writeValue(mCanonicalizedPublicKeyringUri);
|
||||
dest.writeByte((byte) (mExportSecret ? 0x01 : 0x00));
|
||||
dest.writeString(mOutputFile);
|
||||
dest.writeValue(mOutputUri);
|
||||
dest.writeValue(mExportType);
|
||||
dest.writeLongArray(mMasterKeyIds);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<ExportKeyringParcel> CREATOR = new Parcelable.Creator<ExportKeyringParcel>() {
|
||||
@Override
|
||||
public ExportKeyringParcel createFromParcel(Parcel in) {
|
||||
return new ExportKeyringParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportKeyringParcel[] newArray(int size) {
|
||||
return new ExportKeyringParcel[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Empty class, simply serves as a base class for ImportKeyringParcel and ExportKeyringParcel
|
||||
*/
|
||||
public class ImportExportParcel implements Parcelable {
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImportKeyringParcel implements Parcelable {
|
||||
public class ImportKeyringParcel extends ImportExportParcel {
|
||||
// if null, keys are expected to be read from a cache file in ImportExportOperations
|
||||
public ArrayList<ParcelableKeyRing> mKeyList;
|
||||
public String mKeyserver; // must be set if keys are to be imported from a keyserver
|
||||
|
||||
@@ -103,7 +103,8 @@ 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 ImportKeyringParcel){
|
||||
} else if (inputParcel instanceof ImportKeyringParcel
|
||||
|| inputParcel instanceof ExportKeyringParcel){
|
||||
op = new ImportExportOperation(outerThis, new ProviderHelper(outerThis),
|
||||
outerThis, mActionCanceled);
|
||||
} else {
|
||||
|
||||
@@ -91,11 +91,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
|
||||
public static final String ACTION_PROMOTE_KEYRING = Constants.INTENT_PREFIX + "PROMOTE_KEYRING";
|
||||
|
||||
public static final String ACTION_IMPORT_KEYRING = Constants.INTENT_PREFIX + "IMPORT_KEYRING";
|
||||
public static final String ACTION_EXPORT_KEYRING = Constants.INTENT_PREFIX + "EXPORT_KEYRING";
|
||||
|
||||
public static final String ACTION_UPLOAD_KEYRING = Constants.INTENT_PREFIX + "UPLOAD_KEYRING";
|
||||
|
||||
public static final String ACTION_DELETE = Constants.INTENT_PREFIX + "DELETE";
|
||||
|
||||
public static final String ACTION_CONSOLIDATE = Constants.INTENT_PREFIX + "CONSOLIDATE";
|
||||
@@ -117,20 +112,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
public static final String DELETE_KEY_LIST = "delete_list";
|
||||
public static final String DELETE_IS_SECRET = "delete_is_secret";
|
||||
|
||||
// import key
|
||||
public static final String IMPORT_KEY_LIST = "import_key_list";
|
||||
public static final String IMPORT_KEY_SERVER = "import_key_server";
|
||||
|
||||
// export key
|
||||
public static final String EXPORT_FILENAME = "export_filename";
|
||||
public static final String EXPORT_URI = "export_uri";
|
||||
public static final String EXPORT_SECRET = "export_secret";
|
||||
public static final String EXPORT_ALL = "export_all";
|
||||
public static final String EXPORT_KEY_RING_MASTER_KEY_ID = "export_key_ring_id";
|
||||
|
||||
// upload key
|
||||
public static final String UPLOAD_KEY_SERVER = "upload_key_server";
|
||||
|
||||
// promote key
|
||||
public static final String PROMOTE_MASTER_KEY_ID = "promote_master_key_id";
|
||||
public static final String PROMOTE_CARD_AID = "promote_card_aid";
|
||||
@@ -354,76 +335,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION_EXPORT_KEYRING: {
|
||||
|
||||
// Input
|
||||
boolean exportSecret = data.getBoolean(EXPORT_SECRET, false);
|
||||
String outputFile = data.getString(EXPORT_FILENAME);
|
||||
Uri outputUri = data.getParcelable(EXPORT_URI);
|
||||
|
||||
boolean exportAll = data.getBoolean(EXPORT_ALL);
|
||||
long[] masterKeyIds = exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
|
||||
|
||||
// Operation
|
||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||
KeychainService.this, providerHelper, KeychainService.this);
|
||||
ExportResult result;
|
||||
if (outputFile != null) {
|
||||
result = importExportOperation.exportToFile(masterKeyIds, exportSecret, outputFile);
|
||||
} else {
|
||||
result = importExportOperation.exportToUri(masterKeyIds, exportSecret, outputUri);
|
||||
}
|
||||
|
||||
// Result
|
||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION_IMPORT_KEYRING: {
|
||||
|
||||
// Input
|
||||
String keyServer = data.getString(IMPORT_KEY_SERVER);
|
||||
ArrayList<ParcelableKeyRing> keyList = data.getParcelableArrayList(IMPORT_KEY_LIST);
|
||||
|
||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||
KeychainService.this,
|
||||
providerHelper, KeychainService.this, mActionCanceled);
|
||||
|
||||
ImportKeyringParcel inputParcel = new ImportKeyringParcel(keyList, keyServer);
|
||||
CryptoInputParcel cryptoInputParcel = new CryptoInputParcel();
|
||||
|
||||
ImportKeyResult result = importExportOperation.execute(inputParcel, cryptoInputParcel);
|
||||
|
||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION_UPLOAD_KEYRING: {
|
||||
try {
|
||||
|
||||
// Input
|
||||
String keyServer = data.getString(UPLOAD_KEY_SERVER);
|
||||
// and dataUri!
|
||||
|
||||
// Operation
|
||||
HkpKeyserver server = new HkpKeyserver(keyServer);
|
||||
|
||||
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||
KeychainService.this, providerHelper, KeychainService.this);
|
||||
|
||||
try {
|
||||
importExportOperation.uploadKeyRingToServer(server, keyring);
|
||||
} catch (Keyserver.AddKeyException e) {
|
||||
throw new PgpGeneralException("Unable to export key to selected server");
|
||||
}
|
||||
|
||||
sendMessageToHandler(MessageStatus.OKAY);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user