Commit graph libervia-backend/sat/memory
Author SHA1 Message Date
Goffi
bef19967d5 core (memory/params): new "makeOptions" method to easily create options XML from a dict 2020-01-03 13:20:45 +01:00
Goffi
b5af781b82 plugin XEP-0384: OMEMO for MUC implementation:
- encryption is now allowed for group chats
- when an encryption is requested for a MUC, real jids or all occupants are used to
  encrypt the message
- a cache for plain text message sent to MUC is used, because for security reason we can't
  encrypt message for our own device with OMEMO (that would prevent ratchet and break the
  prefect forward secrecy). Thus, message sent in MUC are cached for 5 min, and the
  decrypted version is used when found. We don't send immediately the plain text message
  to frontends and history because we want to keep the same MUC behaviour as for plain
  text, and receiving a message means that it was received and sent back by MUC service
- <origin-id> is used to identify messages sent by our device
- a feedback_jid is now use to use correct entity for feedback message in case of problem:
  with a room we have to send feedback message to the room and not the the emitter
- encryptMessage now only accepts list in the renamed "entity_bare_jids" argument
2019-12-30 20:59:46 +01:00
Goffi
3ccd27de87 core (memory/sqlite): added before_uid filter to retrieve history before a message UID 2019-12-05 22:58:06 +01:00
Goffi
f7aad247c2 misc: don't import memory in launch script:
launch script was importing a method from memory (fixLocalDir), but memory is importing
twisted.internet.reactor which can result to a ReactorAlreadyInstalledError.

This patch fixes it by moving fixLocalDir to tools/config.

The launch script is now using /usr/bin/env.
2019-10-08 12:10:26 +02:00
Goffi
76aadbb3fb jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\

This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).

During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
2019-09-25 08:56:41 +02:00
Goffi
b039dc4572 tools (config), memory: renamed SafeConfigParser following Python 3 port 2019-08-16 17:06:43 +02:00
Goffi
fbfe96c505 Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time

This patch port backend, bridge and frontends to Python 3.

Roughly this has been done this way:

- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
  to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
2019-08-13 19:08:41 +02:00
Goffi
9487b0534b plugin ad-hoc D-Bus: fixed warning when no media player is found 2019-07-19 17:07:56 +02:00
Goffi
420bc6bcfe memory (sqlite): properly wait for messages to be writen in database:
the deferreds of the queries writing message to databases where not gathered and returned,
so the caller was not waiting for them to continue its workflow. This was resulting in
messages not always written when database was read just after the write (a case common
with MUC implementation), and message was appearing empty when sent to bridge.

fix 328
2019-07-18 21:58:34 +02:00
Goffi
72c91471c1 memory (disco): fixed boolean to string conversion 2019-07-18 20:26:49 +02:00
Goffi
5e43c6c98c core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
an old hardcoded value was used in several places to detect if an entity is a MUC, but this
value was not valid anymore. This has been fixed, and ENTITY_TYPE_MUC constant is now used
instead. This fixes message type autodetection for "groupchat" messages.

