2017-03-11 00:29:38 +00:00
|
|
|
using Dino.Entities;
|
|
|
|
using Signal;
|
|
|
|
using Qlite;
|
|
|
|
using Xmpp;
|
|
|
|
using Gee;
|
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
namespace Dino.Plugins.Omemo {
|
2017-03-11 00:29:38 +00:00
|
|
|
|
|
|
|
public class Manager : StreamInteractionModule, Object {
|
2017-03-19 11:55:36 +00:00
|
|
|
public static ModuleIdentity<Manager> IDENTITY = new ModuleIdentity<Manager>("omemo_manager");
|
|
|
|
public string id { get { return IDENTITY.id; } }
|
2017-03-11 00:29:38 +00:00
|
|
|
|
|
|
|
private StreamInteractor stream_interactor;
|
|
|
|
private Database db;
|
2018-07-25 20:27:26 +00:00
|
|
|
private TrustManager trust_manager;
|
2017-03-15 16:23:13 +00:00
|
|
|
private Map<Entities.Message, MessageState> message_states = new HashMap<Entities.Message, MessageState>(Entities.Message.hash_func, Entities.Message.equals_func);
|
2018-01-19 21:37:02 +00:00
|
|
|
private ReceivedMessageListener received_message_listener = new ReceivedMessageListener();
|
2017-03-15 16:23:13 +00:00
|
|
|
|
|
|
|
private class MessageState {
|
|
|
|
public Entities.Message msg { get; private set; }
|
|
|
|
public EncryptState last_try { get; private set; }
|
|
|
|
public int waiting_other_sessions { get; set; }
|
|
|
|
public int waiting_own_sessions { get; set; }
|
|
|
|
public bool waiting_own_devicelist { get; set; }
|
2018-07-11 17:17:57 +00:00
|
|
|
public int waiting_other_devicelists { get; set; }
|
2017-03-15 16:23:13 +00:00
|
|
|
public bool force_next_attempt { get; set; }
|
|
|
|
public bool will_send_now { get; private set; }
|
|
|
|
public bool active_send_attempt { get; set; }
|
|
|
|
|
|
|
|
public MessageState(Entities.Message msg, EncryptState last_try) {
|
|
|
|
this.msg = msg;
|
|
|
|
this.last_try = last_try;
|
|
|
|
update_from_encrypt_status(last_try);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void update_from_encrypt_status(EncryptState new_try) {
|
|
|
|
this.last_try = new_try;
|
|
|
|
this.waiting_other_sessions = new_try.other_unknown;
|
|
|
|
this.waiting_own_sessions = new_try.own_unknown;
|
|
|
|
this.waiting_own_devicelist = !new_try.own_list;
|
2018-07-11 17:17:57 +00:00
|
|
|
this.waiting_other_devicelists = new_try.other_waiting_lists;
|
2017-03-15 16:23:13 +00:00
|
|
|
this.active_send_attempt = false;
|
|
|
|
will_send_now = false;
|
|
|
|
if (new_try.other_failure > 0 || (new_try.other_lost == new_try.other_devices && new_try.other_devices > 0)) {
|
|
|
|
msg.marked = Entities.Message.Marked.WONTSEND;
|
2018-07-11 17:17:57 +00:00
|
|
|
} else if (new_try.other_unknown > 0 || new_try.own_unknown > 0 || new_try.other_waiting_lists > 0 || !new_try.own_list || new_try.own_devices == 0) {
|
2017-03-15 16:23:13 +00:00
|
|
|
msg.marked = Entities.Message.Marked.UNSENT;
|
|
|
|
} else if (!new_try.encrypted) {
|
|
|
|
msg.marked = Entities.Message.Marked.WONTSEND;
|
|
|
|
} else {
|
|
|
|
will_send_now = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool should_retry_now() {
|
2018-07-11 17:17:57 +00:00
|
|
|
return !waiting_own_devicelist && waiting_other_devicelists <= 0 && waiting_other_sessions <= 0 && waiting_own_sessions <= 0 && !active_send_attempt;
|
2017-03-15 16:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string to_string() {
|
2018-07-11 17:17:57 +00:00
|
|
|
return @"MessageState (waiting=(others=$waiting_other_sessions, own=$waiting_own_sessions, other_lists=$waiting_other_devicelists, own_list=$waiting_own_devicelist))";
|
2017-03-15 16:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-11 00:29:38 +00:00
|
|
|
|
|
|
|
private Manager(StreamInteractor stream_interactor, Database db) {
|
|
|
|
this.stream_interactor = stream_interactor;
|
|
|
|
this.db = db;
|
|
|
|
|
2018-07-25 20:27:26 +00:00
|
|
|
this.trust_manager = new TrustManager(stream_interactor, db);
|
|
|
|
|
2017-03-13 20:54:12 +00:00
|
|
|
stream_interactor.stream_negotiated.connect(on_stream_negotiated);
|
2017-03-11 00:29:38 +00:00
|
|
|
stream_interactor.account_added.connect(on_account_added);
|
2018-01-19 21:37:02 +00:00
|
|
|
stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(received_message_listener);
|
2017-04-04 13:47:00 +00:00
|
|
|
stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(on_pre_message_send);
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 21:37:02 +00:00
|
|
|
private class ReceivedMessageListener : MessageListener {
|
|
|
|
|
2018-01-30 16:29:54 +00:00
|
|
|
public string[] after_actions_const = new string[]{ };
|
2018-01-19 21:37:02 +00:00
|
|
|
public override string action_group { get { return "DECRYPT"; } }
|
|
|
|
public override string[] after_actions { get { return after_actions_const; } }
|
|
|
|
|
|
|
|
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
|
|
|
|
MessageFlag? flag = MessageFlag.get_flag(stanza);
|
|
|
|
if (flag != null && ((!)flag).decrypted) {
|
|
|
|
message.encryption = Encryption.OMEMO;
|
|
|
|
}
|
|
|
|
return false;
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:27:26 +00:00
|
|
|
private Gee.List<Jid> get_occupants(Jid jid, Account account){
|
2018-07-11 17:17:57 +00:00
|
|
|
Gee.List<Jid> occupants = new ArrayList<Jid>(Jid.equals_bare_func);
|
2018-07-25 20:27:26 +00:00
|
|
|
if(!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid, account)){
|
|
|
|
occupants.add(jid);
|
|
|
|
}
|
|
|
|
Gee.List<Jid>? occupant_jids = stream_interactor.get_module(MucManager.IDENTITY).get_offline_members(jid, account);
|
2018-07-11 17:17:57 +00:00
|
|
|
if(occupant_jids == null) {
|
|
|
|
return occupants;
|
|
|
|
}
|
|
|
|
foreach (Jid occupant in occupant_jids) {
|
2018-07-17 18:57:42 +00:00
|
|
|
if(!occupant.equals(account.bare_jid)){
|
|
|
|
occupants.add(occupant.bare_jid);
|
2018-07-11 17:17:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return occupants;
|
|
|
|
}
|
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
private void on_pre_message_send(Entities.Message message, Xmpp.MessageStanza message_stanza, Conversation conversation) {
|
2017-03-11 00:29:38 +00:00
|
|
|
if (message.encryption == Encryption.OMEMO) {
|
2018-01-12 20:03:09 +00:00
|
|
|
XmppStream? stream = stream_interactor.get_stream(conversation.account);
|
2017-04-18 15:55:20 +00:00
|
|
|
if (stream == null) {
|
|
|
|
message.marked = Entities.Message.Marked.UNSENT;
|
|
|
|
return;
|
|
|
|
}
|
2017-05-13 15:48:13 +00:00
|
|
|
StreamModule? module_ = ((!)stream).get_module(StreamModule.IDENTITY);
|
|
|
|
if (module_ == null) {
|
|
|
|
message.marked = Entities.Message.Marked.UNSENT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StreamModule module = (!)module_;
|
2018-07-09 13:16:23 +00:00
|
|
|
|
2018-07-11 17:17:57 +00:00
|
|
|
Gee.List<Jid> recipients;
|
|
|
|
if (message_stanza.type_ == MessageStanza.TYPE_GROUPCHAT) {
|
|
|
|
recipients = get_occupants((!)message.to.bare_jid, conversation.account);
|
|
|
|
if (recipients.size == 0) {
|
|
|
|
message.marked = Entities.Message.Marked.WONTSEND;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
recipients = new ArrayList<Jid>(Jid.equals_bare_func);
|
|
|
|
recipients.add(message_stanza.to);
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:27:26 +00:00
|
|
|
EncryptState enc_state = trust_manager.encrypt(message_stanza, conversation.account.bare_jid, recipients, stream, conversation.account);
|
2017-04-18 15:55:20 +00:00
|
|
|
MessageState state;
|
2017-03-15 16:23:13 +00:00
|
|
|
lock (message_states) {
|
|
|
|
if (message_states.has_key(message)) {
|
|
|
|
state = message_states.get(message);
|
|
|
|
state.update_from_encrypt_status(enc_state);
|
|
|
|
} else {
|
|
|
|
state = new MessageState(message, enc_state);
|
|
|
|
message_states[message] = state;
|
|
|
|
}
|
|
|
|
if (state.will_send_now) {
|
|
|
|
message_states.unset(message);
|
|
|
|
}
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 16:23:13 +00:00
|
|
|
if (!state.will_send_now) {
|
|
|
|
if (message.marked == Entities.Message.Marked.WONTSEND) {
|
2017-04-18 15:55:20 +00:00
|
|
|
if (Plugin.DEBUG) print(@"OMEMO: message was not sent: $state\n");
|
2018-06-11 06:11:04 +00:00
|
|
|
message_states.unset(message);
|
2017-03-15 16:23:13 +00:00
|
|
|
} else {
|
2017-04-18 15:55:20 +00:00
|
|
|
if (Plugin.DEBUG) print(@"OMEMO: message will be delayed: $state\n");
|
2017-03-15 16:23:13 +00:00
|
|
|
|
|
|
|
if (state.waiting_own_sessions > 0) {
|
2018-07-25 20:27:26 +00:00
|
|
|
module.fetch_bundles((!)stream, conversation.account.bare_jid, trust_manager.get_trusted_devices(conversation.account, conversation.account.bare_jid));
|
2017-03-15 16:23:13 +00:00
|
|
|
}
|
2017-04-18 15:55:20 +00:00
|
|
|
if (state.waiting_other_sessions > 0 && message.counterpart != null) {
|
2018-07-25 20:27:26 +00:00
|
|
|
foreach(Jid jid in get_occupants(((!)message.counterpart).bare_jid, conversation.account)) {
|
|
|
|
module.fetch_bundles((!)stream, jid, trust_manager.get_trusted_devices(conversation.account, jid));
|
|
|
|
}
|
2017-03-15 16:23:13 +00:00
|
|
|
}
|
2018-07-11 17:17:57 +00:00
|
|
|
if (state.waiting_other_devicelists > 0 && message.counterpart != null) {
|
2018-07-25 20:27:26 +00:00
|
|
|
foreach(Jid jid in get_occupants(((!)message.counterpart).bare_jid, conversation.account)) {
|
|
|
|
module.request_user_devicelist((!)stream, jid);
|
|
|
|
}
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void on_account_added(Account account) {
|
2017-03-12 01:28:23 +00:00
|
|
|
stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).store_created.connect((store) => on_store_created(account, store));
|
2018-07-25 20:27:26 +00:00
|
|
|
stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).device_list_loaded.connect((jid, devices) => on_device_list_loaded(account, jid, devices));
|
2017-05-13 15:48:13 +00:00
|
|
|
stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).bundle_fetched.connect((jid, device_id, bundle) => on_bundle_fetched(account, jid, device_id, bundle));
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
private void on_stream_negotiated(Account account, XmppStream stream) {
|
|
|
|
stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).request_user_devicelist(stream, account.bare_jid);
|
2017-03-13 20:54:12 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:27:26 +00:00
|
|
|
private void on_device_list_loaded(Account account, Jid jid, ArrayList<int32> device_list) {
|
2017-03-15 16:23:13 +00:00
|
|
|
if (Plugin.DEBUG) print(@"OMEMO: received device list for $(account.bare_jid) from $jid\n");
|
2017-05-13 15:48:13 +00:00
|
|
|
|
|
|
|
// Update meta database
|
2018-01-12 20:03:09 +00:00
|
|
|
XmppStream? stream = stream_interactor.get_stream(account);
|
2017-05-13 15:48:13 +00:00
|
|
|
if (stream == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StreamModule? module = ((!)stream).get_module(StreamModule.IDENTITY);
|
|
|
|
if (module == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-11 17:17:57 +00:00
|
|
|
|
2018-06-11 06:11:04 +00:00
|
|
|
db.identity_meta.insert_device_list(account.id, jid.bare_jid.to_string(), device_list);
|
2017-10-28 21:48:07 +00:00
|
|
|
int inc = 0;
|
2018-06-19 10:52:00 +00:00
|
|
|
foreach (Row row in db.identity_meta.with_address(account.id, jid.bare_jid.to_string()).with_null(db.identity_meta.identity_key_public_base64)) {
|
2018-01-12 20:03:09 +00:00
|
|
|
module.fetch_bundle(stream, Jid.parse(row[db.identity_meta.address_name]), row[db.identity_meta.device_id]);
|
2017-10-28 21:48:07 +00:00
|
|
|
inc++;
|
|
|
|
}
|
|
|
|
if (inc > 0) {
|
|
|
|
if (Plugin.DEBUG) print(@"OMEMO: new bundles $inc/$(device_list.size) for $jid\n");
|
2017-05-13 15:48:13 +00:00
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-06-19 10:52:00 +00:00
|
|
|
if (db.trust.select().with(db.trust.identity_id, "=", account.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();
|
|
|
|
}
|
2018-07-25 20:27:26 +00:00
|
|
|
|
|
|
|
HashSet<Entities.Message> send_now = new HashSet<Entities.Message>();
|
|
|
|
lock (message_states) {
|
|
|
|
foreach (Entities.Message msg in message_states.keys) {
|
|
|
|
if (!msg.account.equals(account)) continue;
|
|
|
|
Gee.List<Jid> occupants = get_occupants(msg.counterpart.bare_jid, account);
|
|
|
|
MessageState state = message_states[msg];
|
|
|
|
if (account.bare_jid.equals(jid)) {
|
|
|
|
state.waiting_own_devicelist = false;
|
|
|
|
} else if (msg.counterpart != null && occupants.contains(jid)) {
|
|
|
|
state.waiting_other_devicelists--;
|
|
|
|
}
|
|
|
|
if (state.should_retry_now()) {
|
|
|
|
send_now.add(msg);
|
|
|
|
state.active_send_attempt = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (Entities.Message msg in send_now) {
|
|
|
|
if (msg.counterpart == null) continue;
|
|
|
|
Entities.Conversation? conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(((!)msg.counterpart), account);
|
|
|
|
if (conv == null) continue;
|
|
|
|
stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(msg, (!)conv, true);
|
|
|
|
}
|
|
|
|
|
2017-05-13 15:48:13 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
public void on_bundle_fetched(Account account, Jid jid, int32 device_id, Bundle bundle) {
|
2018-06-11 06:11:04 +00:00
|
|
|
bool blind_trust = db.trust.get_blind_trust(account.id, jid.bare_jid.to_string());
|
|
|
|
|
2018-06-19 10:52:00 +00:00
|
|
|
bool untrust = !(blind_trust || db.identity_meta.with_address(account.id, jid.bare_jid.to_string())
|
2018-06-11 06:11:04 +00:00
|
|
|
.with(db.identity_meta.device_id, "=", device_id)
|
|
|
|
.with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize()))
|
2018-06-19 10:52:00 +00:00
|
|
|
.single().row().is_present());
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-07-06 19:14:51 +00:00
|
|
|
Database.IdentityMetaTable.TrustLevel trusted = (Database.IdentityMetaTable.TrustLevel) db.identity_meta.with_address(account.id, jid.bare_jid.to_string()).with(db.identity_meta.device_id, "=", device_id).single()[db.identity_meta.trust_level, Database.IdentityMetaTable.TrustLevel.UNKNOWN];
|
2018-06-19 10:52:00 +00:00
|
|
|
|
|
|
|
if(untrust) {
|
2018-06-19 10:26:31 +00:00
|
|
|
trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN;
|
2018-06-19 10:52:00 +00:00
|
|
|
} else if (blind_trust && trusted == Database.IdentityMetaTable.TrustLevel.UNKNOWN) {
|
2018-06-19 10:26:31 +00:00
|
|
|
trusted = Database.IdentityMetaTable.TrustLevel.TRUSTED;
|
2018-06-19 10:52:00 +00:00
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
|
|
|
|
db.identity_meta.insert_device_bundle(account.id, jid.bare_jid.to_string(), device_id, bundle, trusted);
|
|
|
|
|
|
|
|
XmppStream? stream = stream_interactor.get_stream(account);
|
|
|
|
if(stream == null) return;
|
|
|
|
StreamModule? module = ((!)stream).get_module(StreamModule.IDENTITY);
|
|
|
|
if(module == null) return;
|
|
|
|
|
|
|
|
HashSet<Entities.Message> send_now = new HashSet<Entities.Message>();
|
|
|
|
lock (message_states) {
|
|
|
|
foreach (Entities.Message msg in message_states.keys) {
|
2018-07-11 17:17:57 +00:00
|
|
|
|
2018-06-11 06:11:04 +00:00
|
|
|
bool session_created = true;
|
|
|
|
if (!msg.account.equals(account)) continue;
|
2018-07-11 17:17:57 +00:00
|
|
|
Gee.List<Jid> occupants = get_occupants(msg.counterpart.bare_jid, account);
|
|
|
|
|
2018-06-11 06:11:04 +00:00
|
|
|
MessageState state = message_states[msg];
|
|
|
|
|
2018-07-25 20:27:26 +00:00
|
|
|
if (trusted == Database.IdentityMetaTable.TrustLevel.TRUSTED || trusted == Database.IdentityMetaTable.TrustLevel.VERIFIED) {
|
2018-07-11 17:17:57 +00:00
|
|
|
if(account.bare_jid.equals(jid) || (msg.counterpart != null && (msg.counterpart.equals_bare(jid) || occupants.contains(jid)))) {
|
2018-06-19 10:26:31 +00:00
|
|
|
session_created = module.start_session(stream, jid, device_id, bundle);
|
2018-06-19 10:52:00 +00:00
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
}
|
|
|
|
if (account.bare_jid.equals(jid) && session_created) {
|
|
|
|
state.waiting_own_sessions--;
|
2018-07-11 17:17:57 +00:00
|
|
|
} else if (msg.counterpart != null && (msg.counterpart.equals_bare(jid) || occupants.contains(jid)) && session_created) {
|
2018-06-11 06:11:04 +00:00
|
|
|
state.waiting_other_sessions--;
|
|
|
|
}
|
|
|
|
if (state.should_retry_now()){
|
|
|
|
send_now.add(msg);
|
|
|
|
state.active_send_attempt = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (Entities.Message msg in send_now) {
|
|
|
|
if (msg.counterpart == null) continue;
|
|
|
|
Entities.Conversation? conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation((!)msg.counterpart, account);
|
|
|
|
if (conv == null) continue;
|
|
|
|
stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(msg, (!)conv, true);
|
|
|
|
}
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
private void on_store_created(Account account, Store store) {
|
2017-10-28 21:48:07 +00:00
|
|
|
Qlite.Row? row = db.identity.row_with(db.identity.account_id, account.id).inner;
|
2017-03-11 00:29:38 +00:00
|
|
|
int identity_id = -1;
|
|
|
|
|
|
|
|
if (row == null) {
|
|
|
|
// OMEMO not yet initialized, starting with empty base
|
2017-03-12 01:28:23 +00:00
|
|
|
try {
|
|
|
|
store.identity_key_store.local_registration_id = Random.int_range(1, int32.MAX);
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-04-18 15:55:20 +00:00
|
|
|
Signal.ECKeyPair key_pair = Plugin.get_context().generate_key_pair();
|
2017-03-12 01:28:23 +00:00
|
|
|
store.identity_key_store.identity_key_private = key_pair.private.serialize();
|
|
|
|
store.identity_key_store.identity_key_public = key_pair.public.serialize();
|
2017-03-11 00:29:38 +00:00
|
|
|
|
|
|
|
identity_id = (int) db.identity.insert().or("REPLACE")
|
2017-03-12 01:28:23 +00:00
|
|
|
.value(db.identity.account_id, account.id)
|
|
|
|
.value(db.identity.device_id, (int) store.local_registration_id)
|
|
|
|
.value(db.identity.identity_key_private_base64, Base64.encode(store.identity_key_store.identity_key_private))
|
|
|
|
.value(db.identity.identity_key_public_base64, Base64.encode(store.identity_key_store.identity_key_public))
|
|
|
|
.perform();
|
2017-03-11 00:29:38 +00:00
|
|
|
} catch (Error e) {
|
|
|
|
// Ignore error
|
|
|
|
}
|
|
|
|
} else {
|
2017-04-18 15:55:20 +00:00
|
|
|
store.identity_key_store.local_registration_id = ((!)row)[db.identity.device_id];
|
|
|
|
store.identity_key_store.identity_key_private = Base64.decode(((!)row)[db.identity.identity_key_private_base64]);
|
|
|
|
store.identity_key_store.identity_key_public = Base64.decode(((!)row)[db.identity.identity_key_public_base64]);
|
|
|
|
identity_id = ((!)row)[db.identity.id];
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (identity_id >= 0) {
|
|
|
|
store.signed_pre_key_store = new BackedSignedPreKeyStore(db, identity_id);
|
|
|
|
store.pre_key_store = new BackedPreKeyStore(db, identity_id);
|
|
|
|
store.session_store = new BackedSessionStore(db, identity_id);
|
|
|
|
} else {
|
2017-03-15 16:23:13 +00:00
|
|
|
print(@"OMEMO: store for $(account.bare_jid) is not persisted!");
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
public bool can_encrypt(Entities.Conversation conversation) {
|
2018-01-12 20:03:09 +00:00
|
|
|
XmppStream? stream = stream_interactor.get_stream(conversation.account);
|
2017-03-15 16:23:13 +00:00
|
|
|
if (stream == null) return false;
|
2017-04-18 15:55:20 +00:00
|
|
|
StreamModule? module = ((!)stream).get_module(StreamModule.IDENTITY);
|
|
|
|
if (module == null) return false;
|
2018-07-17 18:47:07 +00:00
|
|
|
if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(conversation.counterpart, conversation.account)){
|
|
|
|
Xep.Muc.Flag? flag = stream.get_flag(Xep.Muc.Flag.IDENTITY);
|
|
|
|
if (flag == null) return false;
|
2018-07-18 20:42:33 +00:00
|
|
|
if (flag.has_room_feature(conversation.counterpart, Xep.Muc.Feature.NON_ANONYMOUS) && flag.has_room_feature(conversation.counterpart, Xep.Muc.Feature.MEMBERS_ONLY)) {
|
2018-07-17 18:47:07 +00:00
|
|
|
foreach(Jid jid in stream_interactor.get_module(MucManager.IDENTITY).get_offline_members(conversation.counterpart, conversation.account)) {
|
2018-07-28 18:03:52 +00:00
|
|
|
if (!trust_manager.is_known_address(conversation.account, jid.bare_jid)) {
|
|
|
|
module.request_user_devicelist(stream, jid.bare_jid);
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-17 18:47:07 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-28 18:03:52 +00:00
|
|
|
} else if (!trust_manager.is_known_address(conversation.account, conversation.counterpart.bare_jid)) {
|
|
|
|
module.request_user_devicelist(stream, conversation.counterpart.bare_jid);
|
|
|
|
return false;
|
2018-07-17 18:47:07 +00:00
|
|
|
}
|
2018-07-28 18:03:52 +00:00
|
|
|
return true;
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void start(StreamInteractor stream_interactor, Database db) {
|
|
|
|
Manager m = new Manager(stream_interactor, db);
|
|
|
|
stream_interactor.add_module(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-28 21:48:07 +00:00
|
|
|
}
|