diff options
author | Kim Alvefur <zash@zash.se> | 2025-01-23 16:38:56 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2025-01-23 16:38:56 +0100 |
commit | 654edd37bbf7608fa1f1889cda4604cdba76f20f (patch) | |
tree | 9855d4d534fb9ec19172724758d50145f0603561 /util | |
parent | 2d4ea8ac9b1797698bd3d722ee2beed2638be52a (diff) | |
download | prosody-654edd37bbf7608fa1f1889cda4604cdba76f20f.tar.gz prosody-654edd37bbf7608fa1f1889cda4604cdba76f20f.zip |
util.sql: SQLCipher support
This enables use of encrypted databases if LuaDBI or LuaSQLite3 has been
linked against SQLCipher. Using `LD_PRELOAD` may work as well.
Requires SQLCipher >= 4.0.0 due to the use of UPSERT
Diffstat (limited to 'util')
-rw-r--r-- | util/sql.lua | 6 | ||||
-rw-r--r-- | util/sqlite3.lua | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/util/sql.lua b/util/sql.lua index c897d734..2f0ec493 100644 --- a/util/sql.lua +++ b/util/sql.lua @@ -84,6 +84,12 @@ function engine:connect() dbh:autocommit(false); -- don't commit automatically self.conn = dbh; self.prepared = {}; + if params.password then + local ok, err = self:execute(("PRAGMA key='%s'"):format(dbh:quote(params.password))); + if not ok then + return ok, err; + end + end local ok, err = self:set_encoding(); if not ok then return ok, err; diff --git a/util/sqlite3.lua b/util/sqlite3.lua index 470eb46d..fec2d162 100644 --- a/util/sqlite3.lua +++ b/util/sqlite3.lua @@ -114,6 +114,12 @@ function engine:connect() if not dbh then return nil, err; end self.conn = dbh; self.prepared = {}; + if params.password then + local ok, err = self:execute(("PRAGMA key='%s'"):format((params.password:gsub("'", "''")))); + if not ok then + return ok, err; + end + end local ok, err = self:set_encoding(); if not ok then return ok, err; |