fixes 300
2019-07-09 09:06:45 +02:00
Goffi
59faac55fe memory (sqlite): fixed order for last_stanza_id:
"last_stanza_id" filter was ordered by "received_timestamp" instead of "timestamp", resulting in wrong message being used (and a bad MAM request).
2019-07-06 15:50:55 +02:00
Goffi
c05c65b1b3 memory (sqlite): exit with an error if current db version is higher than version expected in current code 2019-06-21 12:59:36 +02:00
Goffi
80da9a6591 core (memory, memory/sqlite): implemented fileDelete 2019-04-28 08:55:13 +02:00
Goffi
cad0d4b0e2 core (memory): raise PermissionError directly instead of using failureFailure, as it could not be catched correctly in every case. 2019-04-28 08:55:13 +02:00
Goffi
a46dda1e12 memory: minor style change 2019-04-26 11:57:26 +02:00
Goffi
98098105e7 memory (sqlite): minor log improvment 2019-04-26 11:57:26 +02:00
Goffi
621c6b3ffa memory (sqlite): fixed fileUpdate when original value is not set (NULL) 2019-04-26 11:57:26 +02:00
Goffi
5e2426c065 core (memory), plugin XEP-0329, plugin invitation: minor style improvments 2019-04-14 08:21:51 +02:00
Goffi
4701027950 memory (sqlite): cast timestamp_start filter to float instead of int 2019-04-07 20:57:13 +02:00
Goffi
8adba38036 core (memory/persistent): added clear method + initialise with a dict:
A "clear" method has been added to delete all data for a specific namespace (and profile).
Internal cache (self._cache) is not initialised with an empty dict instead of None to allow using methods like __setitem__ or clear without having to do a potentially expansive `load()` before. The only counterpart is that we won't have an exception anymore if developer forget to load() data before using them, which can make debugging a bit more difficult.
2019-04-07 18:44:57 +02:00
Goffi
aac5e58ec6 core (memory/sqlite): display arguments in logs in case of too many db/interaction tries 2019-04-07 18:38:18 +02:00
Goffi
8830a7c1d5 core (memory/sqlite): added a "timestamp_start" filter to retrieve history from a specific point in time 2019-03-09 16:24:15 +01:00
Goffi
8ae596600d core (disco): added missing disco extensions when generating the cap hash. 2019-03-01 19:28:11 +01:00
Goffi
d8f6620d00 core: added a base menu allowing to set encryption session or show the trust management UI. 2019-02-24 14:11:08 +01:00
Goffi
d159b9fb49 memory (sqlite): optimizations
indexes were missing on foreign keys for "message", "subject" and "thread" tables, seriously impacting performances.
In addition to those indexes, two indexes have been added to speed ordering by timestamp on "history", and one on "files" table.
history.rowid is not used anymore as there is an index on (profile_id, received_timestamp) which will speed up the query.
Primary keys order has been changed to use automatic index in most common cases (filtering by profile_id then namespace).
2019-01-19 22:49:32 +01:00
Goffi
8e338bf913 date update 2019-01-12 12:25:31 +01:00
Goffi
180b4790bf core (disco): client.disco.requestInfo failure are re-raised:
so far, requestInfo failure where logged as a warning, and an empty disco was returned.
This prevented the requesting entity to know about the error, so now the error is logged and re-raised.
CancelError are converted to TimeoutError (requestInfo is only cancelled on timeout).
An empty disco is still cached in case of failure, to avoid re-waiting for the entity on next request.
2019-01-11 19:48:20 +01:00
Goffi
7a9ee35cfc misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext) 2019-01-11 11:13:15 +01:00
Goffi
02dc38762e core (constants): added a constant for "encrypted" 2019-01-04 18:46:02 +01:00
Goffi
9ad238b884 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces 2019-01-04 11:14:17 +01:00
Goffi
ccfdb695bc memory (sqlite): minor comment move 2019-01-04 09:26:57 +01:00
Goffi
610e88841a memory (sqlite): retry _runInteraction in the same way as for _runQuery, this improve reliability 2019-01-04 09:21:16 +01:00
Goffi
09020b7108 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
- messageEncryptionStart and messageEncryptionStop are now async
- an encryption plugin can now have a startEncryption and endEncryption method, which are called automatically when suitable
- trust is now put in "trusted" key of message_data, and markAsTrusted has been added, it is used in OTR
- getTrustUI implemented for OTR, using legacy authenticate code
- catch potr.crypt.InvalidParameterError on decryption
- fixed some service OTR messages which were not correctly marked as not for storing, and thus were added to MAM archive/carbon copied
- other bug fixes
2019-01-03 21:00:00 +01:00
Goffi
6e38be1dab core (memory/sqlite): new delPrivateNamespace method to delete all data of a specific namespace for a profile. 2019-01-02 18:25:55 +01:00
Goffi
c87e9a23e3 core (memory/persistent): new LazyPersistentBinaryDict.remove method 2019-01-02 18:24:14 +01:00
Goffi
24468a9138 core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
- encryptionNamespaceGet retrieves algorithm namespace from its short name
- encryptionTrustUIGet retrieves trust mangement XMLUI from encryption plugin
- new markAsUntrusted internal helper method, to add untrusted flag to message data
2019-01-02 18:22:30 +01:00
Goffi
0e70587857 core (memory/sqlite): further improvments in update_v7:
- "info" messages deletion is now done by deactivating foreign keys. This seriously boost performances.
- "VACUUM" is done at the end to reduce database size.
2018-12-12 00:53:14 +01:00
Goffi
82d16029b8 core (memory/sqlite): fixed v7 update performance issue:
Performance issue was due to bad ordering in table dropping, this has been fixed.
"infos" message are also deleted by this update as they are containing only presence data and take a lot of space for a barely useful data.
A config option may be available in the future to store presence data in logs.
2018-12-11 23:53:27 +01:00
Goffi
51bc3411ba core (memory/sqlite): do not call commitStatements if there is nothing to commit in checkUpdates 2018-12-10 21:06:20 +01:00
Goffi
c2d7c3e69e core (memory/sqlite): changed history constraint
/!\ Database schema change /!\
History was using a unique constraint on `profile_id, timestamp, source, dest, source_res, dest_res`, which can cause trouble because several messages send quickly by the same person can have a common timestamp (specially with delayed messages where precision is second), resulting in message loss.
The new constraint use `profile_id, stanza_id, source, dest` where `stanza_id` is XEP-0359 stanza_id, so it's unique by definition, and no message should be lost anymore.
Because sqlite doesn't support altering table with a constraint change, we have to create new tables and copy old data to new one, which can be pretty long.
Sqlite update mechanism with "specifics" has been fixed when several updates are applied (e.g. moving from v5 to v7) and a specific is in the workflow.
2018-12-09 14:07:26 +01:00
Goffi
35e15c664c plugin XEP-0045: MAM implementation for MUC 2018-12-07 19:13:28 +01:00
Goffi
13cfba0f8a core (memory/disco): normalise booleans in extensions 2018-12-01 14:40:32 +01:00
Goffi
a245e32391 core (memory/sqlite): skip a line before debug log showing statements 2018-12-01 14:39:35 +01:00
Goffi
0b8e750956 core (memory/sqlite): added stanza_id:
/!\ database schema change /!\
stanza_id is a new field in history added to prepare the implementation of MAM for messages.
A new "last_stanza_id" can be used in filters to retrieve last message with a know stanza id (useful for history synchronisation).
2018-12-01 10:08:17 +01:00
Goffi
a29893ac1f core: minor style/typos fixes 2018-12-01 10:04:17 +01:00
Goffi
1b8345f4af core (xmpp): server certificate validation:
XMPP server certificate is now checked, and connection is refused (by default) if it's not valid.
Certificate check can be disabled in the new parameter "Configuration/check_certificate".
If certificate checking is disabled, a warning note is sent on every new connection.
Twisted and Wokkel are temporarly monkey patched in sat.core.tls_patches module, until modifications are merged upstream.
2018-11-10 10:16:35 +01:00
Goffi
e4bda681b8 core (memore/encryption): new methods and checks:
Following methods are now available though bridge:
    - messageEncryptionStop
    - messageEncryptionGet: retrieve encryption data for a message session
    - encryptionPluginsGet: retrieve all registered encryption plugin

