introduced constants for keyserver sync, fixed sync issue
This commit is contained in:
@@ -29,6 +29,7 @@ public final class Constants {
|
|||||||
public static final boolean DEBUG = BuildConfig.DEBUG;
|
public static final boolean DEBUG = BuildConfig.DEBUG;
|
||||||
public static final boolean DEBUG_LOG_DB_QUERIES = false;
|
public static final boolean DEBUG_LOG_DB_QUERIES = false;
|
||||||
public static final boolean DEBUG_SYNC_REMOVE_CONTACTS = false;
|
public static final boolean DEBUG_SYNC_REMOVE_CONTACTS = false;
|
||||||
|
public static final boolean DEBUG_KEYSERVER_SYNC = false;
|
||||||
|
|
||||||
public static final String TAG = DEBUG ? "Keychain D" : "Keychain";
|
public static final String TAG = DEBUG ? "Keychain D" : "Keychain";
|
||||||
|
|
||||||
@@ -126,7 +127,7 @@ public final class Constants {
|
|||||||
|
|
||||||
public static final class Defaults {
|
public static final class Defaults {
|
||||||
public static final String KEY_SERVERS = "hkps://hkps.pool.sks-keyservers.net, hkps://pgp.mit.edu";
|
public static final String KEY_SERVERS = "hkps://hkps.pool.sks-keyservers.net, hkps://pgp.mit.edu";
|
||||||
public static final int PREF_VERSION = 5;
|
public static final int PREF_VERSION = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class key {
|
public static final class key {
|
||||||
|
|||||||
@@ -23,12 +23,10 @@ import android.app.Application;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -36,7 +34,7 @@ import android.widget.Toast;
|
|||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||||
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||||
import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity;
|
import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@@ -45,7 +43,6 @@ import org.sufficientlysecure.keychain.util.Preferences;
|
|||||||
import org.sufficientlysecure.keychain.util.TlsHelper;
|
import org.sufficientlysecure.keychain.util.TlsHelper;
|
||||||
|
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
@@ -99,7 +96,7 @@ public class KeychainApplication extends Application {
|
|||||||
setupAccountAsNeeded(this);
|
setupAccountAsNeeded(this);
|
||||||
|
|
||||||
// Update keyserver list as needed
|
// Update keyserver list as needed
|
||||||
Preferences.getPreferences(this).upgradePreferences();
|
Preferences.getPreferences(this).upgradePreferences(this);
|
||||||
|
|
||||||
TlsHelper.addStaticCA("pool.sks-keyservers.net", getAssets(), "sks-keyservers.netCA.cer");
|
TlsHelper.addStaticCA("pool.sks-keyservers.net", getAssets(), "sks-keyservers.netCA.cer");
|
||||||
|
|
||||||
@@ -151,18 +148,7 @@ public class KeychainApplication extends Application {
|
|||||||
// for contact sync
|
// for contact sync
|
||||||
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
|
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
|
||||||
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
|
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
|
||||||
// for keyserver sync
|
KeyserverSyncAdapterService.enableKeyserverSync(context);
|
||||||
ContentResolver.setIsSyncable(account, Constants.PROVIDER_AUTHORITY, 1);
|
|
||||||
ContentResolver.setSyncAutomatically(account, Constants.PROVIDER_AUTHORITY,
|
|
||||||
true);
|
|
||||||
// TODO: Increase periodic update time after testing
|
|
||||||
Log.e("PHILIP", "enabled periodic keyserversync");
|
|
||||||
ContentResolver.addPeriodicSync(
|
|
||||||
new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE),
|
|
||||||
Constants.PROVIDER_AUTHORITY,
|
|
||||||
new Bundle(),
|
|
||||||
60
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "Adding account failed!");
|
Log.e(Constants.TAG, "Adding account failed!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
try {
|
try {
|
||||||
data = query(request, proxy);
|
data = query(request, proxy);
|
||||||
} catch (HttpError httpError) {
|
} catch (HttpError httpError) {
|
||||||
Log.e(Constants.TAG, "Failed to get key at HkpKeyserver", httpError);
|
Log.d(Constants.TAG, "Failed to get key at HkpKeyserver", httpError);
|
||||||
throw new QueryFailedException("not found");
|
throw new QueryFailedException("not found");
|
||||||
}
|
}
|
||||||
Matcher matcher = PgpHelper.PGP_PUBLIC_KEY.matcher(data);
|
Matcher matcher = PgpHelper.PGP_PUBLIC_KEY.matcher(data);
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
|||||||
log.add(LogType.MSG_IMPORT_FETCH_ERROR_DECODE, 3);
|
log.add(LogType.MSG_IMPORT_FETCH_ERROR_DECODE, 3);
|
||||||
}
|
}
|
||||||
} catch (Keyserver.QueryFailedException e) {
|
} catch (Keyserver.QueryFailedException e) {
|
||||||
Log.e(Constants.TAG, "query failed", e);
|
Log.d(Constants.TAG, "query failed", e);
|
||||||
log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER_ERROR, 3, e.getMessage());
|
log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER_ERROR, 3, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,13 +93,13 @@ public class RevokeOperation extends BaseOperation<RevokeKeyringParcel> {
|
|||||||
log.add(OperationResult.LogType.MSG_REVOKE_OK, 1);
|
log.add(OperationResult.LogType.MSG_REVOKE_OK, 1);
|
||||||
return new RevokeResult(RevokeResult.RESULT_OK, log, masterKeyId);
|
return new RevokeResult(RevokeResult.RESULT_OK, log, masterKeyId);
|
||||||
} else {
|
} else {
|
||||||
log.add(OperationResult.LogType.MSG_REVOKE_KEY_FAIL, 1);
|
log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1);
|
||||||
return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId);
|
return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (PgpKeyNotFoundException | ProviderHelper.NotFoundException e) {
|
} catch (PgpKeyNotFoundException | ProviderHelper.NotFoundException e) {
|
||||||
Log.e(Constants.TAG, "could not find key to revoke", e);
|
Log.e(Constants.TAG, "could not find key to revoke", e);
|
||||||
log.add(OperationResult.LogType.MSG_REVOKE_KEY_FAIL, 1);
|
log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1);
|
||||||
return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId);
|
return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -763,10 +763,9 @@ public abstract class OperationResult implements Parcelable {
|
|||||||
MSG_DEL_FAIL (LogLevel.WARN, R.plurals.msg_del_fail),
|
MSG_DEL_FAIL (LogLevel.WARN, R.plurals.msg_del_fail),
|
||||||
|
|
||||||
MSG_REVOKE_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_revoke_error_empty),
|
MSG_REVOKE_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_revoke_error_empty),
|
||||||
MSG_REVOKE_ERROR_MULTI_SECRET (LogLevel.DEBUG, R.string.msg_revoke_error_multi_secret),
|
MSG_REVOKE_ERROR_NOT_FOUND (LogLevel.ERROR, R.string.msg_revoke_error_not_found),
|
||||||
MSG_REVOKE_ERROR_NOT_FOUND (LogLevel.DEBUG, R.string.msg_revoke_error_multi_secret),
|
|
||||||
MSG_REVOKE (LogLevel.DEBUG, R.string.msg_revoke_key),
|
MSG_REVOKE (LogLevel.DEBUG, R.string.msg_revoke_key),
|
||||||
MSG_REVOKE_KEY_FAIL (LogLevel.ERROR, R.string.msg_revoke_key_fail),
|
MSG_REVOKE_ERROR_KEY_FAIL (LogLevel.ERROR, R.string.msg_revoke_key_fail),
|
||||||
MSG_REVOKE_OK (LogLevel.OK, R.string.msg_revoke_ok),
|
MSG_REVOKE_OK (LogLevel.OK, R.string.msg_revoke_ok),
|
||||||
|
|
||||||
// keybase verification
|
// keybase verification
|
||||||
|
|||||||
@@ -700,20 +700,14 @@ public class ProviderHelper {
|
|||||||
new String[]{"" + masterKeyId},
|
new String[]{"" + masterKeyId},
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
ContentValues lastUpdatedEntry = null;
|
|
||||||
if (lastUpdatedCursor.moveToNext()) {
|
if (lastUpdatedCursor.moveToNext()) {
|
||||||
lastUpdatedEntry = new ContentValues(2);
|
// there was an entry to re-insert
|
||||||
|
// this operation must happen after the new key is inserted
|
||||||
|
ContentValues lastUpdatedEntry = new ContentValues(2);
|
||||||
lastUpdatedEntry.put(UpdatedKeys.MASTER_KEY_ID,
|
lastUpdatedEntry.put(UpdatedKeys.MASTER_KEY_ID,
|
||||||
lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID));
|
lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID));
|
||||||
lastUpdatedEntry.put(UpdatedKeys.LAST_UPDATED,
|
lastUpdatedEntry.put(UpdatedKeys.LAST_UPDATED,
|
||||||
lastUpdatedCursor.getLong(INDEX_LAST_UPDATED));
|
lastUpdatedCursor.getLong(INDEX_LAST_UPDATED));
|
||||||
Log.e("PHILIP", "cv: " + lastUpdatedEntry + " actual: " + masterKeyId);
|
|
||||||
}
|
|
||||||
lastUpdatedCursor.close();
|
|
||||||
|
|
||||||
if (lastUpdatedEntry != null) {
|
|
||||||
// there was an entry to re-insert
|
|
||||||
// this operation must happen after the new key is inserted
|
|
||||||
operations.add(
|
operations.add(
|
||||||
ContentProviderOperation
|
ContentProviderOperation
|
||||||
.newInsert(UpdatedKeys.CONTENT_URI)
|
.newInsert(UpdatedKeys.CONTENT_URI)
|
||||||
@@ -721,6 +715,7 @@ public class ProviderHelper {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
lastUpdatedCursor.close();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class ContactSyncAdapterService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
|
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
|
||||||
final SyncResult syncResult) {
|
final SyncResult syncResult) {
|
||||||
Log.d(Constants.TAG, "Performing a sync!");
|
Log.d(Constants.TAG, "Performing a contact sync!");
|
||||||
// TODO: Import is currently disabled for 2.8, until we implement proper origin management
|
// TODO: Import is currently disabled for 2.8, until we implement proper origin management
|
||||||
// importDone.set(false);
|
// importDone.set(false);
|
||||||
// KeychainApplication.setupAccountAsNeeded(ContactSyncAdapterService.this);
|
// KeychainApplication.setupAccountAsNeeded(ContactSyncAdapterService.this);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.sufficientlysecure.keychain.service;
|
package org.sufficientlysecure.keychain.service;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
@@ -25,6 +26,7 @@ import android.os.Messenger;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
@@ -50,6 +52,20 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
public class KeyserverSyncAdapterService extends Service {
|
public class KeyserverSyncAdapterService extends Service {
|
||||||
|
|
||||||
|
// how often a sync should be initiated, in s
|
||||||
|
public static final long SYNC_INTERVAL =
|
||||||
|
Constants.DEBUG_KEYSERVER_SYNC
|
||||||
|
? TimeUnit.MINUTES.toSeconds(2) : TimeUnit.DAYS.toSeconds(3);
|
||||||
|
// time since last update after which a key should be updated again, in s
|
||||||
|
public static final long KEY_UPDATE_LIMIT =
|
||||||
|
Constants.DEBUG_KEYSERVER_SYNC ? 1 : TimeUnit.DAYS.toSeconds(7);
|
||||||
|
// time by which a sync is postponed in case of a
|
||||||
|
public static final long SYNC_POSTPONE_TIME =
|
||||||
|
Constants.DEBUG_KEYSERVER_SYNC ? 30 * 1000 : TimeUnit.MINUTES.toMillis(5);
|
||||||
|
// Time taken by Orbot before a new circuit is created
|
||||||
|
public static final int ORBOT_CIRCUIT_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(10);
|
||||||
|
|
||||||
|
|
||||||
private static final String ACTION_IGNORE_TOR = "ignore_tor";
|
private static final String ACTION_IGNORE_TOR = "ignore_tor";
|
||||||
private static final String ACTION_UPDATE_ALL = "update_all";
|
private static final String ACTION_UPDATE_ALL = "update_all";
|
||||||
private static final String ACTION_SYNC_NOW = "sync_now";
|
private static final String ACTION_SYNC_NOW = "sync_now";
|
||||||
@@ -61,8 +77,6 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(final Intent intent, int flags, final int startId) {
|
public int onStartCommand(final Intent intent, int flags, final int startId) {
|
||||||
Log.e("PHILIP", "Sync adapter service starting" + intent.getAction());
|
|
||||||
|
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case ACTION_CANCEL: {
|
case ACTION_CANCEL: {
|
||||||
mCancelled.set(true);
|
mCancelled.set(true);
|
||||||
@@ -103,7 +117,6 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case OrbotRequiredDialogActivity.MESSAGE_ORBOT_STARTED: {
|
case OrbotRequiredDialogActivity.MESSAGE_ORBOT_STARTED: {
|
||||||
Log.e("PHILIP", "orbot activity returned");
|
|
||||||
asyncKeyUpdate(KeyserverSyncAdapterService.this,
|
asyncKeyUpdate(KeyserverSyncAdapterService.this,
|
||||||
new CryptoInputParcel());
|
new CryptoInputParcel());
|
||||||
break;
|
break;
|
||||||
@@ -177,10 +190,8 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
|
|
||||||
private void handleUpdateResult(ImportKeyResult result) {
|
private void handleUpdateResult(ImportKeyResult result) {
|
||||||
if (result.isPending()) {
|
if (result.isPending()) {
|
||||||
Log.e(Constants.TAG, "Keyserver sync pending result: "
|
|
||||||
+ result.getRequiredInputParcel().mType);
|
|
||||||
// result is pending due to Orbot not being started
|
// result is pending due to Orbot not being started
|
||||||
// try to start it silently, if disabled show notificationaa
|
// try to start it silently, if disabled show notifications
|
||||||
new OrbotHelper.SilentStartManager() {
|
new OrbotHelper.SilentStartManager() {
|
||||||
@Override
|
@Override
|
||||||
protected void onOrbotStarted() {
|
protected void onOrbotStarted() {
|
||||||
@@ -199,7 +210,8 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
}
|
}
|
||||||
}.startOrbotAndListen(this, false);
|
}.startOrbotAndListen(this, false);
|
||||||
} else if (isUpdateCancelled()) {
|
} else if (isUpdateCancelled()) {
|
||||||
Log.d(Constants.TAG, "Keyserver sync cancelled");
|
Log.d(Constants.TAG, "Keyserver sync cancelled, postponing by" + SYNC_POSTPONE_TIME
|
||||||
|
+ "ms");
|
||||||
postponeSync();
|
postponeSync();
|
||||||
} else {
|
} else {
|
||||||
Log.d(Constants.TAG, "Keyserver sync completed: Updated: " + result.mUpdatedKeys
|
Log.d(Constants.TAG, "Keyserver sync completed: Updated: " + result.mUpdatedKeys
|
||||||
@@ -216,14 +228,13 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
alarmManager.set(
|
alarmManager.set(
|
||||||
AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||||
SystemClock.elapsedRealtime() + 30 * 1000,
|
SystemClock.elapsedRealtime() + SYNC_POSTPONE_TIME,
|
||||||
pi
|
pi
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void asyncKeyUpdate(final Context context,
|
private void asyncKeyUpdate(final Context context,
|
||||||
final CryptoInputParcel cryptoInputParcel) {
|
final CryptoInputParcel cryptoInputParcel) {
|
||||||
Log.e("PHILIP", "async key update starting");
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -234,7 +245,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized ImportKeyResult updateKeysFromKeyserver(final Context context,
|
private synchronized ImportKeyResult updateKeysFromKeyserver(final Context context,
|
||||||
final CryptoInputParcel cryptoInputParcel) {
|
final CryptoInputParcel cryptoInputParcel) {
|
||||||
mCancelled.set(false);
|
mCancelled.set(false);
|
||||||
|
|
||||||
ArrayList<ParcelableKeyRing> keyList = getKeysToUpdate(context);
|
ArrayList<ParcelableKeyRing> keyList = getKeysToUpdate(context);
|
||||||
@@ -278,10 +289,6 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
private ImportKeyResult staggeredUpdate(Context context, ArrayList<ParcelableKeyRing> keyList,
|
private ImportKeyResult staggeredUpdate(Context context, ArrayList<ParcelableKeyRing> keyList,
|
||||||
CryptoInputParcel cryptoInputParcel) {
|
CryptoInputParcel cryptoInputParcel) {
|
||||||
Log.d(Constants.TAG, "Starting staggered update");
|
Log.d(Constants.TAG, "Starting staggered update");
|
||||||
// assuming maxCircuitDirtiness is 10min in Tor
|
|
||||||
// final int MAX_CIRCUIT_DIRTINESS = (int) TimeUnit.MINUTES.toSeconds(10);
|
|
||||||
// TODO: PHILIP remove after testing
|
|
||||||
final int MAX_CIRCUIT_DIRTINESS = (int) TimeUnit.MINUTES.toSeconds(1);
|
|
||||||
// final int WEEK_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(7);
|
// final int WEEK_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(7);
|
||||||
final int WEEK_IN_SECONDS = 0;
|
final int WEEK_IN_SECONDS = 0;
|
||||||
ImportOperation.KeyImportAccumulator accumulator
|
ImportOperation.KeyImportAccumulator accumulator
|
||||||
@@ -289,10 +296,10 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
for (ParcelableKeyRing keyRing : keyList) {
|
for (ParcelableKeyRing keyRing : keyList) {
|
||||||
int waitTime;
|
int waitTime;
|
||||||
int staggeredTime = new Random().nextInt(1 + 2 * (WEEK_IN_SECONDS / keyList.size()));
|
int staggeredTime = new Random().nextInt(1 + 2 * (WEEK_IN_SECONDS / keyList.size()));
|
||||||
if (staggeredTime >= MAX_CIRCUIT_DIRTINESS) {
|
if (staggeredTime >= ORBOT_CIRCUIT_TIMEOUT) {
|
||||||
waitTime = staggeredTime;
|
waitTime = staggeredTime;
|
||||||
} else {
|
} else {
|
||||||
waitTime = MAX_CIRCUIT_DIRTINESS + new Random().nextInt(MAX_CIRCUIT_DIRTINESS);
|
waitTime = ORBOT_CIRCUIT_TIMEOUT + new Random().nextInt(ORBOT_CIRCUIT_TIMEOUT);
|
||||||
}
|
}
|
||||||
Log.d(Constants.TAG, "Updating key with fingerprint " + keyRing.mExpectedFingerprint +
|
Log.d(Constants.TAG, "Updating key with fingerprint " + keyRing.mExpectedFingerprint +
|
||||||
" with a wait time of " + waitTime + "s");
|
" with a wait time of " + waitTime + "s");
|
||||||
@@ -342,18 +349,14 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
final int INDEX_LAST_UPDATED = 1;
|
final int INDEX_LAST_UPDATED = 1;
|
||||||
|
|
||||||
// all time in seconds not milliseconds
|
// all time in seconds not milliseconds
|
||||||
// TODO: PHILIP correct TIME_MAX after testing
|
|
||||||
// final long TIME_MAX = TimeUnit.DAYS.toSeconds(7);
|
|
||||||
final long TIME_MAX = 1;
|
|
||||||
final long CURRENT_TIME = GregorianCalendar.getInstance().getTimeInMillis() / 1000;
|
final long CURRENT_TIME = GregorianCalendar.getInstance().getTimeInMillis() / 1000;
|
||||||
Log.e("PHILIP", "week: " + TIME_MAX + " current: " + CURRENT_TIME);
|
|
||||||
Cursor updatedKeysCursor = context.getContentResolver().query(
|
Cursor updatedKeysCursor = context.getContentResolver().query(
|
||||||
KeychainContract.UpdatedKeys.CONTENT_URI,
|
KeychainContract.UpdatedKeys.CONTENT_URI,
|
||||||
new String[]{
|
new String[]{
|
||||||
KeychainContract.UpdatedKeys.MASTER_KEY_ID,
|
KeychainContract.UpdatedKeys.MASTER_KEY_ID,
|
||||||
KeychainContract.UpdatedKeys.LAST_UPDATED
|
KeychainContract.UpdatedKeys.LAST_UPDATED
|
||||||
},
|
},
|
||||||
"? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_MAX,
|
"? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + KEY_UPDATE_LIMIT,
|
||||||
new String[]{"" + CURRENT_TIME},
|
new String[]{"" + CURRENT_TIME},
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@@ -361,7 +364,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
ArrayList<Long> ignoreMasterKeyIds = new ArrayList<>();
|
ArrayList<Long> ignoreMasterKeyIds = new ArrayList<>();
|
||||||
while (updatedKeysCursor.moveToNext()) {
|
while (updatedKeysCursor.moveToNext()) {
|
||||||
long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID);
|
long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID);
|
||||||
Log.d(Constants.TAG, "Keyserver sync: {" + masterKeyId + "} last updated at {"
|
Log.d(Constants.TAG, "Keyserver sync: Ignoring {" + masterKeyId + "} last updated at {"
|
||||||
+ updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s");
|
+ updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s");
|
||||||
ignoreMasterKeyIds.add(masterKeyId);
|
ignoreMasterKeyIds.add(masterKeyId);
|
||||||
}
|
}
|
||||||
@@ -391,6 +394,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
if (ignoreMasterKeyIds.contains(keyId)) {
|
if (ignoreMasterKeyIds.contains(keyId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Log.d(Constants.TAG, "Keyserver sync: Updating {" + keyId + "}");
|
||||||
String fingerprint = KeyFormattingUtils
|
String fingerprint = KeyFormattingUtils
|
||||||
.convertFingerprintToHex(keyCursor.getBlob(INDEX_FINGERPRINT));
|
.convertFingerprintToHex(keyCursor.getBlob(INDEX_FINGERPRINT));
|
||||||
String hexKeyId = KeyFormattingUtils
|
String hexKeyId = KeyFormattingUtils
|
||||||
@@ -420,13 +424,6 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: PHILIP remove!
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
Log.e("PHILIP", "onDestroy");
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Notification getOrbotNoification(Context context) {
|
private Notification getOrbotNoification(Context context) {
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||||
builder.setSmallIcon(R.drawable.ic_stat_notify_24dp)
|
builder.setSmallIcon(R.drawable.ic_stat_notify_24dp)
|
||||||
@@ -467,6 +464,33 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void enableKeyserverSync(Context context) {
|
||||||
|
try {
|
||||||
|
AccountManager manager = AccountManager.get(context);
|
||||||
|
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||||
|
|
||||||
|
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
|
||||||
|
if (accounts.length == 0) {
|
||||||
|
if (!manager.addAccountExplicitly(account, null, null)) {
|
||||||
|
Log.e(Constants.TAG, "Adding account failed!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for keyserver sync
|
||||||
|
ContentResolver.setIsSyncable(account, Constants.PROVIDER_AUTHORITY, 1);
|
||||||
|
ContentResolver.setSyncAutomatically(account, Constants.PROVIDER_AUTHORITY,
|
||||||
|
true);
|
||||||
|
ContentResolver.addPeriodicSync(
|
||||||
|
account,
|
||||||
|
Constants.PROVIDER_AUTHORITY,
|
||||||
|
new Bundle(),
|
||||||
|
SYNC_INTERVAL
|
||||||
|
);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
Log.e(Constants.TAG, "SecurityException when adding the account", e);
|
||||||
|
Toast.makeText(context, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android
|
// from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android
|
||||||
private Bitmap getBitmap(int resId, Context context) {
|
private Bitmap getBitmap(int resId, Context context) {
|
||||||
int mLargeIconWidth = (int) context.getResources().getDimension(
|
int mLargeIconWidth = (int) context.getResources().getDimension(
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.preference.PreferenceManager;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.Constants.Pref;
|
import org.sufficientlysecure.keychain.Constants.Pref;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||||
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -306,7 +307,7 @@ public class Preferences {
|
|||||||
return new ProxyPrefs(true, false, Constants.Orbot.PROXY_HOST, Constants.Orbot.PROXY_PORT,
|
return new ProxyPrefs(true, false, Constants.Orbot.PROXY_HOST, Constants.Orbot.PROXY_PORT,
|
||||||
Constants.Orbot.PROXY_TYPE);
|
Constants.Orbot.PROXY_TYPE);
|
||||||
} else if (useNormalProxy) {
|
} else if (useNormalProxy) {
|
||||||
return new ProxyPrefs(useTor, useNormalProxy, getProxyHost(), getProxyPort(), getProxyType());
|
return new ProxyPrefs(false, true, getProxyHost(), getProxyPort(), getProxyType());
|
||||||
} else {
|
} else {
|
||||||
return new ProxyPrefs(false, false, null, -1, null);
|
return new ProxyPrefs(false, false, null, -1, null);
|
||||||
}
|
}
|
||||||
@@ -356,7 +357,7 @@ public class Preferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void upgradePreferences() {
|
public void upgradePreferences(Context context) {
|
||||||
if (mSharedPreferences.getInt(Constants.Pref.PREF_DEFAULT_VERSION, 0) !=
|
if (mSharedPreferences.getInt(Constants.Pref.PREF_DEFAULT_VERSION, 0) !=
|
||||||
Constants.Defaults.PREF_VERSION) {
|
Constants.Defaults.PREF_VERSION) {
|
||||||
switch (mSharedPreferences.getInt(Constants.Pref.PREF_DEFAULT_VERSION, 0)) {
|
switch (mSharedPreferences.getInt(Constants.Pref.PREF_DEFAULT_VERSION, 0)) {
|
||||||
@@ -394,6 +395,10 @@ public class Preferences {
|
|||||||
}
|
}
|
||||||
// fall through
|
// fall through
|
||||||
case 5: {
|
case 5: {
|
||||||
|
KeyserverSyncAdapterService.enableKeyserverSync(context);
|
||||||
|
}
|
||||||
|
// fall through
|
||||||
|
case 6: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -409,7 +409,7 @@ public class OrbotHelper {
|
|||||||
private ProgressDialog mProgressDialog;
|
private ProgressDialog mProgressDialog;
|
||||||
|
|
||||||
public void startOrbotAndListen(final Context context, final boolean showProgress) {
|
public void startOrbotAndListen(final Context context, final boolean showProgress) {
|
||||||
Log.e("PHILIP", "starting orbot listener");
|
Log.d(Constants.TAG, "starting orbot listener");
|
||||||
if (showProgress) {
|
if (showProgress) {
|
||||||
showProgressDialog(context);
|
showProgressDialog(context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1314,7 +1314,6 @@
|
|||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
<string name="msg_revoke_error_empty">"Nothing to revoke!"</string>
|
<string name="msg_revoke_error_empty">"Nothing to revoke!"</string>
|
||||||
<string name="msg_revoke_error_multi_secret">"Secret keys can only be revoked individually!"</string>
|
|
||||||
<string name="msg_revoke_error_not_found">"Cannot find key to revoke!"</string>
|
<string name="msg_revoke_error_not_found">"Cannot find key to revoke!"</string>
|
||||||
<string name="msg_revoke_key">"Revoking key %s"</string>
|
<string name="msg_revoke_key">"Revoking key %s"</string>
|
||||||
<string name="msg_revoke_key_fail">"Failed revoking key"</string>
|
<string name="msg_revoke_key_fail">"Failed revoking key"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user