always insert autocrypt key before update operations
This commit is contained in:
@@ -94,37 +94,39 @@ public class AutocryptPeerDao extends AbstractDao {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureAutocryptPeerExists(String packageName, String autocryptId) {
|
||||||
|
InsertPeer insertStatement = new InsertPeer(getWritableDb());
|
||||||
|
insertStatement.bind(packageName, autocryptId);
|
||||||
|
insertStatement.executeInsert();
|
||||||
|
}
|
||||||
|
|
||||||
public void insertOrUpdateLastSeen(String packageName, String autocryptId, Date date) {
|
public void insertOrUpdateLastSeen(String packageName, String autocryptId, Date date) {
|
||||||
|
ensureAutocryptPeerExists(packageName, autocryptId);
|
||||||
|
|
||||||
UpdateLastSeen updateStatement = new UpdateLastSeen(getWritableDb(), AutocryptPeer.FACTORY);
|
UpdateLastSeen updateStatement = new UpdateLastSeen(getWritableDb(), AutocryptPeer.FACTORY);
|
||||||
updateStatement.bind(packageName, autocryptId, date);
|
updateStatement.bind(packageName, autocryptId, date);
|
||||||
int updated = updateStatement.executeUpdateDelete();
|
updateStatement.executeUpdateDelete();
|
||||||
|
|
||||||
if (updated == 0) {
|
|
||||||
InsertPeer insertStatement = new InsertPeer(getWritableDb(), AutocryptPeer.FACTORY);
|
|
||||||
insertStatement.bind(packageName, autocryptId, date);
|
|
||||||
insertStatement.executeInsert();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateKey(String packageName, String autocryptId, Date effectiveDate, long masterKeyId,
|
public void updateKey(String packageName, String autocryptId, Date effectiveDate, long masterKeyId,
|
||||||
boolean isMutual) {
|
boolean isMutual) {
|
||||||
|
ensureAutocryptPeerExists(packageName, autocryptId);
|
||||||
|
|
||||||
UpdateKey updateStatement = new UpdateKey(getWritableDb(), AutocryptPeer.FACTORY);
|
UpdateKey updateStatement = new UpdateKey(getWritableDb(), AutocryptPeer.FACTORY);
|
||||||
updateStatement.bind(packageName, autocryptId, effectiveDate, masterKeyId, isMutual);
|
updateStatement.bind(packageName, autocryptId, effectiveDate, masterKeyId, isMutual);
|
||||||
int rowsUpdated = updateStatement.executeUpdateDelete();
|
updateStatement.executeUpdateDelete();
|
||||||
if (rowsUpdated == 0) {
|
|
||||||
throw new IllegalStateException("No rows updated! Was this peer inserted before the update?");
|
|
||||||
}
|
|
||||||
getDatabaseNotifyManager().notifyAutocryptUpdate(autocryptId, masterKeyId);
|
getDatabaseNotifyManager().notifyAutocryptUpdate(autocryptId, masterKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateKeyGossip(String packageName, String autocryptId, Date effectiveDate, long masterKeyId,
|
public void updateKeyGossip(String packageName, String autocryptId, Date effectiveDate, long masterKeyId,
|
||||||
GossipOrigin origin) {
|
GossipOrigin origin) {
|
||||||
|
ensureAutocryptPeerExists(packageName, autocryptId);
|
||||||
|
|
||||||
UpdateGossipKey updateStatement = new UpdateGossipKey(getWritableDb(), AutocryptPeer.FACTORY);
|
UpdateGossipKey updateStatement = new UpdateGossipKey(getWritableDb(), AutocryptPeer.FACTORY);
|
||||||
updateStatement.bind(packageName, autocryptId, effectiveDate, masterKeyId, origin);
|
updateStatement.bind(packageName, autocryptId, effectiveDate, masterKeyId, origin);
|
||||||
int rowsUpdated = updateStatement.executeUpdateDelete();
|
updateStatement.executeUpdateDelete();
|
||||||
if (rowsUpdated == 0) {
|
|
||||||
throw new IllegalStateException("No rows updated! Was this peer inserted before the update?");
|
|
||||||
}
|
|
||||||
getDatabaseNotifyManager().notifyAutocryptUpdate(autocryptId, masterKeyId);
|
getDatabaseNotifyManager().notifyAutocryptUpdate(autocryptId, masterKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,10 +40,6 @@ public abstract class AutocryptPeer implements AutocryptPeersModel {
|
|||||||
return gossip_key_is_verified_int() != 0;
|
return gossip_key_is_verified_int() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasKey() {
|
|
||||||
return autocryptPeer().master_key_id() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isKeyRevoked() {
|
public boolean isKeyRevoked() {
|
||||||
Boolean revoked = key_is_revoked_int();
|
Boolean revoked = key_is_revoked_int();
|
||||||
return revoked != null && revoked;
|
return revoked != null && revoked;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ updateGossipKey:
|
|||||||
UPDATE autocrypt_peers SET gossip_last_seen_key = ?3, gossip_master_key_id = ?4, gossip_origin = ?5 WHERE package_name = ?1 AND identifier = ?2;
|
UPDATE autocrypt_peers SET gossip_last_seen_key = ?3, gossip_master_key_id = ?4, gossip_origin = ?5 WHERE package_name = ?1 AND identifier = ?2;
|
||||||
|
|
||||||
insertPeer:
|
insertPeer:
|
||||||
INSERT INTO autocrypt_peers (package_name, identifier, last_seen) VALUES (?, ?, ?);
|
INSERT OR IGNORE INTO autocrypt_peers (package_name, identifier) VALUES (?, ?);
|
||||||
|
|
||||||
selectAutocryptKeyStatus:
|
selectAutocryptKeyStatus:
|
||||||
SELECT autocryptPeer.*,
|
SELECT autocryptPeer.*,
|
||||||
|
|||||||
Reference in New Issue
Block a user