Following methods are available for internal use:
    - getPlugins: retrieve registerd plugins
    - getNSFromName: retrieve namespace from plugin name
    - getBridgeData: serialise session data (to be used with bridge)
    - markAsEncrypted: mark message data as encrypted (to be set by encryption plugin in MessageReceived trigger)

Behaviours improvments:
    - start and stop send messageEncryptionStarted and messageEncryptionStopped signals, and a message feedback
    - new "replace" arguments in start allows to replace a plugin if one is already running (instead of raising a ConflictError)
    - plugins declare themselves as "directed" (i.e. working with only one device at a time) or not.
      This is checked while dealing with jids, an exception is raised when a full jid is received for a non directed encryption.
    - use of new data_format (de)serialise
2018-08-11 18:24:55 +02:00
Goffi
48427e3bdd core (memory/encryption): start improvments, stop and getSession:
- "start" won't do anything if session is already encrypted with requested algorithm, and will raise a ConflictError if it's already encrypted but with an other algorithm
- implemented "stop", with an optional namespace to check we are stopping the expected algorithm
- "getSession" retrieve the current encryption session of a jid, if any
2018-08-11 18:24:55 +02:00
Goffi
32b4db60c9 core: new EncryptionHandler class which manage encrypted session as a core feature:
Plugin handling encryption can now register using host.registerEncryptionPlugin, and an encryption session can now be started using messageEncryptionStart bridge method.

This will make encryption handling more easy, as we now know if a session is clear or e2e encrypted, and which plugin handle it.
2018-07-29 19:22:56 +02:00