Change Autocrypt logic to more closely match the spec

This commit is contained in:
Vincent Breitmoser
2018-01-15 18:16:48 +01:00
parent 1c3f9fd27f
commit ebe262015a
5 changed files with 118 additions and 86 deletions

View File

@@ -153,6 +153,23 @@ public class AutocryptPeerDataAccessObject {
return null;
}
public Date getLastSeenGossip(String autocryptId) {
Cursor cursor = queryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
long lastUpdated = cursor.getColumnIndex(ApiAutocryptPeer.GOSSIP_LAST_SEEN_KEY);
return new Date(lastUpdated);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return null;
}
public void updateLastSeen(String autocryptId, Date date) {
ContentValues cv = new ContentValues();
cv.put(ApiAutocryptPeer.LAST_SEEN, date.getTime());

View File

@@ -1114,42 +1114,25 @@ public class KeychainProvider extends ContentProvider {
break;
}
case AUTOCRYPT_PEERS_BY_PACKAGE_NAME_AND_TRUST_ID: {
ContentValues actualValues = new ContentValues();
String packageName = uri.getPathSegments().get(2);
actualValues.put(ApiAutocryptPeer.PACKAGE_NAME, packageName);
actualValues.put(ApiAutocryptPeer.IDENTIFIER, uri.getLastPathSegment());
String identifier = uri.getLastPathSegment();
values.put(ApiAutocryptPeer.PACKAGE_NAME, packageName);
values.put(ApiAutocryptPeer.IDENTIFIER, identifier);
Long newLastSeen = values.getAsLong(ApiAutocryptPeer.LAST_SEEN);
if (newLastSeen != null) {
actualValues.put(ApiAutocryptPeer.LAST_SEEN, newLastSeen);
db.replace(Tables.API_AUTOCRYPT_PEERS, null, actualValues);
break;
int updated = db.update(Tables.API_AUTOCRYPT_PEERS, values,
ApiAutocryptPeer.PACKAGE_NAME + "=? AND " + ApiAutocryptPeer.IDENTIFIER + "=?",
new String[] { packageName, identifier });
if (updated == 0) {
db.insertOrThrow(Tables.API_AUTOCRYPT_PEERS, null, values);
}
Long masterKeyId = values.getAsLong(ApiAutocryptPeer.MASTER_KEY_ID);
if (masterKeyId != null) {
Long lastSeenKey = values.getAsLong(ApiAutocryptPeer.LAST_SEEN_KEY);
Long preferEncryptState = values.getAsLong(ApiAutocryptPeer.IS_MUTUAL);
actualValues.put(ApiAutocryptPeer.MASTER_KEY_ID, masterKeyId);
actualValues.put(ApiAutocryptPeer.LAST_SEEN_KEY, lastSeenKey);
actualValues.put(ApiAutocryptPeer.IS_MUTUAL, preferEncryptState);
db.replace(Tables.API_AUTOCRYPT_PEERS, null, actualValues);
contentResolver.notifyChange(KeyRings.buildGenericKeyRingUri(masterKeyId), null);
break;
}
Long gossipMasterKeyId = values.getAsLong(ApiAutocryptPeer.GOSSIP_MASTER_KEY_ID);
if (gossipMasterKeyId != null) {
Long gossipLastSeenKey = values.getAsLong(ApiAutocryptPeer.GOSSIP_LAST_SEEN_KEY);
actualValues.put(ApiAutocryptPeer.GOSSIP_MASTER_KEY_ID, gossipMasterKeyId);
actualValues.put(ApiAutocryptPeer.GOSSIP_LAST_SEEN_KEY, gossipLastSeenKey);
db.replace(Tables.API_AUTOCRYPT_PEERS, null, actualValues);
if (gossipMasterKeyId != null && !gossipMasterKeyId.equals(masterKeyId)) {
contentResolver.notifyChange(KeyRings.buildGenericKeyRingUri(gossipMasterKeyId), null);
break;
}
break;