Index consistently with the identity id
This commit is contained in:
parent
b589275ab4
commit
e2932af18f
|
@ -37,6 +37,8 @@ public class ContactDetailsDialog : Gtk.Dialog {
|
||||||
|
|
||||||
(get_header_bar() as HeaderBar).set_subtitle(jid.bare_jid.to_string());
|
(get_header_bar() as HeaderBar).set_subtitle(jid.bare_jid.to_string());
|
||||||
|
|
||||||
|
int identity_id = plugin.db.identity.get_id(account.id);
|
||||||
|
if (identity_id < 0) return;
|
||||||
|
|
||||||
// Dialog opened from the account settings menu
|
// Dialog opened from the account settings menu
|
||||||
// Show the fingerprint for this device separately with buttons for a qrcode and to copy
|
// Show the fingerprint for this device separately with buttons for a qrcode and to copy
|
||||||
|
@ -64,19 +66,19 @@ public class ContactDetailsDialog : Gtk.Dialog {
|
||||||
keys_listbox.set_header_func(header_function);
|
keys_listbox.set_header_func(header_function);
|
||||||
|
|
||||||
//Show any new devices for which the user must decide whether to accept or reject
|
//Show any new devices for which the user must decide whether to accept or reject
|
||||||
foreach (Row device in plugin.db.identity_meta.get_new_devices(account.id, jid.to_string())) {
|
foreach (Row device in plugin.db.identity_meta.get_new_devices(identity_id, jid.to_string())) {
|
||||||
add_new_fingerprint(device);
|
add_new_fingerprint(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Show the normal devicelist
|
//Show the normal devicelist
|
||||||
foreach (Row device in plugin.db.identity_meta.get_known_devices(account.id, jid.to_string())) {
|
foreach (Row device in plugin.db.identity_meta.get_known_devices(identity_id, jid.to_string())) {
|
||||||
if(own && device[plugin.db.identity_meta.device_id] == own_id) {
|
if(own && device[plugin.db.identity_meta.device_id] == own_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
add_fingerprint(device, (Database.IdentityMetaTable.TrustLevel) device[plugin.db.identity_meta.trust_level]);
|
add_fingerprint(device, (Database.IdentityMetaTable.TrustLevel) device[plugin.db.identity_meta.trust_level]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto_accept_switch.set_active(plugin.db.trust.get_blind_trust(account.id, jid.bare_jid.to_string()));
|
auto_accept_switch.set_active(plugin.db.trust.get_blind_trust(identity_id, jid.bare_jid.to_string()));
|
||||||
|
|
||||||
auto_accept_switch.state_set.connect((active) => {
|
auto_accept_switch.state_set.connect((active) => {
|
||||||
plugin.trust_manager.set_blind_trust(account, jid, active);
|
plugin.trust_manager.set_blind_trust(account, jid, active);
|
||||||
|
@ -84,7 +86,7 @@ public class ContactDetailsDialog : Gtk.Dialog {
|
||||||
if (active) {
|
if (active) {
|
||||||
new_keys_container.visible = false;
|
new_keys_container.visible = false;
|
||||||
|
|
||||||
foreach (Row device in plugin.db.identity_meta.get_new_devices(account.id, jid.to_string())) {
|
foreach (Row device in plugin.db.identity_meta.get_new_devices(identity_id, jid.to_string())) {
|
||||||
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], Database.IdentityMetaTable.TrustLevel.TRUSTED);
|
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], Database.IdentityMetaTable.TrustLevel.TRUSTED);
|
||||||
add_fingerprint(device, Database.IdentityMetaTable.TrustLevel.TRUSTED);
|
add_fingerprint(device, Database.IdentityMetaTable.TrustLevel.TRUSTED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,11 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
|
||||||
public void populate(Conversation conversation, Plugins.ContactDetails contact_details, WidgetType type) {
|
public void populate(Conversation conversation, Plugins.ContactDetails contact_details, WidgetType type) {
|
||||||
if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK) {
|
if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK) {
|
||||||
|
|
||||||
|
int identity_id = plugin.db.identity.get_id(conversation.account.id);
|
||||||
|
if (identity_id < 0) return;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (Row row in plugin.db.identity_meta.with_address(conversation.account.id, conversation.counterpart.to_string())) {
|
foreach (Row row in plugin.db.identity_meta.with_address(identity_id, conversation.counterpart.to_string())) {
|
||||||
if (row[plugin.db.identity_meta.identity_key_public_base64] != null) {
|
if (row[plugin.db.identity_meta.identity_key_public_base64] != null) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class Database : Qlite.Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert_device_list(int32 identity_id, string address_name, ArrayList<int32> devices) {
|
public void insert_device_list(int32 identity_id, string address_name, ArrayList<int32> devices) {
|
||||||
update().with(this.address_name, "=", address_name).set(now_active, false).perform();
|
update().with(this.identity_id, "=", identity_id).with(this.address_name, "=", address_name).set(now_active, false).perform();
|
||||||
foreach (int32 device_id in devices) {
|
foreach (int32 device_id in devices) {
|
||||||
upsert()
|
upsert()
|
||||||
.value(this.identity_id, identity_id, true)
|
.value(this.identity_id, identity_id, true)
|
||||||
|
@ -124,6 +124,13 @@ public class Database : Qlite.Database {
|
||||||
base(db, "identity");
|
base(db, "identity");
|
||||||
init({id, account_id, device_id, identity_key_private_base64, identity_key_public_base64});
|
init({id, account_id, device_id, identity_key_private_base64, identity_key_public_base64});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int get_id(int account_id) {
|
||||||
|
int id = -1;
|
||||||
|
Row? row = this.row_with(this.account_id, account_id).inner;
|
||||||
|
if (row != null) id = ((!)row)[this.id];
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SignedPreKeyTable : Table {
|
public class SignedPreKeyTable : Table {
|
||||||
|
|
|
@ -20,7 +20,9 @@ public class DeviceNotificationPopulator : NotificationPopulator, Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool has_new_devices(Jid jid) {
|
public bool has_new_devices(Jid jid) {
|
||||||
return plugin.db.identity_meta.get_new_devices(current_conversation.account.id, jid.bare_jid.to_string()).count() > 0;
|
int identity_id = plugin.db.identity.get_id(current_conversation.account.id);
|
||||||
|
if (identity_id < 0) return false;
|
||||||
|
return plugin.db.identity_meta.get_new_devices(identity_id, jid.bare_jid.to_string()).count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(Conversation conversation, NotificationCollection notification_collection, Plugins.WidgetType type) {
|
public void init(Conversation conversation, NotificationCollection notification_collection, Plugins.WidgetType type) {
|
||||||
|
|
|
@ -203,12 +203,15 @@ public class Manager : StreamInteractionModule, Object {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int identity_id = db.identity.get_id(account.id);
|
||||||
|
if (identity_id < 0) return;
|
||||||
|
|
||||||
//Update meta database
|
//Update meta database
|
||||||
db.identity_meta.insert_device_list(account.id, jid.bare_jid.to_string(), device_list);
|
db.identity_meta.insert_device_list(identity_id, jid.bare_jid.to_string(), device_list);
|
||||||
|
|
||||||
//Fetch the bundle for each new device
|
//Fetch the bundle for each new device
|
||||||
int inc = 0;
|
int inc = 0;
|
||||||
foreach (Row row in db.identity_meta.get_unknown_devices(account.id, jid.bare_jid.to_string())) {
|
foreach (Row row in db.identity_meta.get_unknown_devices(identity_id, jid.bare_jid.to_string())) {
|
||||||
module.fetch_bundle(stream, Jid.parse(row[db.identity_meta.address_name]), row[db.identity_meta.device_id]);
|
module.fetch_bundle(stream, Jid.parse(row[db.identity_meta.address_name]), row[db.identity_meta.device_id]);
|
||||||
inc++;
|
inc++;
|
||||||
}
|
}
|
||||||
|
@ -217,8 +220,8 @@ public class Manager : StreamInteractionModule, Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create an entry for the jid in the account table if one does not exist already
|
//Create an entry for the jid in the account table if one does not exist already
|
||||||
if (db.trust.select().with(db.trust.identity_id, "=", account.id).with(db.trust.address_name, "=", jid.bare_jid.to_string()).count() == 0) {
|
if (db.trust.select().with(db.trust.identity_id, "=", identity_id).with(db.trust.address_name, "=", jid.bare_jid.to_string()).count() == 0) {
|
||||||
db.trust.insert().value(db.trust.identity_id, account.id).value(db.trust.address_name, jid.bare_jid.to_string()).value(db.trust.blind_trust, true).perform();
|
db.trust.insert().value(db.trust.identity_id, identity_id).value(db.trust.address_name, jid.bare_jid.to_string()).value(db.trust.blind_trust, true).perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get all messages that needed the devicelist and determine if we can now send them
|
//Get all messages that needed the devicelist and determine if we can now send them
|
||||||
|
@ -249,16 +252,19 @@ public class Manager : StreamInteractionModule, Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void on_bundle_fetched(Account account, Jid jid, int32 device_id, Bundle bundle) {
|
public void on_bundle_fetched(Account account, Jid jid, int32 device_id, Bundle bundle) {
|
||||||
bool blind_trust = db.trust.get_blind_trust(account.id, jid.bare_jid.to_string());
|
int identity_id = db.identity.get_id(account.id);
|
||||||
|
if (identity_id < 0) return;
|
||||||
|
|
||||||
|
bool blind_trust = db.trust.get_blind_trust(identity_id, jid.bare_jid.to_string());
|
||||||
|
|
||||||
//If we don't blindly trust new devices and we haven't seen this key before then don't trust it
|
//If we don't blindly trust new devices and we haven't seen this key before then don't trust it
|
||||||
bool untrust = !(blind_trust || db.identity_meta.with_address(account.id, jid.bare_jid.to_string())
|
bool untrust = !(blind_trust || db.identity_meta.with_address(identity_id, jid.bare_jid.to_string())
|
||||||
.with(db.identity_meta.device_id, "=", device_id)
|
.with(db.identity_meta.device_id, "=", device_id)
|
||||||
.with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize()))
|
.with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize()))
|
||||||
.single().row().is_present());
|
.single().row().is_present());
|
||||||
|
|
||||||
//Get trust information from the database if the device id is known
|
//Get trust information from the database if the device id is known
|
||||||
Row device = db.identity_meta.get_device(account.id, jid.bare_jid.to_string(), device_id);
|
Row device = db.identity_meta.get_device(identity_id, jid.bare_jid.to_string(), device_id);
|
||||||
Database.IdentityMetaTable.TrustLevel trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN;
|
Database.IdentityMetaTable.TrustLevel trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN;
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
trusted = (Database.IdentityMetaTable.TrustLevel) device[db.identity_meta.trust_level];
|
trusted = (Database.IdentityMetaTable.TrustLevel) device[db.identity_meta.trust_level];
|
||||||
|
@ -271,7 +277,7 @@ public class Manager : StreamInteractionModule, Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update the database with the appropriate trust information
|
//Update the database with the appropriate trust information
|
||||||
db.identity_meta.insert_device_bundle(account.id, jid.bare_jid.to_string(), device_id, bundle, trusted);
|
db.identity_meta.insert_device_bundle(identity_id, jid.bare_jid.to_string(), device_id, bundle, trusted);
|
||||||
|
|
||||||
XmppStream? stream = stream_interactor.get_stream(account);
|
XmppStream? stream = stream_interactor.get_stream(account);
|
||||||
if(stream == null) return;
|
if(stream == null) return;
|
||||||
|
|
|
@ -26,7 +26,10 @@ public class OwnNotifications {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool has_new_devices(Jid jid) {
|
public bool has_new_devices(Jid jid) {
|
||||||
return plugin.db.identity_meta.get_new_devices(account.id, jid.bare_jid.to_string()).count() > 0;
|
int identity_id = plugin.db.identity.get_id(account.id);
|
||||||
|
if (identity_id < 0) return false;
|
||||||
|
|
||||||
|
return plugin.db.identity_meta.get_new_devices(identity_id, jid.bare_jid.to_string()).count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void display_notification() {
|
private void display_notification() {
|
||||||
|
|
|
@ -21,15 +21,18 @@ public class TrustManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set_blind_trust(Account account, Jid jid, bool blind_trust) {
|
public void set_blind_trust(Account account, Jid jid, bool blind_trust) {
|
||||||
|
int identity_id = db.identity.get_id(account.id);
|
||||||
|
if (identity_id < 0) return;
|
||||||
db.trust.update()
|
db.trust.update()
|
||||||
.with(db.trust.identity_id, "=", account.id)
|
.with(db.trust.identity_id, "=", identity_id)
|
||||||
.with(db.trust.address_name, "=", jid.bare_jid.to_string())
|
.with(db.trust.address_name, "=", jid.bare_jid.to_string())
|
||||||
.set(db.trust.blind_trust, blind_trust).perform();
|
.set(db.trust.blind_trust, blind_trust).perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set_device_trust(Account account, Jid jid, int device_id, Database.IdentityMetaTable.TrustLevel trust_level) {
|
public void set_device_trust(Account account, Jid jid, int device_id, Database.IdentityMetaTable.TrustLevel trust_level) {
|
||||||
|
int identity_id = db.identity.get_id(account.id);
|
||||||
db.identity_meta.update()
|
db.identity_meta.update()
|
||||||
.with(db.identity_meta.identity_id, "=", account.id)
|
.with(db.identity_meta.identity_id, "=", identity_id)
|
||||||
.with(db.identity_meta.address_name, "=", jid.bare_jid.to_string())
|
.with(db.identity_meta.address_name, "=", jid.bare_jid.to_string())
|
||||||
.with(db.identity_meta.device_id, "=", device_id)
|
.with(db.identity_meta.device_id, "=", device_id)
|
||||||
.set(db.identity_meta.trust_level, trust_level).perform();
|
.set(db.identity_meta.trust_level, trust_level).perform();
|
||||||
|
@ -135,12 +138,16 @@ public class TrustManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool is_known_address(Account account, Jid jid) {
|
public bool is_known_address(Account account, Jid jid) {
|
||||||
return db.identity_meta.with_address(account.id, jid.to_string()).count() > 0;
|
int identity_id = db.identity.get_id(account.id);
|
||||||
|
if (identity_id < 0) return false;
|
||||||
|
return db.identity_meta.with_address(identity_id, jid.to_string()).count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gee.List<int32> get_trusted_devices(Account account, Jid jid) {
|
public Gee.List<int32> get_trusted_devices(Account account, Jid jid) {
|
||||||
Gee.List<int32> devices = new ArrayList<int32>();
|
Gee.List<int32> devices = new ArrayList<int32>();
|
||||||
foreach (Row device in db.identity_meta.get_trusted_devices(account.id, jid.bare_jid.to_string())) {
|
int identity_id = db.identity.get_id(account.id);
|
||||||
|
if (identity_id < 0) return devices;
|
||||||
|
foreach (Row device in db.identity_meta.get_trusted_devices(identity_id, jid.bare_jid.to_string())) {
|
||||||
if(device[db.identity_meta.trust_level] != Database.IdentityMetaTable.TrustLevel.UNKNOWN || device[db.identity_meta.identity_key_public_base64] == null)
|
if(device[db.identity_meta.trust_level] != Database.IdentityMetaTable.TrustLevel.UNKNOWN || device[db.identity_meta.identity_key_public_base64] == null)
|
||||||
devices.add(device[db.identity_meta.device_id]);
|
devices.add(device[db.identity_meta.device_id]);
|
||||||
}
|
}
|
||||||
|
@ -163,12 +170,14 @@ public class TrustManager {
|
||||||
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
|
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
|
||||||
MessageFlag? flag = MessageFlag.get_flag(stanza);
|
MessageFlag? flag = MessageFlag.get_flag(stanza);
|
||||||
if(flag != null && ((!)flag).decrypted) {
|
if(flag != null && ((!)flag).decrypted) {
|
||||||
|
int identity_id = db.identity.get_id(conversation.account.id);
|
||||||
|
if (identity_id < 0) return false;
|
||||||
StanzaNode header = stanza.stanza.get_subnode("encrypted", "eu.siacs.conversations.axolotl").get_subnode("header");
|
StanzaNode header = stanza.stanza.get_subnode("encrypted", "eu.siacs.conversations.axolotl").get_subnode("header");
|
||||||
Jid jid = message.from;
|
Jid jid = message.from;
|
||||||
if(conversation.type_ == Conversation.Type.GROUPCHAT) {
|
if(conversation.type_ == Conversation.Type.GROUPCHAT) {
|
||||||
jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(jid, conversation.account);
|
jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(jid, conversation.account);
|
||||||
}
|
}
|
||||||
Database.IdentityMetaTable.TrustLevel trust_level = (Database.IdentityMetaTable.TrustLevel) db.identity_meta.get_device(conversation.account.id, jid.bare_jid.to_string(), header.get_attribute_int("sid"))[db.identity_meta.trust_level];
|
Database.IdentityMetaTable.TrustLevel trust_level = (Database.IdentityMetaTable.TrustLevel) db.identity_meta.get_device(identity_id, jid.bare_jid.to_string(), header.get_attribute_int("sid"))[db.identity_meta.trust_level];
|
||||||
if (trust_level == Database.IdentityMetaTable.TrustLevel.UNTRUSTED) {
|
if (trust_level == Database.IdentityMetaTable.TrustLevel.UNTRUSTED) {
|
||||||
message.body = _("OMEMO message from a rejected device");
|
message.body = _("OMEMO message from a rejected device");
|
||||||
message.marked = Message.Marked.WONTSEND;
|
message.marked = Message.Marked.WONTSEND;
|
||||||
|
|
Loading…
Reference in a new issue