From e4b77ed9e68373e2bad48a7c825db3860a6ad4d6 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 30 Aug 2022 12:31:41 +0100 Subject: [PATCH 1/5] use SQLCipher (#507) * use SQLCipher * pass database key via options, use local direct-sqlcipher and sqlcipher-simple * update stack.yaml * use dependencies in git * update sqlcipher dependencies --- cabal.project | 11 +++++++++ package.yaml | 4 +-- simplexmq.cabal | 20 +++++++-------- src/Simplex/Messaging/Agent/Env/SQLite.hs | 6 +++-- src/Simplex/Messaging/Agent/Store/SQLite.hs | 27 ++++++++++++--------- stack.yaml | 6 +++++ tests/AgentTests/SQLiteTests.hs | 4 +-- tests/AgentTests/SchemaDump.hs | 2 +- 8 files changed, 51 insertions(+), 29 deletions(-) diff --git a/cabal.project b/cabal.project index fab9495dc..bccf2e365 100644 --- a/cabal.project +++ b/cabal.project @@ -1,6 +1,17 @@ packages: . +-- packages: . ../direct-sqlcipher ../sqlcipher-simple source-repository-package type: git location: https://github.com/simplex-chat/aeson.git tag: 3eb66f9a68f103b5f1489382aad89f5712a64db7 + +source-repository-package + type: git + location: https://github.com/simplex-chat/direct-sqlcipher.git + tag: 477955063df65a2776c2a958b656ff359b76374d + +source-repository-package + type: git + location: https://github.com/simplex-chat/sqlcipher-simple.git + tag: 0738c7957e971b84a2a156d297596206b948c4f6 diff --git a/package.yaml b/package.yaml index ac686a874..6c765a766 100644 --- a/package.yaml +++ b/package.yaml @@ -38,7 +38,7 @@ dependencies: - cryptonite >= 0.27 && < 0.30 - cryptostore == 0.2.* - data-default == 0.7.* - - direct-sqlite == 2.3.* + - direct-sqlcipher == 2.3.* - directory == 1.3.* - filepath == 1.4.* - http-types == 0.12.* @@ -56,7 +56,7 @@ dependencies: - random >= 1.1 && < 1.3 - simple-logger == 0.1.* - socks == 0.6.* - - sqlite-simple == 0.4.* + - sqlcipher-simple == 0.4.* - stm == 2.5.* - template-haskell == 2.16.* - text == 1.2.* diff --git a/simplexmq.cabal b/simplexmq.cabal index c185f10cc..44ee69951 100644 --- a/simplexmq.cabal +++ b/simplexmq.cabal @@ -114,7 +114,7 @@ library , cryptonite >=0.27 && <0.30 , cryptostore ==0.2.* , data-default ==0.7.* - , direct-sqlite ==2.3.* + , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* , generic-random >=1.3 && <1.5 @@ -131,7 +131,7 @@ library , random >=1.1 && <1.3 , simple-logger ==0.1.* , socks ==0.6.* - , sqlite-simple ==0.4.* + , sqlcipher-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* , text ==1.2.* @@ -175,7 +175,7 @@ executable ntf-server , cryptonite >=0.27 && <0.30 , cryptostore ==0.2.* , data-default ==0.7.* - , direct-sqlite ==2.3.* + , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* , generic-random >=1.3 && <1.5 @@ -193,7 +193,7 @@ executable ntf-server , simple-logger ==0.1.* , simplexmq , socks ==0.6.* - , sqlite-simple ==0.4.* + , sqlcipher-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* , text ==1.2.* @@ -237,7 +237,7 @@ executable smp-agent , cryptonite >=0.27 && <0.30 , cryptostore ==0.2.* , data-default ==0.7.* - , direct-sqlite ==2.3.* + , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* , generic-random >=1.3 && <1.5 @@ -255,7 +255,7 @@ executable smp-agent , simple-logger ==0.1.* , simplexmq , socks ==0.6.* - , sqlite-simple ==0.4.* + , sqlcipher-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* , text ==1.2.* @@ -299,7 +299,7 @@ executable smp-server , cryptonite >=0.27 && <0.30 , cryptostore ==0.2.* , data-default ==0.7.* - , direct-sqlite ==2.3.* + , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* , generic-random >=1.3 && <1.5 @@ -317,7 +317,7 @@ executable smp-server , simple-logger ==0.1.* , simplexmq , socks ==0.6.* - , sqlite-simple ==0.4.* + , sqlcipher-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* , text ==1.2.* @@ -378,7 +378,7 @@ test-suite smp-server-test , cryptonite >=0.27 && <0.30 , cryptostore ==0.2.* , data-default ==0.7.* - , direct-sqlite ==2.3.* + , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* , generic-random >=1.3 && <1.5 @@ -398,7 +398,7 @@ test-suite smp-server-test , simple-logger ==0.1.* , simplexmq , socks ==0.6.* - , sqlite-simple ==0.4.* + , sqlcipher-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* , text ==1.2.* diff --git a/src/Simplex/Messaging/Agent/Env/SQLite.hs b/src/Simplex/Messaging/Agent/Env/SQLite.hs index 5e85097d9..03cb3ba7b 100644 --- a/src/Simplex/Messaging/Agent/Env/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Env/SQLite.hs @@ -65,6 +65,7 @@ data AgentConfig = AgentConfig connIdBytes :: Int, tbqSize :: Natural, dbFile :: FilePath, + dbKey :: String, yesToMigrations :: Bool, smpCfg :: ProtocolClientConfig, ntfCfg :: ProtocolClientConfig, @@ -108,6 +109,7 @@ defaultAgentConfig = connIdBytes = 12, tbqSize = 64, dbFile = "smp-agent.db", + dbKey = "", yesToMigrations = False, smpCfg = defaultClientConfig {defaultTransport = (show defaultSMPPort, transport @TLS)}, ntfCfg = defaultClientConfig {defaultTransport = ("443", transport @TLS)}, @@ -139,9 +141,9 @@ data Env = Env } newSMPAgentEnv :: (MonadUnliftIO m, MonadRandom m) => AgentConfig -> m Env -newSMPAgentEnv config@AgentConfig {dbFile, yesToMigrations} = do +newSMPAgentEnv config@AgentConfig {dbFile, dbKey, yesToMigrations} = do idsDrg <- newTVarIO =<< drgNew - store <- liftIO $ createSQLiteStore dbFile Migrations.app yesToMigrations + store <- liftIO $ createSQLiteStore dbFile dbKey Migrations.app yesToMigrations clientCounter <- newTVarIO 0 randomServer <- newTVarIO =<< liftIO newStdGen ntfSupervisor <- atomically . newNtfSubSupervisor $ tbqSize config diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index 25316fa1a..a3e1aa10a 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -152,11 +152,11 @@ data SQLiteStore = SQLiteStore dbNew :: Bool } -createSQLiteStore :: FilePath -> [Migration] -> Bool -> IO SQLiteStore -createSQLiteStore dbFilePath migrations yesToMigrations = do +createSQLiteStore :: FilePath -> String -> [Migration] -> Bool -> IO SQLiteStore +createSQLiteStore dbFilePath dbKey migrations yesToMigrations = do let dbDir = takeDirectory dbFilePath createDirectoryIfMissing False dbDir - st <- connectSQLiteStore dbFilePath + st <- connectSQLiteStore dbFilePath dbKey checkThreadsafe st migrateSchema st migrations yesToMigrations pure st @@ -192,24 +192,27 @@ confirmOrExit s = do ok <- getLine when (map toLower ok /= "y") exitFailure -connectSQLiteStore :: FilePath -> IO SQLiteStore -connectSQLiteStore dbFilePath = do +connectSQLiteStore :: FilePath -> String -> IO SQLiteStore +connectSQLiteStore dbFilePath dbKey = do dbNew <- not <$> doesFileExist dbFilePath - dbConnection <- newTMVarIO =<< connectDB dbFilePath + dbConnection <- newTMVarIO =<< connectDB dbFilePath dbKey pure SQLiteStore {dbFilePath, dbConnection, dbNew} -connectDB :: FilePath -> IO DB.Connection -connectDB path = do - dbConn <- DB.open path - SQLite3.exec (DB.connectionHandle dbConn) . fromQuery $ +connectDB :: FilePath -> String -> IO DB.Connection +connectDB path key = do + db <- DB.open path + let exec = SQLite3.exec $ DB.connectionHandle db + -- TODO escape key + unless (null key) . exec $ "PRAGMA key = '" <> T.pack key <> "';" + exec . fromQuery $ [sql| PRAGMA foreign_keys = ON; -- PRAGMA trusted_schema = OFF; PRAGMA secure_delete = ON; PRAGMA auto_vacuum = FULL; |] - -- _printPragmas dbConn path - pure dbConn + -- _printPragmas db path + pure db -- _printPragmas :: DB.Connection -> FilePath -> IO () -- _printPragmas db path = do diff --git a/stack.yaml b/stack.yaml index 29af9bcdb..38ec75bf4 100644 --- a/stack.yaml +++ b/stack.yaml @@ -48,6 +48,12 @@ extra-deps: - time-compat-1.9.6.1@sha256:42d8f2e08e965e1718917d54ad69e1d06bd4b87d66c41dc7410f59313dba4ed1,5033 - github: simplex-chat/aeson commit: 3eb66f9a68f103b5f1489382aad89f5712a64db7 + # - ../direct-sqlcipher + - github: simplex-chat/direct-sqlcipher + commit: 477955063df65a2776c2a958b656ff359b76374d + # - ../sqlcipher-simple + - github: simplex-chat/sqlcipher-simple + commit: 0738c7957e971b84a2a156d297596206b948c4f6 # - ../hs-tls/core # - github: simplex-chat/hs-tls # commit: f6cc753611f80af300401cfae63846e9d7c40d9e diff --git a/tests/AgentTests/SQLiteTests.hs b/tests/AgentTests/SQLiteTests.hs index 6a79fdea2..84ae3e1aa 100644 --- a/tests/AgentTests/SQLiteTests.hs +++ b/tests/AgentTests/SQLiteTests.hs @@ -43,7 +43,7 @@ withStore2 = before connect2 . after (removeStore . fst) connect2 :: IO (SQLiteStore, SQLiteStore) connect2 = do s1 <- createStore - s2 <- connectSQLiteStore (dbFilePath s1) + s2 <- connectSQLiteStore (dbFilePath s1) "" pure (s1, s2) createStore :: IO SQLiteStore @@ -51,7 +51,7 @@ createStore = do -- Randomize DB file name to avoid SQLite IO errors supposedly caused by asynchronous -- IO operations on multiple similarly named files; error seems to be environment specific r <- randomIO :: IO Word32 - createSQLiteStore (testDB <> show r) Migrations.app True + createSQLiteStore (testDB <> show r) "" Migrations.app True removeStore :: SQLiteStore -> IO () removeStore db = do diff --git a/tests/AgentTests/SchemaDump.hs b/tests/AgentTests/SchemaDump.hs index 03baa28b2..43c67a332 100644 --- a/tests/AgentTests/SchemaDump.hs +++ b/tests/AgentTests/SchemaDump.hs @@ -20,7 +20,7 @@ schemaDumpTest = testVerifySchemaDump :: IO () testVerifySchemaDump = do - void $ createSQLiteStore testDB Migrations.app False + void $ createSQLiteStore testDB "" Migrations.app False void $ readCreateProcess (shell $ "touch " <> schema) "" savedSchema <- readFile schema savedSchema `seq` pure () From f872c25f09393c191913bf658f1721aeaf6443e4 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 30 Aug 2022 14:23:36 +0100 Subject: [PATCH 2/5] update dependencies (to not use SQL encryption unless flag is set) --- cabal.project | 4 ++-- stack.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cabal.project b/cabal.project index bccf2e365..96cf5badd 100644 --- a/cabal.project +++ b/cabal.project @@ -9,9 +9,9 @@ source-repository-package source-repository-package type: git location: https://github.com/simplex-chat/direct-sqlcipher.git - tag: 477955063df65a2776c2a958b656ff359b76374d + tag: 34309410eb2069b029b8fc1872deb1e0db123294 source-repository-package type: git location: https://github.com/simplex-chat/sqlcipher-simple.git - tag: 0738c7957e971b84a2a156d297596206b948c4f6 + tag: 5e154a2aeccc33ead6c243ec07195ab673137221 diff --git a/stack.yaml b/stack.yaml index 38ec75bf4..0cc68455c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -50,10 +50,10 @@ extra-deps: commit: 3eb66f9a68f103b5f1489382aad89f5712a64db7 # - ../direct-sqlcipher - github: simplex-chat/direct-sqlcipher - commit: 477955063df65a2776c2a958b656ff359b76374d + commit: 34309410eb2069b029b8fc1872deb1e0db123294 # - ../sqlcipher-simple - github: simplex-chat/sqlcipher-simple - commit: 0738c7957e971b84a2a156d297596206b948c4f6 + commit: 5e154a2aeccc33ead6c243ec07195ab673137221 # - ../hs-tls/core # - github: simplex-chat/hs-tls # commit: f6cc753611f80af300401cfae63846e9d7c40d9e From 26d149d17c0ceb5cc17d0fd1c1357d95bd47e549 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 31 Aug 2022 17:57:38 +0100 Subject: [PATCH 3/5] interpolate sql strings (#510) --- src/Simplex/Messaging/Agent/Client.hs | 6 +++--- src/Simplex/Messaging/Agent/Store/SQLite.hs | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Client.hs b/src/Simplex/Messaging/Agent/Client.hs index 329ebbb34..476ba4b56 100644 --- a/src/Simplex/Messaging/Agent/Client.hs +++ b/src/Simplex/Messaging/Agent/Client.hs @@ -52,7 +52,7 @@ module Simplex.Messaging.Agent.Client logServer, removeSubscription, hasActiveSubscription, - agentDbPath, + agentStore, AgentOperation (..), AgentOpState (..), AgentState (..), @@ -227,8 +227,8 @@ newAgentClient InitialAgentServers {smp, ntf, netCfg} agentEnv = do lock <- newTMVar () return AgentClient {active, rcvQ, subQ, msgQ, smpServers, smpClients, ntfServers, ntfClients, useNetworkConfig, subscrSrvrs, pendingSubscrSrvrs, subscrConns, activeSubscrConns, connMsgsQueued, smpQueueMsgQueues, smpQueueMsgDeliveries, ntfNetworkOp, rcvNetworkOp, msgDeliveryOp, sndNetworkOp, databaseOp, agentState, getMsgLocks, reconnections, asyncClients, clientId, agentEnv, lock} -agentDbPath :: AgentClient -> FilePath -agentDbPath AgentClient {agentEnv = Env {store = SQLiteStore {dbFilePath}}} = dbFilePath +agentStore :: AgentClient -> SQLiteStore +agentStore AgentClient {agentEnv = Env {store}} = store class ProtocolServerClient msg where getProtocolServerClient :: AgentMonad m => AgentClient -> ProtoServer msg -> m (ProtocolClient msg) diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index a3e1aa10a..d8af7226b 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -22,6 +22,7 @@ module Simplex.Messaging.Agent.Store.SQLite ( SQLiteStore (..), createSQLiteStore, connectSQLiteStore, + sqlString, -- * Queues and connections createRcvConn, @@ -148,6 +149,7 @@ import UnliftIO.STM data SQLiteStore = SQLiteStore { dbFilePath :: FilePath, + dbKey :: String, dbConnection :: TMVar DB.Connection, dbNew :: Bool } @@ -196,14 +198,13 @@ connectSQLiteStore :: FilePath -> String -> IO SQLiteStore connectSQLiteStore dbFilePath dbKey = do dbNew <- not <$> doesFileExist dbFilePath dbConnection <- newTMVarIO =<< connectDB dbFilePath dbKey - pure SQLiteStore {dbFilePath, dbConnection, dbNew} + pure SQLiteStore {dbFilePath, dbKey, dbConnection, dbNew} connectDB :: FilePath -> String -> IO DB.Connection connectDB path key = do db <- DB.open path let exec = SQLite3.exec $ DB.connectionHandle db - -- TODO escape key - unless (null key) . exec $ "PRAGMA key = '" <> T.pack key <> "';" + unless (null key) . exec $ "PRAGMA key = " <> sqlString key <> ";" exec . fromQuery $ [sql| PRAGMA foreign_keys = ON; @@ -214,6 +215,11 @@ connectDB path key = do -- _printPragmas db path pure db +sqlString :: String -> Text +sqlString s = quote <> T.replace quote "''" (T.pack s) <> quote + where + quote = "'" + -- _printPragmas :: DB.Connection -> FilePath -> IO () -- _printPragmas db path = do -- foreign_keys <- DB.query_ db "PRAGMA foreign_keys;" :: IO [[Int]] From e4b47825b56122222e5bf4716285b419acdac83d Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 2 Sep 2022 15:42:37 +0100 Subject: [PATCH 4/5] functions to create and close store (#512) --- src/Simplex/Messaging/Agent/Env/SQLite.hs | 6 ++- src/Simplex/Messaging/Agent/Store/SQLite.hs | 41 ++++++++++----------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Env/SQLite.hs b/src/Simplex/Messaging/Agent/Env/SQLite.hs index 03cb3ba7b..9004a2bd9 100644 --- a/src/Simplex/Messaging/Agent/Env/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Env/SQLite.hs @@ -18,6 +18,7 @@ module Simplex.Messaging.Agent.Env.SQLite defaultReconnectInterval, Env (..), newSMPAgentEnv, + createAgentStore, NtfSupervisor (..), NtfSupervisorCommand (..), ) @@ -143,12 +144,15 @@ data Env = Env newSMPAgentEnv :: (MonadUnliftIO m, MonadRandom m) => AgentConfig -> m Env newSMPAgentEnv config@AgentConfig {dbFile, dbKey, yesToMigrations} = do idsDrg <- newTVarIO =<< drgNew - store <- liftIO $ createSQLiteStore dbFile dbKey Migrations.app yesToMigrations + store <- liftIO $ createAgentStore dbFile dbKey yesToMigrations clientCounter <- newTVarIO 0 randomServer <- newTVarIO =<< liftIO newStdGen ntfSupervisor <- atomically . newNtfSubSupervisor $ tbqSize config return Env {config, store, idsDrg, clientCounter, randomServer, ntfSupervisor} +createAgentStore :: FilePath -> String -> Bool -> IO SQLiteStore +createAgentStore dbFilePath dbKey = createSQLiteStore dbFilePath dbKey Migrations.app + data NtfSupervisor = NtfSupervisor { ntfTkn :: TVar (Maybe NtfToken), ntfSubQ :: TBQueue (ConnId, NtfSupervisorCommand), diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index d8af7226b..ba62da04d 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -22,6 +22,7 @@ module Simplex.Messaging.Agent.Store.SQLite ( SQLiteStore (..), createSQLiteStore, connectSQLiteStore, + closeSQLiteStore, sqlString, -- * Queues and connections @@ -107,7 +108,7 @@ import Data.ByteString (ByteString) import qualified Data.ByteString.Base64.URL as U import Data.Char (toLower) import Data.Functor (($>)) -import Data.List (find, foldl') +import Data.List (foldl') import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.Map.Strict as M import Data.Maybe (fromMaybe, listToMaybe) @@ -141,7 +142,7 @@ import System.Directory (copyFile, createDirectoryIfMissing, doesFileExist) import System.Exit (exitFailure) import System.FilePath (takeDirectory) import System.IO (hFlush, stdout) -import UnliftIO.Exception (bracket) +import UnliftIO.Exception (bracket, onException) import qualified UnliftIO.Exception as E import UnliftIO.STM @@ -159,19 +160,9 @@ createSQLiteStore dbFilePath dbKey migrations yesToMigrations = do let dbDir = takeDirectory dbFilePath createDirectoryIfMissing False dbDir st <- connectSQLiteStore dbFilePath dbKey - checkThreadsafe st - migrateSchema st migrations yesToMigrations + migrateSchema st migrations yesToMigrations `onException` closeSQLiteStore st pure st -checkThreadsafe :: SQLiteStore -> IO () -checkThreadsafe st = withConnection st $ \db -> do - compileOptions <- DB.query_ db "pragma COMPILE_OPTIONS;" :: IO [[Text]] - let threadsafeOption = find (T.isPrefixOf "THREADSAFE=") (concat compileOptions) - case threadsafeOption of - Just "THREADSAFE=0" -> confirmOrExit "SQLite compiled with non-threadsafe code." - Nothing -> putStrLn "Warning: SQLite THREADSAFE compile option not found" - _ -> return () - migrateSchema :: SQLiteStore -> [Migration] -> Bool -> IO () migrateSchema st migrations yesToMigrations = withConnection st $ \db -> do Migrations.initialize db @@ -203,17 +194,23 @@ connectSQLiteStore dbFilePath dbKey = do connectDB :: FilePath -> String -> IO DB.Connection connectDB path key = do db <- DB.open path - let exec = SQLite3.exec $ DB.connectionHandle db - unless (null key) . exec $ "PRAGMA key = " <> sqlString key <> ";" - exec . fromQuery $ - [sql| - PRAGMA foreign_keys = ON; - -- PRAGMA trusted_schema = OFF; - PRAGMA secure_delete = ON; - PRAGMA auto_vacuum = FULL; - |] + prepare db `onException` DB.close db -- _printPragmas db path pure db + where + prepare db = do + let exec = SQLite3.exec $ DB.connectionHandle db + unless (null key) . exec $ "PRAGMA key = " <> sqlString key <> ";" + exec . fromQuery $ + [sql| + PRAGMA foreign_keys = ON; + -- PRAGMA trusted_schema = OFF; + PRAGMA secure_delete = ON; + PRAGMA auto_vacuum = FULL; + |] + +closeSQLiteStore :: SQLiteStore -> IO () +closeSQLiteStore st = atomically (takeTMVar $ dbConnection st) >>= DB.close sqlString :: String -> Text sqlString s = quote <> T.replace quote "''" (T.pack s) <> quote From 50c210c5c0c7f792c39123c2177bb60b307295b9 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 5 Sep 2022 12:55:14 +0100 Subject: [PATCH 5/5] remove database key from SQLiteStore (#514) --- src/Simplex/Messaging/Agent/Store/SQLite.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index ba62da04d..2ded4a576 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -150,7 +150,7 @@ import UnliftIO.STM data SQLiteStore = SQLiteStore { dbFilePath :: FilePath, - dbKey :: String, + dbEncrypted :: TVar Bool, dbConnection :: TMVar DB.Connection, dbNew :: Bool } @@ -189,7 +189,8 @@ connectSQLiteStore :: FilePath -> String -> IO SQLiteStore connectSQLiteStore dbFilePath dbKey = do dbNew <- not <$> doesFileExist dbFilePath dbConnection <- newTMVarIO =<< connectDB dbFilePath dbKey - pure SQLiteStore {dbFilePath, dbKey, dbConnection, dbNew} + dbEncrypted <- newTVarIO . not $ null dbKey + pure SQLiteStore {dbFilePath, dbEncrypted, dbConnection, dbNew} connectDB :: FilePath -> String -> IO DB.Connection connectDB path key = do