aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java38
1 files changed, 22 insertions, 16 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java
index 86cfc21a3..ffce2f39c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java
@@ -38,7 +38,6 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
-import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
@@ -157,6 +156,15 @@ public class ImportExportOperation extends BaseOperation {
}
+ /**
+ * Since the introduction of multithreaded import, we expect calling functions to handle the key sync i,e
+ * ContactSyncAdapterService.requestSync()
+ *
+ * @param entries keys to import
+ * @param num number of keys to import
+ * @param keyServerUri contains uri of keyserver to import from, if it is an import from cloud
+ * @return
+ */
public ImportKeyResult importKeyRings(Iterator<ParcelableKeyRing> entries, int num, String keyServerUri) {
updateProgress(R.string.progress_importing, 0, 100);
@@ -244,25 +252,25 @@ public class ImportExportOperation extends BaseOperation {
try {
log.add(LogType.MSG_IMPORT_FETCH_KEYBASE, 2, entry.mKeybaseName);
byte[] data = keybaseServer.get(entry.mKeybaseName).getBytes();
- key = UncachedKeyRing.decodeFromData(data);
+ UncachedKeyRing keybaseKey = UncachedKeyRing.decodeFromData(data);
- // If there already is a key (of keybase origin), merge the two
- if (key != null) {
+ // If there already is a key, merge the two
+ if (key != null && keybaseKey != null) {
log.add(LogType.MSG_IMPORT_MERGE, 3);
- UncachedKeyRing merged = UncachedKeyRing.decodeFromData(data);
- merged = key.merge(merged, log, 4);
+ keybaseKey = key.merge(keybaseKey, log, 4);
// If the merge didn't fail, use the new merged key
- if (merged != null) {
- key = merged;
+ if (keybaseKey != null) {
+ key = keybaseKey;
+ } else {
+ log.add(LogType.MSG_IMPORT_MERGE_ERROR, 4);
}
- } else {
- log.add(LogType.MSG_IMPORT_FETCH_ERROR_DECODE, 3);
- key = UncachedKeyRing.decodeFromData(data);
+ } else if (keybaseKey != null) {
+ key = keybaseKey;
}
} catch (Keyserver.QueryFailedException e) {
// download failed, too bad. just proceed
Log.e(Constants.TAG, "query failed", e);
- log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER_ERROR, 3);
+ log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER_ERROR, 3, e.getMessage());
}
}
}
@@ -331,8 +339,8 @@ public class ImportExportOperation extends BaseOperation {
// Special: make sure new data is synced into contacts
// disabling sync right now since it reduces speed while multi-threading
- // so, we expect calling functions to take care of it. KeychainIntentService handles this
- //ContactSyncAdapterService.requestSync();
+ // so, we expect calling functions to take care of it. KeychainService handles this
+ // ContactSyncAdapterService.requestSync();
// convert to long array
long[] importedMasterKeyIdsArray = new long[importedMasterKeyIds.size()];
@@ -376,8 +384,6 @@ public class ImportExportOperation extends BaseOperation {
log.add(LogType.MSG_IMPORT_ERROR, 1);
}
- ContactSyncAdapterService.requestSync();
-
return new ImportKeyResult(resultType, log, newKeys, updatedKeys, badKeys, secret,
importedMasterKeyIdsArray);
}