From c0775afb631bd09e13eb683392fa19ab35401f5d Mon Sep 17 00:00:00 2001 From: rootiest Date: Fri, 4 Oct 2024 11:08:48 -0400 Subject: [PATCH] feat: session encryption -- Allows user-customization of encryption --- README.md | 21 +++++++++++++++++++++ encryption.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ opts.lua | 7 ++++++- plugins/resurrect.lua | 24 ------------------------ wezterm.lua | 3 +++ 5 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 encryption.lua diff --git a/README.md b/README.md index 9fb98aa..7029424 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,27 @@ This is applied after the default config so user options will override any defau Further, the `user.lua` file is ignored by git and will not impact your ability to pull updates. +### Session Encryption + +The default configuration attempts to use my personal encryption keys. + +If the keyfile cannot be found, encryption is disabled. + +You can customize this by adding (above the `return{}` table): + +```lua +MYKEY = "/path/to/keyfile.txt" -- Path to the keyfile +MYPUBKEY = "age1q80h5jsp9d48kggf9kra82xkgyaqdnehqenm003ftapem9re7ytqp9hr6h" + +return { + -- Etc.. +} +``` + +These global variables will be detected and used to apply the encryption. + +As with the default configuration, if the keyfile is not found, encryption is disabled. + ## Screenshots ![Rootiest WezTerm](.screenshots/term.png) diff --git a/encryption.lua b/encryption.lua new file mode 100644 index 0000000..af663cd --- /dev/null +++ b/encryption.lua @@ -0,0 +1,43 @@ +-- ╭─────────────────────────────────────────────────────────╮ +-- │ ENCRYPTION │ +-- ╰─────────────────────────────────────────────────────────╯ + +local M = {} + +-- Set the keyfile +local key = WEZTERM.home_dir .. "/.config/.private/key.txt" +local pubkey = "age1q80h5jsp9d48kggf9kra82xkgyaqdnehqenm003ftapem9re7ytqp9hr6h" + +if MYKEY then + key = MYKEY +elseif MYOS == "win" then + key = WEZTERM.home_dir .. "\\.config\\.private\\key.txt" +end + +if MYPUBKEY then + pubkey = MYPUBKEY +else +end + +---@function Check if a file exists +---@param file string The file path to check +---@return boolean exists True if the file exists, false otherwise +local function file_exists(file) + local f = io.open(file, "r") + if f then + f:close() + return true + end + return false +end + +if file_exists(key) then + RESURRECT.set_encryption({ + enable = true, + method = "age", -- "age" is the default encryption method, but you can also specify "rage" or "gpg" + private_key = key, -- if using "gpg", you can omit this + public_key = pubkey, + }) +end + +return M diff --git a/opts.lua b/opts.lua index d98d44c..8556cb5 100644 --- a/opts.lua +++ b/opts.lua @@ -27,7 +27,12 @@ end -- If USERCONFIG is true, merge userconfig into opts if USERCONFIG then - merge_into_opts("user") + for k, v in pairs(require("user")) do + opts[k] = v + end +else + MYKEY = nil + MYPUBKEY = nil end -- Return config options table diff --git a/plugins/resurrect.lua b/plugins/resurrect.lua index a56aaf2..d98996b 100644 --- a/plugins/resurrect.lua +++ b/plugins/resurrect.lua @@ -7,30 +7,6 @@ local M = {} -- Load Resurrect plugin RESURRECT = WEZTERM.plugin.require("https://github.com/MLFlexer/resurrect.wezterm") --- Set the keyfile -local key = WEZTERM.home_dir .. "/.config/.private/key.txt" - ----@function Check if a file exists ----@param file string The file path to check ----@return boolean exists True if the file exists, false otherwise -local function file_exists(file) - local f = io.open(file, "r") - if f then - f:close() - return true - end - return false -end - -if file_exists(key) then - RESURRECT.set_encryption({ - enable = true, - method = "age", -- "age" is the default encryption method, but you can also specify "rage" or "gpg" - private_key = key, -- if using "gpg", you can omit this - public_key = "age1q80h5jsp9d48kggf9kra82xkgyaqdnehqenm003ftapem9re7ytqp9hr6h", - }) -end - -- Set the periodic save interval RESURRECT.periodic_save({ interval_seconds = 60, save_workspaces = true, save_windows = true }) diff --git a/wezterm.lua b/wezterm.lua index 63b3719..bdc988f 100644 --- a/wezterm.lua +++ b/wezterm.lua @@ -32,6 +32,9 @@ USERCONFIG = pcall(require, "user") -- Load plugins require("plugs") +-- Encrypt Sessions +require("encryption") + --------- Update Plugins ---------- ---Running this may cause slowdowns -----------------------------------