mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 04:22:18 -05:00
added OperationResult support to upload to keyserver
This commit is contained in:
parent
d95798dda2
commit
8be184d46f
@ -23,6 +23,8 @@ import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
||||
import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
|
||||
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
||||
@ -208,12 +210,12 @@ public class CertifyOperation extends BaseOperation {
|
||||
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey);
|
||||
|
||||
if (importExportOperation != null) {
|
||||
// TODO use subresult, get rid of try/catch!
|
||||
try {
|
||||
importExportOperation.uploadKeyRingToServer(keyServer, certifiedKey, proxy);
|
||||
ExportResult uploadResult = importExportOperation.uploadKeyRingToServer(keyServer, certifiedKey, proxy);
|
||||
log.add(uploadResult, 2);
|
||||
|
||||
if (uploadResult.success()) {
|
||||
uploadOk += 1;
|
||||
} catch (AddKeyException e) {
|
||||
Log.e(Constants.TAG, "error uploading key", e);
|
||||
} else {
|
||||
uploadError += 1;
|
||||
}
|
||||
}
|
||||
@ -233,11 +235,15 @@ public class CertifyOperation extends BaseOperation {
|
||||
return new CertifyResult(CertifyResult.RESULT_ERROR, log, certifyOk, certifyError, uploadOk, uploadError);
|
||||
}
|
||||
|
||||
log.add(LogType.MSG_CRT_SUCCESS, 0);
|
||||
//since only verified keys are synced to contacts, we need to initiate a sync now
|
||||
// since only verified keys are synced to contacts, we need to initiate a sync now
|
||||
ContactSyncAdapterService.requestSync();
|
||||
|
||||
return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError, uploadOk, uploadError);
|
||||
log.add(LogType.MSG_CRT_SUCCESS, 0);
|
||||
if (uploadError != 0) {
|
||||
return new CertifyResult(CertifyResult.RESULT_WARNINGS, log, certifyOk, certifyError, uploadOk, uploadError);
|
||||
} else {
|
||||
return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError, uploadOk, uploadError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,9 @@ import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver;
|
||||
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
||||
import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
|
||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.*;
|
||||
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.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
@ -44,7 +41,6 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
@ -99,13 +95,18 @@ public class ImportExportOperation extends BaseOperation {
|
||||
super(context, providerHelper, progressable, cancelled);
|
||||
}
|
||||
|
||||
public void uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring, Proxy proxy) throws AddKeyException {
|
||||
uploadKeyRingToServer(server, keyring.getUncachedKeyRing(), proxy);
|
||||
public ExportResult uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring, Proxy proxy) {
|
||||
return uploadKeyRingToServer(server, keyring.getUncachedKeyRing(), proxy);
|
||||
}
|
||||
|
||||
public void uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) throws AddKeyException {
|
||||
public ExportResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream aos = null;
|
||||
OperationLog log = new OperationLog();
|
||||
log.add(LogType.MSG_EXPORT_UPLOAD_PUBLIC, 0, KeyFormattingUtils.convertKeyIdToHex(
|
||||
keyring.getPublicKey().getKeyId()
|
||||
));
|
||||
|
||||
try {
|
||||
aos = new ArmoredOutputStream(bos);
|
||||
keyring.encode(aos);
|
||||
@ -113,9 +114,19 @@ public class ImportExportOperation extends BaseOperation {
|
||||
|
||||
String armoredKey = bos.toString("UTF-8");
|
||||
server.add(armoredKey, proxy);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_UPLOAD_SUCCESS, 1);
|
||||
return new ExportResult(ExportResult.RESULT_OK, log);
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "IOException", e);
|
||||
throw new AddKeyException();
|
||||
|
||||
log.add(LogType.MSG_EXPORT_ERROR_KEY, 1);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
||||
} catch (AddKeyException e) {
|
||||
Log.e(Constants.TAG, "AddKeyException", e);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_ERROR_UPLOAD, 1);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
||||
} finally {
|
||||
try {
|
||||
if (aos != null) {
|
||||
|
@ -685,6 +685,7 @@ public abstract class OperationResult implements Parcelable {
|
||||
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_WARN_UPLOAD_FAILED (LogLevel.WARN, R.string.msg_crt_warn_upload_failed),
|
||||
|
||||
MSG_IMPORT (LogLevel.START, R.plurals.msg_import),
|
||||
|
||||
@ -705,6 +706,7 @@ public abstract class OperationResult implements Parcelable {
|
||||
MSG_IMPORT_SUCCESS (LogLevel.OK, R.string.msg_import_success),
|
||||
|
||||
MSG_EXPORT (LogLevel.START, R.plurals.msg_export),
|
||||
MSG_EXPORT_UPLOAD_PUBLIC(LogLevel.START, R.string.msg_export_upload_public),
|
||||
MSG_EXPORT_PUBLIC (LogLevel.DEBUG, R.string.msg_export_public),
|
||||
MSG_EXPORT_SECRET (LogLevel.DEBUG, R.string.msg_export_secret),
|
||||
MSG_EXPORT_ALL (LogLevel.START, R.string.msg_export_all),
|
||||
@ -716,7 +718,9 @@ public abstract class OperationResult implements Parcelable {
|
||||
MSG_EXPORT_ERROR_DB (LogLevel.ERROR, R.string.msg_export_error_db),
|
||||
MSG_EXPORT_ERROR_IO (LogLevel.ERROR, R.string.msg_export_error_io),
|
||||
MSG_EXPORT_ERROR_KEY (LogLevel.ERROR, R.string.msg_export_error_key),
|
||||
MSG_EXPORT_ERROR_UPLOAD (LogLevel.ERROR, R.string.msg_export_error_upload),
|
||||
MSG_EXPORT_SUCCESS (LogLevel.OK, R.string.msg_export_success),
|
||||
MSG_EXPORT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_export_upload_success),
|
||||
|
||||
MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success),
|
||||
|
||||
|
@ -441,9 +441,9 @@ public class KeychainService extends Service implements Progressable {
|
||||
ImportExportOperation importExportOperation = new ImportExportOperation(KeychainService.this,
|
||||
providerHelper, KeychainService.this);
|
||||
|
||||
try {
|
||||
importExportOperation.uploadKeyRingToServer(server, keyring, getProxyFromBundle(data));
|
||||
} catch (Keyserver.AddKeyException e) {
|
||||
ExportResult uploadResult = importExportOperation.uploadKeyRingToServer(server, keyring,
|
||||
getProxyFromBundle(data));
|
||||
if (uploadResult.getResult() != ExportResult.RESULT_OK) {
|
||||
throw new PgpGeneralException("Unable to export key to selected server");
|
||||
}
|
||||
|
||||
|
@ -1174,6 +1174,7 @@
|
||||
<string name="msg_crt_warn_not_found">"Key not found!"</string>
|
||||
<string name="msg_crt_warn_cert_failed">"Certificate generation failed!"</string>
|
||||
<string name="msg_crt_warn_save_failed">"Save operation failed!"</string>
|
||||
<string name="msg_crt_warn_upload_failed">"Upload operation failed!"</string>
|
||||
|
||||
<string name="msg_crt_upload_success">"Successfully uploaded key to server"</string>
|
||||
|
||||
@ -1203,6 +1204,7 @@
|
||||
</plurals>
|
||||
<string name="msg_export_all">"Exporting all keys"</string>
|
||||
<string name="msg_export_public">"Exporting public key %s"</string>
|
||||
<string name="msg_export_upload_public">"Uploading public key %s"</string>
|
||||
<string name="msg_export_secret">"Exporting secret key %s"</string>
|
||||
<string name="msg_export_error_no_file">"No filename specified!"</string>
|
||||
<string name="msg_export_error_fopen">"Error opening file!"</string>
|
||||
@ -1212,7 +1214,9 @@
|
||||
<string name="msg_export_error_db">"Database error!"</string>
|
||||
<string name="msg_export_error_io">"Input/output error!"</string>
|
||||
<string name="msg_export_error_key">"Error preprocessing key data!"</string>
|
||||
<string name="msg_export_error_upload">"Error uploading key to server! Please check your internet connection"</string>
|
||||
<string name="msg_export_success">"Export operation successful"</string>
|
||||
<string name="msg_export_upload_success">"Upload to keyserver successful"</string>
|
||||
|
||||
<string name="msg_del_error_empty">"Nothing to delete!"</string>
|
||||
<string name="msg_del_error_multi_secret">"Secret keys can only be deleted individually!"</string>
|
||||
|
Loading…
Reference in New Issue
Block a user