From e95d9d0b49cdbb66440bba62ad55eba5938fad22 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 18 Nov 2023 19:18:02 +0000 Subject: [PATCH] core: rename migration to remote-control, comments (#3393) --- simplex-chat.cabal | 2 +- .../Migrations/M20231114_remote_control.hs | 45 ++++++++++++++++++ .../Migrations/M20231114_remote_controller.hs | 47 ------------------- src/Simplex/Chat/Migrations/chat_schema.sql | 38 +++++++-------- src/Simplex/Chat/Store/Migrations.hs | 4 +- 5 files changed, 66 insertions(+), 70 deletions(-) create mode 100644 src/Simplex/Chat/Migrations/M20231114_remote_control.hs delete mode 100644 src/Simplex/Chat/Migrations/M20231114_remote_controller.hs diff --git a/simplex-chat.cabal b/simplex-chat.cabal index d40d3239d..abcfcc4c4 100644 --- a/simplex-chat.cabal +++ b/simplex-chat.cabal @@ -123,7 +123,7 @@ library Simplex.Chat.Migrations.M20231030_xgrplinkmem_received Simplex.Chat.Migrations.M20231107_indexes Simplex.Chat.Migrations.M20231113_group_forward - Simplex.Chat.Migrations.M20231114_remote_controller + Simplex.Chat.Migrations.M20231114_remote_control Simplex.Chat.Mobile Simplex.Chat.Mobile.File Simplex.Chat.Mobile.Shared diff --git a/src/Simplex/Chat/Migrations/M20231114_remote_control.hs b/src/Simplex/Chat/Migrations/M20231114_remote_control.hs new file mode 100644 index 000000000..e716b2aa6 --- /dev/null +++ b/src/Simplex/Chat/Migrations/M20231114_remote_control.hs @@ -0,0 +1,45 @@ +{-# LANGUAGE QuasiQuotes #-} + +module Simplex.Chat.Migrations.M20231114_remote_control where + +import Database.SQLite.Simple (Query) +import Database.SQLite.Simple.QQ (sql) + +m20231114_remote_control :: Query +m20231114_remote_control = + [sql| +CREATE TABLE remote_hosts ( -- e.g., mobiles known to a desktop app + remote_host_id INTEGER PRIMARY KEY AUTOINCREMENT, + host_device_name TEXT NOT NULL, + store_path TEXT NOT NULL, -- relative folder name for host files + ca_key BLOB NOT NULL, + ca_cert BLOB NOT NULL, + id_key BLOB NOT NULL, -- long-term/identity signing key + host_fingerprint BLOB NOT NULL, -- remote host CA cert fingerprint, set when connected + host_dh_pub BLOB NOT NULL -- last session DH key +); + +CREATE UNIQUE INDEX idx_remote_hosts_host_fingerprint ON remote_hosts(host_fingerprint); + +CREATE TABLE remote_controllers ( -- e.g., desktops known to a mobile app + remote_ctrl_id INTEGER PRIMARY KEY AUTOINCREMENT, + ctrl_device_name TEXT NOT NULL, + ca_key BLOB NOT NULL, + ca_cert BLOB NOT NULL, + ctrl_fingerprint BLOB NOT NULL, -- remote controller CA cert fingerprint, set when connected + id_pub BLOB NOT NULL, -- remote controller long-term/identity key to verify signatures + dh_priv_key BLOB NOT NULL, -- last session DH key + prev_dh_priv_key BLOB -- previous session DH key +); + +CREATE UNIQUE INDEX idx_remote_controllers_ctrl_fingerprint ON remote_controllers(ctrl_fingerprint); +|] + +down_m20231114_remote_control :: Query +down_m20231114_remote_control = + [sql| +DROP INDEX idx_remote_hosts_host_fingerprint; +DROP INDEX idx_remote_controllers_ctrl_fingerprint; +DROP TABLE remote_hosts; +DROP TABLE remote_controllers; +|] diff --git a/src/Simplex/Chat/Migrations/M20231114_remote_controller.hs b/src/Simplex/Chat/Migrations/M20231114_remote_controller.hs deleted file mode 100644 index a8e92a998..000000000 --- a/src/Simplex/Chat/Migrations/M20231114_remote_controller.hs +++ /dev/null @@ -1,47 +0,0 @@ -{-# LANGUAGE QuasiQuotes #-} - -module Simplex.Chat.Migrations.M20231114_remote_controller where - -import Database.SQLite.Simple (Query) -import Database.SQLite.Simple.QQ (sql) - -m20231114_remote_controller :: Query -m20231114_remote_controller = - [sql| -CREATE TABLE remote_hosts ( -- hosts known to a controlling app - remote_host_id INTEGER PRIMARY KEY AUTOINCREMENT, - host_device_name TEXT NOT NULL, - store_path TEXT NOT NULL, -- file path for host files relative to app storage (must not contain "/") - -- RCHostPairing - ca_key BLOB NOT NULL, -- private key to sign session certificates - ca_cert BLOB NOT NULL, -- root certificate - id_key BLOB NOT NULL, -- long-term/identity signing key - -- KnownHostPairing - host_fingerprint BLOB NOT NULL, -- pinned remote host CA, set when connected - -- stored host session key - host_dh_pub BLOB NOT NULL, -- session DH key - UNIQUE (host_fingerprint) ON CONFLICT FAIL -); - -CREATE TABLE remote_controllers ( -- controllers known to a hosting app - remote_ctrl_id INTEGER PRIMARY KEY AUTOINCREMENT, - ctrl_device_name TEXT NOT NULL, - -- RCCtrlPairing - ca_key BLOB NOT NULL, -- CA key - ca_cert BLOB NOT NULL, -- CA certificate for TLS clients - ctrl_fingerprint BLOB NOT NULL, -- remote controller CA, set when connected - id_pub BLOB NOT NULL, -- remote controller long-term/identity key to verify signatures - -- stored session key, commited on connection confirmation - dh_priv_key BLOB NOT NULL, -- session DH key - -- prev session key - prev_dh_priv_key BLOB, -- previous session DH key - UNIQUE (ctrl_fingerprint) ON CONFLICT FAIL -); -|] - -down_m20231114_remote_controller :: Query -down_m20231114_remote_controller = - [sql| -DROP TABLE remote_hosts; -DROP TABLE remote_controllers; -|] diff --git a/src/Simplex/Chat/Migrations/chat_schema.sql b/src/Simplex/Chat/Migrations/chat_schema.sql index f6aed7698..bc441ec6f 100644 --- a/src/Simplex/Chat/Migrations/chat_schema.sql +++ b/src/Simplex/Chat/Migrations/chat_schema.sql @@ -528,34 +528,26 @@ CREATE TABLE IF NOT EXISTS "received_probes"( updated_at TEXT CHECK(updated_at NOT NULL) ); CREATE TABLE remote_hosts( - -- hosts known to a controlling app + -- e.g., mobiles known to a desktop app remote_host_id INTEGER PRIMARY KEY AUTOINCREMENT, host_device_name TEXT NOT NULL, - store_path TEXT NOT NULL, -- file path for host files relative to app storage(must not contain "/") - -- RCHostPairing - ca_key BLOB NOT NULL, -- private key to sign session certificates - ca_cert BLOB NOT NULL, -- root certificate + store_path TEXT NOT NULL, -- relative folder name for host files + ca_key BLOB NOT NULL, + ca_cert BLOB NOT NULL, id_key BLOB NOT NULL, -- long-term/identity signing key - -- KnownHostPairing - host_fingerprint BLOB NOT NULL, -- pinned remote host CA, set when connected - -- stored host session key - host_dh_pub BLOB NOT NULL, -- session DH key - UNIQUE(host_fingerprint) ON CONFLICT FAIL + host_fingerprint BLOB NOT NULL, -- remote host CA cert fingerprint, set when connected + host_dh_pub BLOB NOT NULL -- last session DH key ); CREATE TABLE remote_controllers( - -- controllers known to a hosting app + -- e.g., desktops known to a mobile app remote_ctrl_id INTEGER PRIMARY KEY AUTOINCREMENT, ctrl_device_name TEXT NOT NULL, - -- RCCtrlPairing - ca_key BLOB NOT NULL, -- CA key - ca_cert BLOB NOT NULL, -- CA certificate for TLS clients - ctrl_fingerprint BLOB NOT NULL, -- remote controller CA, set when connected + ca_key BLOB NOT NULL, + ca_cert BLOB NOT NULL, + ctrl_fingerprint BLOB NOT NULL, -- remote controller CA cert fingerprint, set when connected id_pub BLOB NOT NULL, -- remote controller long-term/identity key to verify signatures - -- stored session key, commited on connection confirmation - dh_priv_key BLOB NOT NULL, -- session DH key - -- prev session key - prev_dh_priv_key BLOB, -- previous session DH key - UNIQUE(ctrl_fingerprint) ON CONFLICT FAIL + dh_priv_key BLOB NOT NULL, -- last session DH key + prev_dh_priv_key BLOB -- previous session DH key ); CREATE INDEX contact_profiles_index ON contact_profiles( display_name, @@ -808,3 +800,9 @@ CREATE INDEX idx_messages_group_id_shared_msg_id ON messages( CREATE INDEX idx_chat_items_forwarded_by_group_member_id ON chat_items( forwarded_by_group_member_id ); +CREATE UNIQUE INDEX idx_remote_hosts_host_fingerprint ON remote_hosts( + host_fingerprint +); +CREATE UNIQUE INDEX idx_remote_controllers_ctrl_fingerprint ON remote_controllers( + ctrl_fingerprint +); diff --git a/src/Simplex/Chat/Store/Migrations.hs b/src/Simplex/Chat/Store/Migrations.hs index f7b10971c..7b9ead1b1 100644 --- a/src/Simplex/Chat/Store/Migrations.hs +++ b/src/Simplex/Chat/Store/Migrations.hs @@ -89,7 +89,7 @@ import Simplex.Chat.Migrations.M20231019_indexes import Simplex.Chat.Migrations.M20231030_xgrplinkmem_received import Simplex.Chat.Migrations.M20231107_indexes import Simplex.Chat.Migrations.M20231113_group_forward -import Simplex.Chat.Migrations.M20231114_remote_controller +import Simplex.Chat.Migrations.M20231114_remote_control import Simplex.Messaging.Agent.Store.SQLite.Migrations (Migration (..)) schemaMigrations :: [(String, Query, Maybe Query)] @@ -179,7 +179,7 @@ schemaMigrations = ("20231030_xgrplinkmem_received", m20231030_xgrplinkmem_received, Just down_m20231030_xgrplinkmem_received), ("20231107_indexes", m20231107_indexes, Just down_m20231107_indexes), ("20231113_group_forward", m20231113_group_forward, Just down_m20231113_group_forward), - ("20231114_remote_controller", m20231114_remote_controller, Just down_m20231114_remote_controller) + ("20231114_remote_control", m20231114_remote_control, Just down_m20231114_remote_control) ] -- | The list of migrations in ascending order by date