return key status differently for uid and autocrypt peer in KeychainExternalProvider
This commit is contained in:
@@ -119,37 +119,30 @@ public class AutocryptPeerDataAccessObject {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setMasterKeyIdForAutocryptPeer(String autocryptId, long masterKeyId, Date date) {
|
||||
Date lastUpdated = getLastSeen(autocryptId);
|
||||
if (lastUpdated != null && lastUpdated.after(date)) {
|
||||
throw new IllegalArgumentException("Database entry was newer than the one to be inserted! Cannot backdate");
|
||||
}
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ApiAutocryptPeer.MASTER_KEY_ID, masterKeyId);
|
||||
cv.put(ApiAutocryptPeer.LAST_SEEN_KEY, date.getTime());
|
||||
mQueryInterface.update(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId), cv, null, null);
|
||||
public void updateToResetState(String autocryptId, Date effectiveDate) {
|
||||
updateAutocryptState(autocryptId, effectiveDate, null, ApiAutocryptPeer.RESET);
|
||||
}
|
||||
|
||||
public void updateToResetState(String autocryptId, Date effectiveDate) {
|
||||
updateAutocryptState(autocryptId, effectiveDate, ApiAutocryptPeer.RESET);
|
||||
public void updateToGossipState(String autocryptId, Date effectiveDate, long masterKeyId) {
|
||||
updateAutocryptState(autocryptId, effectiveDate, masterKeyId, ApiAutocryptPeer.GOSSIP);
|
||||
}
|
||||
|
||||
public void updateToMutualState(String autocryptId, Date effectiveDate, long masterKeyId) {
|
||||
setMasterKeyIdForAutocryptPeer(autocryptId, masterKeyId, effectiveDate);
|
||||
updateAutocryptState(autocryptId, effectiveDate, ApiAutocryptPeer.MUTUAL);
|
||||
updateAutocryptState(autocryptId, effectiveDate, masterKeyId, ApiAutocryptPeer.MUTUAL);
|
||||
}
|
||||
|
||||
public void updateToAvailableState(String autocryptId, Date effectiveDate, long masterKeyId) {
|
||||
setMasterKeyIdForAutocryptPeer(autocryptId, masterKeyId, effectiveDate);
|
||||
updateAutocryptState(autocryptId, effectiveDate, ApiAutocryptPeer.AVAILABLE);
|
||||
updateAutocryptState(autocryptId, effectiveDate, masterKeyId, ApiAutocryptPeer.AVAILABLE);
|
||||
}
|
||||
|
||||
private void updateAutocryptState(String autocryptId, Date date, int status) {
|
||||
private void updateAutocryptState(String autocryptId, Date date, Long masterKeyId, int status) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ApiAutocryptPeer.MASTER_KEY_ID, (Integer) null);
|
||||
cv.put(ApiAutocryptPeer.MASTER_KEY_ID, masterKeyId);
|
||||
cv.put(ApiAutocryptPeer.LAST_SEEN, date.getTime());
|
||||
cv.put(ApiAutocryptPeer.STATUS, status);
|
||||
if (masterKeyId != null) {
|
||||
cv.put(ApiAutocryptPeer.LAST_SEEN_KEY, masterKeyId);
|
||||
}
|
||||
cv.put(ApiAutocryptPeer.STATE, status);
|
||||
mQueryInterface.update(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId), cv, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class KeychainContract {
|
||||
String IDENTIFIER = "identifier";
|
||||
String LAST_SEEN = "last_updated";
|
||||
String LAST_SEEN_KEY = "last_seen_key";
|
||||
String STATUS = "status";
|
||||
String STATE = "state";
|
||||
String MASTER_KEY_ID = "master_key_id";
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
||||
+ ApiAutocryptPeerColumns.IDENTIFIER + " TEXT NOT NULL, "
|
||||
+ ApiAutocryptPeerColumns.LAST_SEEN + " INTEGER NOT NULL, "
|
||||
+ ApiAutocryptPeerColumns.LAST_SEEN_KEY + " INTEGER NOT NULL, "
|
||||
+ ApiAutocryptPeerColumns.STATUS + " INTEGER NOT NULL, "
|
||||
+ ApiAutocryptPeerColumns.STATE + " INTEGER NOT NULL, "
|
||||
+ ApiAutocryptPeerColumns.MASTER_KEY_ID + " INTEGER NULL, "
|
||||
+ "PRIMARY KEY(" + ApiAutocryptPeerColumns.PACKAGE_NAME + ", "
|
||||
+ ApiAutocryptPeerColumns.IDENTIFIER + "), "
|
||||
|
||||
@@ -26,9 +26,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPee
|
||||
|
||||
|
||||
public class KeychainExternalContract {
|
||||
public static final int KEY_STATUS_UNAVAILABLE = 0;
|
||||
public static final int KEY_STATUS_UNVERIFIED = 1;
|
||||
public static final int KEY_STATUS_VERIFIED = 2;
|
||||
|
||||
// this is in KeychainExternalContract already, but we want to be double
|
||||
// sure this isn't mixed up with the internal one!
|
||||
@@ -36,15 +33,31 @@ public class KeychainExternalContract {
|
||||
private static final Uri BASE_CONTENT_URI_EXTERNAL = Uri
|
||||
.parse("content://" + CONTENT_AUTHORITY_EXTERNAL);
|
||||
public static final String BASE_EMAIL_STATUS = "email_status";
|
||||
public static final String BASE_AUTOCRYPT_PEER_STATUS = "autocrypt_status";
|
||||
public static final String BASE_AUTOCRYPT_PEERS = "autocrypt_peers";
|
||||
|
||||
|
||||
public static class EmailStatus implements BaseColumns {
|
||||
public static final String EMAIL_ADDRESS = "email_address";
|
||||
public static final String USER_ID = "user_id";
|
||||
public static final String USER_ID_STATUS = "email_status";
|
||||
public static final String MASTER_KEY_ID = "master_key_id";
|
||||
public static final String ADDRESS = "address";
|
||||
|
||||
public static final String UID_ADDRESS = "uid_address";
|
||||
public static final String UID_KEY_STATUS = "uid_key_status";
|
||||
public static final String UID_MASTER_KEY_ID = "uid_master_key_id";
|
||||
public static final String UID_CANDIDATES = "uid_candidates";
|
||||
|
||||
public static final String AUTOCRYPT_MASTER_KEY_ID = "autocrypt_master_key_id";
|
||||
public static final String AUTOCRYPT_KEY_STATUS = "autocrypt_key_status";
|
||||
public static final String AUTOCRYPT_PEER_STATE = "autocrypt_peer_state";
|
||||
public static final String AUTOCRYPT_LAST_SEEN = "autocrypt_last_seen";
|
||||
public static final String AUTOCRYPT_LAST_SEEN_KEY = "autocrypt_last_seen_key";
|
||||
|
||||
public static final int KEY_STATUS_UNAVAILABLE = 0;
|
||||
public static final int KEY_STATUS_UNVERIFIED = 1;
|
||||
public static final int KEY_STATUS_VERIFIED = 2;
|
||||
|
||||
public static final int AUTOCRYPT_PEER_RESET = 0;
|
||||
public static final int AUTOCRYPT_PEER_GOSSIP = 1;
|
||||
public static final int AUTOCRYPT_PEER_AVAILABLE = 2;
|
||||
public static final int AUTOCRYPT_PEER_MUTUAL = 3;
|
||||
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_EXTERNAL.buildUpon()
|
||||
.appendPath(BASE_EMAIL_STATUS).build();
|
||||
@@ -53,19 +66,6 @@ public class KeychainExternalContract {
|
||||
"vnd.android.cursor.dir/vnd.org.sufficientlysecure.keychain.provider.email_status";
|
||||
}
|
||||
|
||||
public static class AutocryptPeerStatus implements BaseColumns {
|
||||
public static final String EMAIL_ADDRESS = "email_address";
|
||||
public static final String MASTER_KEY_ID = "master_key_id";
|
||||
public static final String AUTOCRYPT_PEER_LAST_SEEN = "autocrypt_peer_last_seen";
|
||||
public static final String AUTOCRYPT_PEER_STATUS = "autocrypt_peer_state";
|
||||
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_EXTERNAL.buildUpon()
|
||||
.appendPath(BASE_EMAIL_STATUS).build();
|
||||
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.org.sufficientlysecure.keychain.provider.autocrypt_status";
|
||||
}
|
||||
|
||||
public static class ApiAutocryptPeer implements ApiAutocryptPeerColumns, BaseColumns {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_EXTERNAL.buildUpon()
|
||||
.appendPath(BASE_AUTOCRYPT_PEERS).build();
|
||||
|
||||
@@ -999,7 +999,6 @@ public class KeychainProvider extends ContentProvider {
|
||||
}
|
||||
case TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID: {
|
||||
Long masterKeyId = values.getAsLong(ApiAutocryptPeer.MASTER_KEY_ID);
|
||||
long updateTime = values.getAsLong(ApiAutocryptPeer.LAST_SEEN);
|
||||
if (masterKeyId == null) {
|
||||
throw new IllegalArgumentException("master_key_id must be a non-null value!");
|
||||
}
|
||||
@@ -1009,7 +1008,20 @@ public class KeychainProvider extends ContentProvider {
|
||||
actualValues.put(ApiAutocryptPeer.PACKAGE_NAME, packageName);
|
||||
actualValues.put(ApiAutocryptPeer.IDENTIFIER, uri.getLastPathSegment());
|
||||
actualValues.put(ApiAutocryptPeer.MASTER_KEY_ID, masterKeyId);
|
||||
actualValues.put(ApiAutocryptPeer.LAST_SEEN, updateTime);
|
||||
|
||||
Long newLastSeen = values.getAsLong(ApiAutocryptPeer.LAST_SEEN);
|
||||
if (newLastSeen != null) {
|
||||
actualValues.put(ApiAutocryptPeer.LAST_SEEN, newLastSeen);
|
||||
}
|
||||
|
||||
if (values.containsKey(ApiAutocryptPeer.LAST_SEEN_KEY)) {
|
||||
actualValues.put(ApiAutocryptPeer.LAST_SEEN_KEY,
|
||||
values.getAsLong(ApiAutocryptPeer.LAST_SEEN_KEY));
|
||||
}
|
||||
if (values.containsKey(ApiAutocryptPeer.STATE)) {
|
||||
actualValues.put(ApiAutocryptPeer.STATE,
|
||||
values.getAsLong(ApiAutocryptPeer.STATE));
|
||||
}
|
||||
|
||||
try {
|
||||
db.replace(Tables.API_AUTOCRYPT_PEERS, null, actualValues);
|
||||
|
||||
Reference in New Issue
Block a user