Merge pull request #2110 from open-keychain/keyserver-status

Keyserver status
This commit is contained in:
Vincent Breitmoser
2017-07-24 14:13:45 +02:00
committed by GitHub
32 changed files with 676 additions and 36 deletions

View File

@@ -466,6 +466,29 @@ public class ParcelableHkpKeyserver extends Keyserver implements Parcelable {
return getHostID();
}
@Override
public boolean equals(Object obj) {
if (! (obj instanceof ParcelableHkpKeyserver)) {
return false;
}
ParcelableHkpKeyserver other = (ParcelableHkpKeyserver) obj;
if (other.mUrl == null ^ mUrl == null) {
return false;
}
if (other.mOnion == null ^ mOnion == null) {
return false;
}
if (mUrl != null && !mUrl.equals(other.mUrl)) {
return false;
}
if (mOnion != null && !mOnion.equals(other.mOnion)) {
return false;
}
return true;
}
/**
* Tries to find a server responsible for a given domain
*

View File

@@ -188,6 +188,11 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
log.add(LogType.MSG_IMPORT_FETCH_ERROR_NOT_FOUND, 2);
missingKeys += 1;
byte[] fingerprintHex = entry.getExpectedFingerprint();
if (fingerprintHex != null) {
mKeyWritableRepository.renewKeyLastUpdatedTime(
KeyFormattingUtils.getKeyIdFromFingerprint(fingerprintHex), false);
}
continue;
}
@@ -234,7 +239,7 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
}
if (!skipSave) {
mKeyWritableRepository.renewKeyLastUpdatedTime(key.getMasterKeyId());
mKeyWritableRepository.renewKeyLastUpdatedTime(key.getMasterKeyId(), keyWasDownloaded);
}
}

View File

@@ -280,6 +280,32 @@ public class KeyRepository {
return lastUpdateTime;
}
@Nullable
Boolean getSeenOnKeyservers(long masterKeyId) {
Cursor cursor = mContentResolver.query(
UpdatedKeys.CONTENT_URI,
new String[] { UpdatedKeys.SEEN_ON_KEYSERVERS },
UpdatedKeys.MASTER_KEY_ID + " = ?",
new String[] { "" + masterKeyId },
null
);
if (cursor == null) {
return null;
}
Boolean seenOnKeyservers;
try {
if (!cursor.moveToNext()) {
return null;
}
seenOnKeyservers = cursor.isNull(0) ? null : cursor.getInt(0) != 0;
} finally {
cursor.close();
}
return seenOnKeyservers;
}
public final byte[] loadPublicKeyRingData(long masterKeyId) throws NotFoundException {
byte[] data = (byte[]) getGenericDataOrNull(KeyRingData.buildPublicKeyRingUri(masterKeyId),
KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB);

View File

@@ -1348,12 +1348,26 @@ public class KeyWritableRepository extends KeyRepository {
return ContentProviderOperation.newInsert(uri).withValues(values).build();
}
public Uri renewKeyLastUpdatedTime(long masterKeyId) {
public Uri renewKeyLastUpdatedTime(long masterKeyId, boolean seenOnKeyservers) {
boolean isFirstKeyserverStatusCheck = getSeenOnKeyservers(masterKeyId) == null;
ContentValues values = new ContentValues();
values.put(UpdatedKeys.MASTER_KEY_ID, masterKeyId);
values.put(UpdatedKeys.LAST_UPDATED, GregorianCalendar.getInstance().getTimeInMillis() / 1000);
if (seenOnKeyservers || isFirstKeyserverStatusCheck) {
values.put(UpdatedKeys.SEEN_ON_KEYSERVERS, seenOnKeyservers);
}
// this will actually update/replace, doing the right thing™ for seenOnKeyservers value
// see `KeychainProvider.insert()`
return mContentResolver.insert(UpdatedKeys.CONTENT_URI, values);
}
public void resetAllLastUpdatedTimes() {
ContentValues values = new ContentValues();
values.putNull(UpdatedKeys.LAST_UPDATED);
values.putNull(UpdatedKeys.SEEN_ON_KEYSERVERS);
mContentResolver.update(UpdatedKeys.CONTENT_URI, values, null, null);
}
}

View File

@@ -55,6 +55,7 @@ public class KeychainContract {
interface UpdatedKeysColumns {
String MASTER_KEY_ID = "master_key_id"; // not a database id
String LAST_UPDATED = "last_updated"; // time since epoch in seconds
String SEEN_ON_KEYSERVERS = "seen_on_keyservers";
}
interface UserPacketsColumns {

View File

@@ -52,7 +52,7 @@ import org.sufficientlysecure.keychain.util.Log;
*/
public class KeychainDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "openkeychain.db";
private static final int DATABASE_VERSION = 21;
private static final int DATABASE_VERSION = 22;
private Context mContext;
public interface Tables {
@@ -151,6 +151,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
"CREATE TABLE IF NOT EXISTS " + Tables.UPDATED_KEYS + " ("
+ UpdatedKeysColumns.MASTER_KEY_ID + " INTEGER PRIMARY KEY, "
+ UpdatedKeysColumns.LAST_UPDATED + " INTEGER, "
+ UpdatedKeysColumns.SEEN_ON_KEYSERVERS + " INTEGER, "
+ "FOREIGN KEY(" + UpdatedKeysColumns.MASTER_KEY_ID + ") REFERENCES "
+ Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE"
+ ")";
@@ -197,6 +198,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
db.execSQL(CREATE_UPDATE_KEYS);
db.execSQL(CREATE_API_APPS);
db.execSQL(CREATE_API_APPS_ALLOWED_KEYS);
db.execSQL(CREATE_OVERRIDDEN_WARNINGS);
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", "
@@ -307,8 +309,16 @@ public class KeychainDatabase extends SQLiteOpenHelper {
}
*/
case 20:
db.execSQL(CREATE_OVERRIDDEN_WARNINGS);
if (oldVersion == 18 || oldVersion == 19 || oldVersion == 20) {
db.execSQL(
"CREATE TABLE IF NOT EXISTS overridden_warnings ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "identifier TEXT NOT NULL UNIQUE "
+ ")");
case 21:
db.execSQL("ALTER TABLE updated_keys ADD COLUMN seen_on_keyservers INTEGER;");
if (oldVersion == 18 || oldVersion == 19 || oldVersion == 20 || oldVersion == 21) {
// no consolidate for now, often crashes!
return;
}

View File

@@ -639,10 +639,10 @@ public class KeychainProvider extends ContentProvider {
case UPDATED_KEYS_SPECIFIC: {
HashMap<String, String> projectionMap = new HashMap<>();
qb.setTables(Tables.UPDATED_KEYS);
projectionMap.put(UpdatedKeys.MASTER_KEY_ID, Tables.UPDATED_KEYS + "."
+ UpdatedKeys.MASTER_KEY_ID);
projectionMap.put(UpdatedKeys.LAST_UPDATED, Tables.UPDATED_KEYS + "."
+ UpdatedKeys.LAST_UPDATED);
projectionMap.put(UpdatedKeys.MASTER_KEY_ID, Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID);
projectionMap.put(UpdatedKeys.LAST_UPDATED, Tables.UPDATED_KEYS + "." + UpdatedKeys.LAST_UPDATED);
projectionMap.put(UpdatedKeys.SEEN_ON_KEYSERVERS,
Tables.UPDATED_KEYS + "." + UpdatedKeys.SEEN_ON_KEYSERVERS);
qb.setProjectionMap(projectionMap);
if (match == UPDATED_KEYS_SPECIFIC) {
qb.appendWhere(UpdatedKeys.MASTER_KEY_ID + " = ");
@@ -780,9 +780,14 @@ public class KeychainProvider extends ContentProvider {
break;
}
case UPDATED_KEYS: {
long updatedKeyId = db.replace(Tables.UPDATED_KEYS, null, values);
rowUri = UpdatedKeys.CONTENT_URI.buildUpon().appendPath("" + updatedKeyId)
.build();
keyId = values.getAsLong(UpdatedKeys.MASTER_KEY_ID);
try {
db.insertOrThrow(Tables.UPDATED_KEYS, null, values);
} catch (SQLiteConstraintException e) {
db.update(Tables.UPDATED_KEYS, values,
UpdatedKeys.MASTER_KEY_ID + " = ?", new String[] { Long.toString(keyId) });
}
rowUri = UpdatedKeys.CONTENT_URI;
break;
}
case API_APPS: {
@@ -911,6 +916,19 @@ public class KeychainProvider extends ContentProvider {
buildDefaultApiAppsSelection(uri, selection), selectionArgs);
break;
}
case UPDATED_KEYS: {
if (values.size() != 2 ||
!values.containsKey(UpdatedKeys.SEEN_ON_KEYSERVERS) ||
!values.containsKey(UpdatedKeys.LAST_UPDATED) ||
values.get(UpdatedKeys.LAST_UPDATED) != null ||
values.get(UpdatedKeys.SEEN_ON_KEYSERVERS) != null ||
selection != null || selectionArgs != null) {
throw new UnsupportedOperationException("can only reset all keys");
}
db.update(Tables.UPDATED_KEYS, values, null, null);
break;
}
default: {
throw new UnsupportedOperationException("Unknown uri: " + uri);
}

View File

@@ -18,6 +18,11 @@
package org.sufficientlysecure.keychain.ui;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -38,6 +43,8 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver;
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.ui.dialog.AddEditKeyserverDialogFragment;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
import org.sufficientlysecure.keychain.ui.util.Notify;
@@ -45,20 +52,20 @@ import org.sufficientlysecure.keychain.ui.util.recyclerview.ItemTouchHelperAdapt
import org.sufficientlysecure.keychain.ui.util.recyclerview.ItemTouchHelperDragCallback;
import org.sufficientlysecure.keychain.ui.util.recyclerview.ItemTouchHelperViewHolder;
import org.sufficientlysecure.keychain.ui.util.recyclerview.RecyclerItemClickListener;
import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver;
import org.sufficientlysecure.keychain.util.Preferences;
import java.util.ArrayList;
import java.util.Collections;
public class SettingsKeyserverFragment extends Fragment implements RecyclerItemClickListener.OnItemClickListener {
private static final String ARG_KEYSERVER_ARRAY = "arg_keyserver_array";
private ItemTouchHelper mItemTouchHelper;
private ArrayList<ParcelableHkpKeyserver> mKeyservers;
private ArrayList<ParcelableHkpKeyserver> mKeyserversMutable;
private List<ParcelableHkpKeyserver> mKeyservers;
private KeyserverListAdapter mAdapter;
private KeyWritableRepository databaseReadWriteInteractor;
public static SettingsKeyserverFragment newInstance(ArrayList<ParcelableHkpKeyserver> keyservers) {
Bundle args = new Bundle();
args.putParcelableArrayList(ARG_KEYSERVER_ARRAY, keyservers);
@@ -72,6 +79,7 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
databaseReadWriteInteractor = KeyWritableRepository.createDatabaseReadWriteInteractor(getContext());
return inflater.inflate(R.layout.settings_keyserver_fragment, null);
}
@@ -80,9 +88,10 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mKeyservers = getArguments().getParcelableArrayList(ARG_KEYSERVER_ARRAY);
mKeyserversMutable = getArguments().getParcelableArrayList(ARG_KEYSERVER_ARRAY);
mKeyservers = Collections.unmodifiableList(new ArrayList<>(mKeyserversMutable));
mAdapter = new KeyserverListAdapter(mKeyservers);
mAdapter = new KeyserverListAdapter(mKeyserversMutable);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.keyserver_recycler_view);
// recyclerView.setHasFixedSize(true); // the size of the first item changes
@@ -143,7 +152,7 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
if (deleted) {
Notify.create(getActivity(),
getActivity().getString(
R.string.keyserver_preference_deleted, mKeyservers.get(position)),
R.string.keyserver_preference_deleted, mKeyserversMutable.get(position)),
Notify.Style.OK)
.show();
deleteKeyserver(position);
@@ -187,27 +196,27 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
}
private void addKeyserver(ParcelableHkpKeyserver keyserver) {
mKeyservers.add(keyserver);
mAdapter.notifyItemInserted(mKeyservers.size() - 1);
mKeyserversMutable.add(keyserver);
mAdapter.notifyItemInserted(mKeyserversMutable.size() - 1);
saveKeyserverList();
}
private void editKeyserver(ParcelableHkpKeyserver newKeyserver, int position) {
mKeyservers.set(position, newKeyserver);
mKeyserversMutable.set(position, newKeyserver);
mAdapter.notifyItemChanged(position);
saveKeyserverList();
}
private void deleteKeyserver(int position) {
if (mKeyservers.size() == 1) {
if (mKeyserversMutable.size() == 1) {
Notify.create(getActivity(), R.string.keyserver_preference_cannot_delete_last,
Notify.Style.ERROR).show();
return;
}
mKeyservers.remove(position);
mKeyserversMutable.remove(position);
// we use this
mAdapter.notifyItemRemoved(position);
if (position == 0 && mKeyservers.size() > 0) {
if (position == 0 && mKeyserversMutable.size() > 0) {
// if we deleted the first item, we need the adapter to redraw the new first item
mAdapter.notifyItemChanged(0);
}
@@ -215,13 +224,20 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
}
private void saveKeyserverList() {
Preferences.getPreferences(getActivity()).setKeyServers(mKeyservers);
if (mKeyserversMutable.equals(mKeyservers)) {
return;
}
Preferences.getPreferences(getActivity()).setKeyServers(mKeyserversMutable);
mKeyservers = Collections.unmodifiableList(new ArrayList<>(mKeyserversMutable));
databaseReadWriteInteractor.resetAllLastUpdatedTimes();
}
@Override
public void onItemClick(View view, int position) {
startEditKeyserverDialog(AddEditKeyserverDialogFragment.DialogAction.EDIT,
mKeyservers.get(position), position);
mKeyserversMutable.get(position), position);
}
public class KeyserverListAdapter extends RecyclerView.Adapter<KeyserverListAdapter.ViewHolder>

View File

@@ -35,10 +35,12 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.ui.base.LoaderFragment;
import org.sufficientlysecure.keychain.ui.keyview.presenter.IdentitiesPresenter;
import org.sufficientlysecure.keychain.ui.keyview.presenter.KeyHealthPresenter;
import org.sufficientlysecure.keychain.ui.keyview.presenter.KeyserverStatusPresenter;
import org.sufficientlysecure.keychain.ui.keyview.presenter.SystemContactPresenter;
import org.sufficientlysecure.keychain.ui.keyview.presenter.ViewKeyMvpView;
import org.sufficientlysecure.keychain.ui.keyview.view.IdentitiesCardView;
import org.sufficientlysecure.keychain.ui.keyview.view.KeyHealthView;
import org.sufficientlysecure.keychain.ui.keyview.view.KeyserverStatusView;
import org.sufficientlysecure.keychain.ui.keyview.view.SystemContactCardView;
@@ -51,6 +53,7 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
private static final int LOADER_IDENTITIES = 1;
private static final int LOADER_ID_LINKED_CONTACT = 2;
private static final int LOADER_ID_SUBKEY_STATUS = 3;
private static final int LOADER_ID_KEYSERVER_STATUS = 4;
private IdentitiesCardView mIdentitiesCardView;
private IdentitiesPresenter mIdentitiesPresenter;
@@ -59,8 +62,10 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
SystemContactPresenter mSystemContactPresenter;
KeyHealthView mKeyStatusHealth;
KeyserverStatusView mKeyStatusKeyserver;
KeyHealthPresenter mKeyHealthPresenter;
KeyserverStatusPresenter mKeyserverStatusPresenter;
/**
* Creates new instance of this fragment
@@ -85,6 +90,7 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
mSystemContactCard = (SystemContactCardView) view.findViewById(R.id.linked_system_contact_card);
mKeyStatusHealth = (KeyHealthView) view.findViewById(R.id.key_status_health);
mKeyStatusKeyserver = (KeyserverStatusView) view.findViewById(R.id.key_status_keyserver);
return root;
}
@@ -107,6 +113,10 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
mKeyHealthPresenter = new KeyHealthPresenter(
getContext(), mKeyStatusHealth, LOADER_ID_SUBKEY_STATUS, masterKeyId, mIsSecret);
mKeyHealthPresenter.startLoader(getLoaderManager());
mKeyserverStatusPresenter = new KeyserverStatusPresenter(
getContext(), mKeyStatusKeyserver, LOADER_ID_KEYSERVER_STATUS, masterKeyId, mIsSecret);
mKeyserverStatusPresenter.startLoader(getLoaderManager());
}
@Override

View File

@@ -34,6 +34,7 @@ import com.google.auto.value.AutoValue;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.linked.LinkedAttribute;
import org.sufficientlysecure.keychain.linked.UriAttribute;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.IdentityInfo;
@@ -72,6 +73,7 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
private List<IdentityInfo> cachedResult;
private ForceLoadContentObserver identityObserver;
public IdentityLoader(Context context, ContentResolver contentResolver, long masterKeyId, boolean showLinkedIds) {
super(context);
@@ -79,6 +81,8 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
this.contentResolver = contentResolver;
this.masterKeyId = masterKeyId;
this.showLinkedIds = showLinkedIds;
this.identityObserver = new ForceLoadContentObserver();
}
@Override
@@ -169,6 +173,16 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
if (takeContentChanged() || cachedResult == null) {
forceLoad();
}
getContext().getContentResolver().registerContentObserver(
KeyRings.buildGenericKeyRingUri(masterKeyId), true, identityObserver);
}
@Override
protected void onAbandon() {
super.onAbandon();
getContext().getContentResolver().unregisterContentObserver(identityObserver);
}
public interface IdentityInfo {

View File

@@ -0,0 +1,153 @@
/*
* Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.keyview.loader;
import java.util.Date;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusLoader.KeyserverStatus;
public class KeyserverStatusLoader extends AsyncTaskLoader<KeyserverStatus> {
public static final String[] PROJECTION = new String[] {
UpdatedKeys.LAST_UPDATED,
UpdatedKeys.SEEN_ON_KEYSERVERS
};
private static final int INDEX_LAST_UPDATED = 0;
private static final int INDEX_SEEN_ON_KEYSERVERS = 1;
private final ContentResolver contentResolver;
private final long masterKeyId;
private KeyserverStatus cachedResult;
private ForceLoadContentObserver keyserverStatusObserver;
public KeyserverStatusLoader(Context context, ContentResolver contentResolver, long masterKeyId) {
super(context);
this.contentResolver = contentResolver;
this.masterKeyId = masterKeyId;
this.keyserverStatusObserver = new ForceLoadContentObserver();
}
@Override
public KeyserverStatus loadInBackground() {
Cursor cursor = contentResolver.query(UpdatedKeys.CONTENT_URI, PROJECTION,
UpdatedKeys.MASTER_KEY_ID + " = ?", new String[] { Long.toString(masterKeyId) }, null);
if (cursor == null) {
Log.e(Constants.TAG, "Error loading key items!");
return null;
}
try {
if (cursor.moveToFirst()) {
if (cursor.isNull(INDEX_SEEN_ON_KEYSERVERS) || cursor.isNull(INDEX_LAST_UPDATED)) {
return new KeyserverStatus(masterKeyId);
}
boolean isPublished = cursor.getInt(INDEX_SEEN_ON_KEYSERVERS) != 0;
Date lastUpdated = new Date(cursor.getLong(INDEX_LAST_UPDATED) * 1000);
return new KeyserverStatus(masterKeyId, isPublished, lastUpdated);
}
return new KeyserverStatus(masterKeyId);
} finally {
cursor.close();
}
}
@Override
public void deliverResult(KeyserverStatus keySubkeyStatus) {
cachedResult = keySubkeyStatus;
if (isStarted()) {
super.deliverResult(keySubkeyStatus);
}
}
@Override
protected void onStartLoading() {
if (cachedResult != null) {
deliverResult(cachedResult);
}
if (takeContentChanged() || cachedResult == null) {
forceLoad();
}
getContext().getContentResolver().registerContentObserver(
KeyRings.buildGenericKeyRingUri(masterKeyId), true, keyserverStatusObserver);
}
@Override
protected void onAbandon() {
super.onAbandon();
getContext().getContentResolver().unregisterContentObserver(keyserverStatusObserver);
}
public static class KeyserverStatus {
private final long masterKeyId;
private final boolean isPublished;
private final Date lastUpdated;
KeyserverStatus(long masterKeyId, boolean isPublished, Date lastUpdated) {
this.masterKeyId = masterKeyId;
this.isPublished = isPublished;
this.lastUpdated = lastUpdated;
}
KeyserverStatus(long masterKeyId) {
this.masterKeyId = masterKeyId;
this.isPublished = false;
this.lastUpdated = null;
}
long getMasterKeyId() {
return masterKeyId;
}
public boolean hasBeenUpdated() {
return lastUpdated != null;
}
public boolean isPublished() {
if (lastUpdated == null) {
throw new IllegalStateException("Cannot get publication state if key has never been updated!");
}
return isPublished;
}
public Date getLastUpdated() {
return lastUpdated;
}
}
}

View File

@@ -115,9 +115,11 @@ public class KeyHealthPresenter implements LoaderCallbacks<KeySubkeyStatus> {
view.setKeyStatus(keyHealthStatus);
view.setPrimaryExpiryDate(subkeyStatus.keyCertify.mExpiry);
view.setShowExpander(false);
view.hideExpandedInfo();
} else {
view.setKeyStatus(keyHealthStatus);
view.setShowExpander(keyHealthStatus != KeyHealthStatus.REVOKED);
view.hideExpandedInfo();
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.keyview.presenter;
import java.util.Date;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusLoader;
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusLoader.KeyserverStatus;
public class KeyserverStatusPresenter implements LoaderCallbacks<KeyserverStatus> {
private final Context context;
private final KeyserverStatusMvpView view;
private final int loaderId;
private final long masterKeyId;
private final boolean isSecret;
public KeyserverStatusPresenter(Context context, KeyserverStatusMvpView view, int loaderId, long masterKeyId,
boolean isSecret) {
this.context = context;
this.view = view;
this.loaderId = loaderId;
this.masterKeyId = masterKeyId;
this.isSecret = isSecret;
}
public void startLoader(LoaderManager loaderManager) {
loaderManager.restartLoader(loaderId, null, this);
}
@Override
public Loader<KeyserverStatus> onCreateLoader(int id, Bundle args) {
return new KeyserverStatusLoader(context, context.getContentResolver(), masterKeyId);
}
@Override
public void onLoadFinished(Loader<KeyserverStatus> loader, KeyserverStatus keyserverStatus) {
if (keyserverStatus.hasBeenUpdated()) {
if (keyserverStatus.isPublished()) {
view.setDisplayStatusPublished();
} else {
view.setDisplayStatusNotPublished();
}
view.setLastUpdated(keyserverStatus.getLastUpdated());
} else {
view.setDisplayStatusUnknown();
}
}
@Override
public void onLoaderReset(Loader loader) {
}
public interface KeyserverStatusMvpView {
void setDisplayStatusPublished();
void setDisplayStatusNotPublished();
void setLastUpdated(Date lastUpdated);
void setDisplayStatusUnknown();
}
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.keyview.view;
import java.util.Date;
import android.content.Context;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.keyview.presenter.KeyserverStatusPresenter.KeyserverStatusMvpView;
public class KeyserverStatusView extends FrameLayout implements KeyserverStatusMvpView {
private final View vLayout;
private final TextView vTitle;
private final TextView vSubtitle;
private final ImageView vIcon;
public KeyserverStatusView(Context context, AttributeSet attrs) {
super(context, attrs);
View view = LayoutInflater.from(context).inflate(R.layout.key_keyserver_status_layout, this, true);
vLayout = view.findViewById(R.id.keyserver_status_layout);
vTitle = (TextView) view.findViewById(R.id.keyserver_status_title);
vSubtitle = (TextView) view.findViewById(R.id.keyserver_status_subtitle);
vIcon = (ImageView) view.findViewById(R.id.keyserver_icon);
// vExpander = (ImageView) view.findViewById(R.id.key_health_expander);
}
private enum KeyserverDisplayStatus {
PUBLISHED (R.string.keyserver_title_published, R.drawable.ic_cloud_black_24dp, R.color.md_grey_900),
NOT_PUBLISHED (R.string.keyserver_title_not_published, R.drawable.ic_cloud_off_24dp, R.color.md_grey_900),
UNKNOWN (R.string.keyserver_title_unknown, R.drawable.ic_cloud_unknown_24dp, R.color.md_grey_900);
@StringRes
private final int title;
@DrawableRes
private final int icon;
@ColorRes
private final int iconColor;
KeyserverDisplayStatus(@StringRes int title, @DrawableRes int icon, @ColorRes int iconColor) {
this.title = title;
this.icon = icon;
this.iconColor = iconColor;
}
}
@Override
public void setDisplayStatusPublished() {
setDisplayStatus(KeyserverDisplayStatus.PUBLISHED);
}
@Override
public void setDisplayStatusNotPublished() {
setDisplayStatus(KeyserverDisplayStatus.NOT_PUBLISHED);
}
@Override
public void setDisplayStatusUnknown() {
setDisplayStatus(KeyserverDisplayStatus.UNKNOWN);
vSubtitle.setText(R.string.keyserver_last_updated_never);
}
@Override
public void setLastUpdated(Date lastUpdated) {
String lastUpdatedText = DateFormat.getMediumDateFormat(getContext()).format(lastUpdated);
vSubtitle.setText(getResources().getString(R.string.keyserver_last_updated, lastUpdatedText));
}
private void setDisplayStatus(KeyserverDisplayStatus displayStatus) {
vTitle.setText(displayStatus.title);
vIcon.setImageResource(displayStatus.icon);
vIcon.setColorFilter(ContextCompat.getColor(getContext(), displayStatus.iconColor));
setVisibility(View.VISIBLE);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -70,7 +70,9 @@
android:layout_width="match_parent"
android:layout_height="1dip"
android:id="@+id/key_health_divider"
android:background="?android:attr/listDivider" />
android:background="?android:attr/listDivider"
android:visibility="gone"
tools:visibility="visible" />
<LinearLayout
android:orientation="vertical"
@@ -82,7 +84,7 @@
android:paddingRight="8dp"
android:id="@+id/key_insecure_layout"
android:visibility="gone"
tools:visibility="visible">
tools:visibility="gone">
<TextView
android:layout_width="wrap_content"
@@ -122,18 +124,24 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:id="@+id/key_expiry_layout"
android:visibility="gone"
tools:visibility="visible">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider"
/>
<TextView
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:id="@+id/key_expiry_text"
android:textAppearance="?android:textAppearanceSmall"
tools:text="@string/key_expiry_text"

View File

@@ -0,0 +1,65 @@
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/keyserver_status_layout"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:background="?selectableItemBackground"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/keyserver_icon"
tools:src="@drawable/ic_cloud_black_24dp"
tools:tint="@color/android_green_light"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/keyserver_status_title"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="@string/keyserver_title_published" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/keyserver_status_subtitle"
tools:text="Last updated: 2017-05-20" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/key_health_expander"
android:src="@drawable/ic_expand_more_black_24dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:visibility="gone"
tools:visibility="visible"
/>
</LinearLayout>
</merge>

View File

@@ -1,7 +1,9 @@
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="@layout/tools_vertlin">
tools:parentTag="LinearLayout"
tools:layout_width="match_parent"
tools:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"

View File

@@ -36,6 +36,17 @@
android:id="@+id/key_status_health"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<org.sufficientlysecure.keychain.ui.keyview.view.KeyserverStatusView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/key_status_keyserver"
/>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@@ -1842,6 +1842,12 @@
<string name="key_health_partial_stripped_title">"Healthy (Partially Stripped)"</string>
<string name="key_health_partial_stripped_subtitle">"Click for details"</string>
<string name="keyserver_title_published">"Published"</string>
<string name="keyserver_title_not_published">"Not Published"</string>
<string name="keyserver_title_unknown">"Keyserver status: Unknown"</string>
<string name="keyserver_last_updated">"Last checked: %s"</string>
<string name="keyserver_last_updated_never">Last checked: Never</string>
<string name="key_insecure_bitstrength_2048_problem">"This key uses the <b>%1$s</b> algorithm with a strength of <b>%2$s bits</b>. A secure key should have a strength of 2048 bits."</string>
<string name="key_insecure_bitstrength_2048_solution">"This key can\'t be upgraded. For secure communication, the owner must generate a new key."</string>

View File

@@ -0,0 +1,4 @@
<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M19.35 10.04C18.67 6.59 15.64 4 12 4c-1.48 0-2.85.43-4.01 1.17l1.46 1.46C10.21 6.23 11.08 6 12 6c3.04 0 5.5 2.46 5.5 5.5v.5H19c1.66 0 3 1.34 3 3 0 1.13-.64 2.11-1.56 2.62l1.45 1.45C23.16 18.16 24 16.68 24 15c0-2.64-2.05-4.78-4.65-4.96zM3 5.27l2.75 2.74C2.56 8.15 0 10.77 0 14c0 3.31 2.69 6 6 6h11.73l2 2L21 20.73 4.27 4 3 5.27zM7.73 10l8 8H6c-2.21 0-4-1.79-4-4s1.79-4 4-4h1.73z"/>
</svg>

After

Width:  |  Height:  |  Size: 541 B

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="190.282px" height="190.282px" viewBox="0 0 190.282 190.282" style="enable-background:new 0 0 190.282 190.282;"
xml:space="preserve">
<g>
<g id="_x31_48_28_">
<g>
<rect x="161.592" y="134.46" width="15.346" height="14.609"/>
<path d="M189.068,105.211c-0.711-1.793-1.833-3.438-3.355-4.941c-1.523-1.492-3.515-2.722-5.973-3.687
c-2.457-0.96-5.479-1.437-9.074-1.437c-3.636,0-6.723,0.548-9.252,1.655c-2.533,1.106-4.615,2.544-6.23,4.312
c-1.63,1.777-2.828,3.782-3.615,6.012c-0.782,2.239-1.255,4.515-1.402,6.83h15.417c-0.147-1.63,0.147-3.077,0.884-4.352
c0.736-1.28,1.99-1.92,3.763-1.92c2.849,0,4.275,1.249,4.275,3.763c0,0.838-0.243,1.549-0.736,2.138
c-0.497,0.59-1.097,1.098-1.812,1.514c-0.711,0.416-1.457,0.797-2.249,1.143c-0.793,0.351-1.473,0.665-2.067,0.965
c-1.422,0.782-2.498,1.772-3.245,2.945c-0.736,1.183-1.249,2.387-1.549,3.615c-0.294,1.229-0.441,2.433-0.441,3.61
c0,1.133,0.025,2.062,0.081,2.798h13.645c0-0.827,0.062-1.568,0.178-2.209c0.122-0.64,0.335-1.203,0.63-1.695
c0.3-0.493,0.716-0.96,1.254-1.402c0.544-0.446,1.229-0.889,2.062-1.33c1.224-0.64,2.438-1.265,3.61-1.879
c1.188-0.614,2.254-1.392,3.209-2.325c0.955-0.93,1.731-2.098,2.325-3.504c0.584-1.401,0.884-3.229,0.884-5.495
C190.186,108.709,189.785,107.009,189.068,105.211z"/>
<path d="M176.42,73.035c1.193,0,2.376,0.099,3.555,0.178c0.167-1.176,0.299-2.356,0.36-3.547
c-1.158-21.498-16.463-36.785-37.942-37.945c-12.604-0.675-23.115,5.759-29.859,15.168C105.8,38.02,95.317,32.408,82.655,31.72
c-21.439-1.152-36.869,18.199-37.933,37.945c-0.122,2.536,0.041,4.977,0.437,7.335c-1.343-0.19-2.709-0.32-4.103-0.398
c-23.176-1.249-39.852,19.672-41.002,41c-1.181,21.805,17.266,37.851,37.222,40.628v0.381h101.679
c-8.389-9.095-13.558-21.205-13.558-34.561C125.391,95.877,148.242,73.035,176.42,73.035z"/>
</g>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -22,7 +22,7 @@ SRC_DIR=./drawables/
#inkscape -w 512 -h 512 -e "$PLAY_DIR/$NAME.png" $NAME.svg
for NAME in "broken_heart" "ic_cloud_search" "ic_action_encrypt_file" "ic_action_encrypt_text" "ic_action_verified_cutout" "ic_action_encrypt_copy" "ic_action_encrypt_paste" "ic_action_encrypt_save" "ic_action_encrypt_share" "status_lock_closed" "status_lock_error" "status_lock_open" "status_signature_expired_cutout" "status_signature_invalid_cutout" "status_signature_revoked_cutout" "status_signature_unknown_cutout" "status_signature_unverified_cutout" "status_signature_verified_cutout" "key_flag_authenticate" "key_flag_certify" "key_flag_encrypt" "key_flag_sign" "yubi_icon" "ic_stat_notify" "status_signature_verified_inner" "link" "octo_link"
for NAME in "ic_cloud_unknown" "ic_cloud_off" "broken_heart" "ic_cloud_search" "ic_action_encrypt_file" "ic_action_encrypt_text" "ic_action_verified_cutout" "ic_action_encrypt_copy" "ic_action_encrypt_paste" "ic_action_encrypt_save" "ic_action_encrypt_share" "status_lock_closed" "status_lock_error" "status_lock_open" "status_signature_expired_cutout" "status_signature_invalid_cutout" "status_signature_revoked_cutout" "status_signature_unknown_cutout" "status_signature_unverified_cutout" "status_signature_verified_cutout" "key_flag_authenticate" "key_flag_certify" "key_flag_encrypt" "key_flag_sign" "yubi_icon" "ic_stat_notify" "status_signature_verified_inner" "link" "octo_link"
do
echo $NAME
inkscape -w 24 -h 24 -e "$MDPI_DIR/${NAME}_24dp.png" "$SRC_DIR/$NAME.svg"