199 Commits
Author SHA1 Message Date
RandyTheSilly cfb4a2ad51 Prepare for release v0.2.4 2024-12-13 12:43:46 -05:00
RandyTheSilly dda33755b3 Bump Go to v1.23.4; bump dependencies (including golang.org/x/crypto to address CVE-2024-45337) 2024-12-13 12:05:06 -05:00
RandyTheSilly 544261a461 Remove commit.sh 2024-10-29 17:18:02 -04:00
RandyTheSilly 77014cf5e3 Add optional build tag for experimental BEAN Markdown renderer support 2024-10-29 17:08:57 -04:00
RandyTheSilly 750029a491 Add Go bump to patch notes 2024-10-19 17:00:40 -04:00
RandyTheSilly 380c49bd00 Prepare for release v0.2.3 2024-10-19 16:53:04 -04:00
RandyTheSilly 33b8704f0c Bump dependencies 2024-10-19 16:32:25 -04:00
RandyTheSilly f96b60d3ef Bump Go to v1.23.2 2024-10-19 16:02:20 -04:00
RandyTheSilly 13422e12c4 Add script to generate Alpine APKBUILDs 2024-10-19 15:34:08 -04:00
RandyTheSilly 880d633da0 Improve Arch PKGBUILD's CPU feature detection 2024-10-19 11:37:41 -04:00
RandyTheSilly cbf9035969 Add gnupg as a dependency in Arch PKGBUILD 2024-10-18 12:37:38 -04:00
RandyTheSilly a5d93d4527 Correct typo in release notes archive 2024-10-18 12:21:46 -04:00
RandyTheSilly 0c62a84195 Prepare for release v0.2.2 2024-08-20 21:17:13 -04:00
RandyTheSilly 8c1b986e20 Fix adding new entries on Windows 2024-08-19 22:14:47 -04:00
RandyTheSilly a44bef1db9 Prepare for release v0.2.1 2024-08-13 22:33:37 -04:00
RandyTheSilly 9cc4965ed8 Bump: github.com/rwinkhart/libmutton PRE-TAG => v0.2.1; add script for generating release binaries 2024-08-13 21:46:14 -04:00
RandyTheSilly b68b2a8931 Implement error-specific exit codes defined by libmutton 2024-08-13 17:36:15 -04:00
RandyTheSilly 888b1ca80d Properly format function documentation comments 2024-08-11 19:05:16 -04:00
RandyTheSilly 498fe20d95 [wiki] Update to match libmutton wiki changes 2024-08-08 20:06:22 -04:00
RandyTheSilly 35df3b078f Add AUR link to README.md; update roadmap 2024-08-08 19:39:33 -04:00
RandyTheSilly 113883f40a Remove gofmt targets that have been relocated 2024-08-08 19:14:56 -04:00
RandyTheSilly 73346b15cb [wiki] Fix links to various wiki pages 2024-08-08 19:13:25 -04:00
RandyTheSilly 66ea87aa11 Update README.md to accommodate repo split 2024-08-08 19:06:14 -04:00
RandyTheSilly 369aab5074 Update .gitignore 2024-08-08 18:42:57 -04:00
RandyTheSilly d8a239237c Decouple MUTN and libmutton versions 2024-08-08 18:38:12 -04:00
RandyTheSilly 39bc3bc442 Bump libmutton to v0.0.0-20240808213918-f5e5cd31bb85 2024-08-08 18:08:26 -04:00
RandyTheSilly 58dde7ed5d Move libmuttonserver.go to github.com/rwinkhart/libmutton 2024-08-08 17:41:22 -04:00
RandyTheSilly a23ae4a4b9 Switch to dependence on github.com/rwinkhart/libmutton 2024-08-08 17:24:48 -04:00
RandyTheSilly 57378c521a [wiki] Remove extra subdirectory 2024-08-08 17:09:47 -04:00
RandyTheSilly 3480fd8fdb Ship man page in PKGBUILD 2024-08-06 16:33:34 -04:00
RandyTheSilly bb127860c3 PKGBUILD description: specify for CLI 2024-08-06 16:10:08 -04:00
RandyTheSilly 68ea24fc15 [wiki/MUTN] Mention AUR package from install guide and mention that pre-built binaries do not use CGO 2024-08-06 15:55:36 -04:00
RandyTheSilly db7e95d4af Fix PKGBUILD x86_64 feature level check 2024-08-06 15:35:51 -04:00
RandyTheSilly 871897b6ce [wiki/MUTN] Link to release page from install guide; mention server binary must be called "libmuttonserver" 2024-08-06 15:24:17 -04:00
RandyTheSilly c80f875623 Prepare for release v0.2.0 2024-08-06 14:57:09 -04:00
RandyTheSilly 3e2a2839c5 Bump Go to v1.22.6; bump dependencies 2024-08-06 14:34:23 -04:00
RandyTheSilly fe412daa8d [wiki/MUTN] Link Glamour issue for v0.8.0 regression 2024-08-05 23:10:17 -04:00
RandyTheSilly e59cdaa88e Do not use deprecated golang.org/x/crypto/ssh/terminal 2024-08-05 22:29:43 -04:00
RandyTheSilly 72da94d682 [wiki/MUTN] Specify why MUTN is using out-of-date Glamour 2024-08-05 15:42:40 -04:00
RandyTheSilly ffe220fa9b Retrieve packaging version number from a temporary Go program 2024-08-05 14:00:49 -04:00
RandyTheSilly 0494143318 Add initial packaging script (currently only for generating source PKGBUILD) 2024-08-05 13:36:05 -04:00
RandyTheSilly 322877d273 Bump dependencies 2024-08-05 10:09:16 -04:00
RandyTheSilly 15e9f77f59 Announce TOTP code has been copied only after the entry has already been decrypted 2024-07-30 18:32:14 -04:00
RandyTheSilly 4785634454 [wiki/MUTN] Fix ordered list in usage guide 2024-07-30 16:20:44 -04:00
RandyTheSilly b839dc2772 [wiki/MUTN] Link to usage guide from installation guide 2024-07-30 16:00:24 -04:00
RandyTheSilly 6b04d7367e Update README.md w/banner image and a link to the installation guide 2024-07-30 15:57:43 -04:00
RandyTheSilly 4b82738048 Add fallback SSH identity file (~/.ssh/id_ed25519) 2024-07-21 22:56:24 -04:00
RandyTheSilly cdb2c949f0 Verify user-specified SSH identity file exists 2024-07-21 22:41:13 -04:00
RandyTheSilly 79d1713080 [wiki/MUTN] Add basic setup and usage instructions 2024-07-19 17:56:42 -04:00
RandyTheSilly d659291a2f Fail early if adding an entry to a directory that does not exist (or if the directory is a file) 2024-07-19 15:53:54 -04:00
RandyTheSilly 9077501d66 Fix rename prompting for new location before verifying old one exists 2024-07-19 13:48:14 -04:00
RandyTheSilly 07d2c5fd04 Update README.md 2024-07-19 03:17:30 -04:00
RandyTheSilly cdf554179a Improve StringGen to allow creating file name-safe complex strings; remove in-code references to future additions 2024-07-18 17:04:48 -04:00
RandyTheSilly ba197006a5 Do not upload/download any entries if the client and server time are more than 30 seconds out of sync; appropriately warn the user 2024-07-18 15:55:50 -04:00
RandyTheSilly 19bccf1464 Fix ANSI escapes (on Windows) not being interpreted after using GPG pinentry 2024-07-17 18:54:29 -04:00
RandyTheSilly 1e5c0feaba Simplify text editor fallback 2024-07-17 17:26:01 -04:00
RandyTheSilly c9b87dd121 Move text editor config under [MUTN] section header in libmutton.ini 2024-07-17 15:53:17 -04:00
RandyTheSilly 4daa031c0e Allow writing to different section headers in libmutton.ini 2024-07-17 15:49:45 -04:00
RandyTheSilly e6edc7c336 Move text editor determination to cli package 2024-07-17 14:59:57 -04:00
RandyTheSilly d46a2eddfc Allow parsing different section headers in libmutton.ini 2024-07-17 14:44:18 -04:00
RandyTheSilly 5d32636816 Use more specific names for global variables in Bash and ZSH completions 2024-07-16 18:35:31 -04:00
RandyTheSilly f7555f35ec Allow using Powershell completions on non-Windows platforms 2024-07-16 18:12:34 -04:00
RandyTheSilly fa93b53aba [wiki/MUTN] Add more Glamour-related issues to known bugs list 2024-07-16 16:24:57 -04:00
RandyTheSilly 0a56130d94 Clarify key-based authentication requirement in man page 2024-07-16 16:05:29 -04:00
RandyTheSilly c6734dd283 Add tag for building without Markdown support 2024-07-16 15:30:48 -04:00
RandyTheSilly 66e9511eec Do not initialize extra iterator in EntryReader() 2024-07-16 14:52:09 -04:00
RandyTheSilly 3535368424 Update .gitignore to ignore specific files rather than everything not manually added 2024-07-16 14:17:38 -04:00
RandyTheSilly 3c896b492c Bump "regexp2" to v1.11.2 2024-07-15 16:59:58 -04:00
RandyTheSilly 54d5d8bd0e Add initial man page and make help info wording more consistent 2024-07-15 16:01:43 -04:00
RandyTheSilly 82b1e31e5b Replace use of ASCII control characters with unicode characters allowed in Windows filenames (fixes shearing with a Windows server) 2024-07-10 15:23:13 -04:00
RandyTheSilly 0ebc404db2 Remove "-v" and "-h" shortcuts from server for consistency with MUTN cli 2024-07-10 03:44:59 -04:00
RandyTheSilly 08e8a64d29 Split sync.Rename into separate functions for client and server to avoid compiling SSH into the server binary 2024-07-10 00:01:59 -04:00
RandyTheSilly b9ac59fb67 Implement synchronized renaming 2024-07-09 23:18:13 -04:00
RandyTheSilly 9614ffc513 Expand "~" to home directory when specifying ssh identity file 2024-07-09 17:23:36 -04:00
RandyTheSilly 20c70bac9e Prompt for SSH port before IP (to avoid users responding to the IP prompt with a socket); specify SSH address may be a domain name 2024-07-09 15:26:17 -04:00
RandyTheSilly 48576ced29 [wiki/MUTN] Add known bugs list 2024-07-09 14:51:47 -04:00
RandyTheSilly e3aabfb7e4 Fix PowerShell completions not completing after directories containing spaces 2024-07-09 14:29:15 -04:00
RandyTheSilly d749452943 [wiki/MUTN] Move shell completions download link to completions.md 2024-07-07 23:08:11 -04:00
RandyTheSilly a6abd6c04e Sort shell completions scripts into folders so that their intended names can be used 2024-07-07 23:04:53 -04:00
RandyTheSilly 565f869da1 [wiki/MUTN] Add basic building/installation instructions 2024-07-07 22:59:55 -04:00
RandyTheSilly 995e2bd982 [wiki/MUTN] Add list of Windows quirks 2024-07-06 00:18:32 -04:00
RandyTheSilly 37f5883893 [wiki/MUTN] Add shell completions troubleshooting guide 2024-07-06 00:04:28 -04:00
RandyTheSilly 4b16bb9d22 Implement initial markdown wiki w/copy of clipboard troubleshooting info from sshyp 2024-07-05 23:42:40 -04:00
RandyTheSilly 964b6ea589 Bump Go to v1.22.5, bump dependencies 2024-07-05 22:32:34 -04:00
RandyTheSilly b757cdc30d Remove "-v" shortcut for "version" argument, as it does not work with Powershell completion; remove "-h" visual option for "help" for consistency 2024-07-05 21:41:18 -04:00
RandyTheSilly 6511ac6b6a Improve error clarity in cli.editNote 2024-06-05 18:19:01 -04:00
RandyTheSilly 71b5dc75cf Improve generic UNIX clipboard clearing logic 2024-06-05 17:43:21 -04:00
RandyTheSilly 6dc26859e9 Provide feedback after successful server directory initialization 2024-06-05 17:24:45 -04:00
RandyTheSilly 295b126d3a Write and append to config file using ini package 2024-06-05 14:56:17 -04:00
RandyTheSilly 1ec966b396 Enforce more consistent meanings for the various field separator characters 2024-06-04 21:51:58 -04:00
RandyTheSilly 4bec8d3e83 Server stdin migration: register 2024-06-04 20:05:12 -04:00
RandyTheSilly e49a7d8f0a Server stdin migration: shear 2024-06-04 15:57:00 -04:00
RandyTheSilly b2ba8b84d9 Server stdin migration: fetch 2024-06-04 15:38:46 -04:00
RandyTheSilly 6aaa9611ac Server stdin migration: addfolder 2024-06-04 15:33:50 -04:00
RandyTheSilly 7ab46f7402 Add initial support for reading stdin from the server binary 2024-06-04 15:09:57 -04:00
RandyTheSilly 182b50cd27 Fix Windows sync (WalkEntryDir now returns only UNIX-style separators); fix setting remote mod time on remote files when downloading; fix server binary compilation; fix init failing silently during SSH configuration 2024-05-31 01:23:50 -04:00
RandyTheSilly 423ea8a81b Fix init deleting device ID immediately after generating it; fix sync failure for non-manual syncs 2024-05-30 23:25:08 -04:00
RandyTheSilly 7dd313add0 Save server EntryRoot and OS type during init, use to progress toward Windows server support 2024-05-30 22:57:05 -04:00
RandyTheSilly 29d7f4d655 Simplify clipboard build constraints 2024-05-30 22:21:39 -04:00
RandyTheSilly b0d6c6121b Lay groundwork for NT/UNIX-like sync interoperability 2024-05-30 22:12:29 -04:00
RandyTheSilly 7ff5e5abfd Add "wsl_clipboard" build tag for creating Linux binaries that use the Windows clipboard 2024-05-29 15:42:15 -04:00
RandyTheSilly 7abad339af Update README.md now that native sync has been implemented 2024-05-29 13:59:43 -04:00
RandyTheSilly 7c29bde27a Bump dependencies 2024-05-29 13:26:28 -04:00
RandyTheSilly c7a2b4fb95 Reorganize function parameters to not specify repeat types 2024-05-29 13:23:08 -04:00
RandyTheSilly 4d735d220b Rename "hidePassword" to "hideSecrets" for clarity 2024-05-29 12:50:47 -04:00
RandyTheSilly ca160adabc Move TOTP secrets to a dedicated entry field (breaks sshyp entry format compatibility) 2024-05-21 19:21:42 -04:00
RandyTheSilly f5c5a28545 Reduce size of server binary by not compiling SSH 2024-05-19 19:34:28 -04:00
RandyTheSilly 665d4d4cb1 Switch from SCP to SFTP for sync 2024-05-19 17:30:39 -04:00
RandyTheSilly bc51f20d41 Promote native sync to replace sshyp-based sync on all platforms 2024-05-17 19:49:49 -04:00
RandyTheSilly 1230c8a437 Make server respond to "fetch" with output formatted for the client's OS family 2024-05-17 19:36:23 -04:00
RandyTheSilly 5ecd7142b3 Implement initial SCP functionality (not yet usable due to mod times not being preserved) 2024-05-17 15:44:15 -04:00
RandyTheSilly 8c1eaf3d65 Fix import cycle (over SSH keyfile passphrase input) 2024-05-17 12:25:10 -04:00
RandyTheSilly 66995c3c06 Implement initial support for passphrase-protected SSH keyfiles 2024-05-17 11:42:44 -04:00
RandyTheSilly d8fa62f1ad Add help and version info for server binary 2024-05-16 22:22:12 -04:00
RandyTheSilly da044ca59a Remove pre-existing config directory during init, structure Windows config directory more similarly to UNIX 2024-05-16 21:40:02 -04:00
RandyTheSilly a703c6b2ac Move device ID generation to sync.DeviceIDGen 2024-05-16 21:26:42 -04:00
RandyTheSilly 854bd906f0 When a folder is created on the client, also create it on the server 2024-05-16 21:15:16 -04:00
RandyTheSilly ddb2f257f3 Parse deletions per-deviceID 2024-05-16 17:46:03 -04:00
RandyTheSilly f18a023bb7 Implement device ID server registration and server-side init 2024-05-16 17:14:42 -04:00
RandyTheSilly bb67446653 Implement initial server-side shearing logic 2024-05-16 16:35:05 -04:00
RandyTheSilly 043a17de59 Bump dependencies 2024-05-15 17:14:36 -04:00
RandyTheSilly 102d2a8ee6 Better fetch remote data in a way that does not add blank items to slices 2024-05-15 16:57:46 -04:00
RandyTheSilly 7ab5e67256 Implement initial server-side code 2024-05-15 16:25:42 -04:00
RandyTheSilly e4b9ca6c34 Implement initial SSH data retrieval 2024-05-15 14:58:21 -04:00
RandyTheSilly 570e257f08 Initial groundwork for native sync support 2024-05-11 20:52:38 -04:00
RandyTheSilly db5f3ec7f4 Prepare to tag v0.1.0 2024-04-16 11:33:06 -04:00
RandyTheSilly 93d7670508 Merge EditEntryNote into EditEntryField 2024-04-16 11:20:22 -04:00
RandyTheSilly f33eb3d480 Refactor for better modularity (share more code among edit functions, rename "offline" package to "backend" 2024-04-15 18:16:05 -04:00
RandyTheSilly d124080813 Strip trailing whitespace from each line in notes before saving 2024-04-15 16:52:16 -04:00
RandyTheSilly 995fcac0ab Use gruvbox colors for version info graphic 2024-04-12 21:32:06 -04:00
RandyTheSilly 3be77fe1ac Move initial directory indentation multiplier determination to be with rest of indentation logic 2024-04-12 16:00:34 -04:00
RandyTheSilly 9eefcb7c47 Show total entry count in entry list 2024-04-12 11:32:25 -04:00
RandyTheSilly 8b2b7ac7ff Bump dependencies 2024-04-12 11:16:34 -04:00
RandyTheSilly 426f91bda0 (Markdown) Improve consistency of in-line code and block quote colors (block quotes are currently busted) 2024-04-11 16:46:31 -04:00
RandyTheSilly 468a28a036 (Markdown) Reduce quantity of "+" in lower-tier headings 2024-04-11 16:15:12 -04:00
RandyTheSilly e3ebcf0db4 (Markdown) Fix definitions lists, set color for HR, images 2024-04-11 16:10:44 -04:00
RandyTheSilly 513fdd6f2e (Markdown) Make code block syntax highlighting more consistent with gruvbox 2024-04-11 15:45:41 -04:00
RandyTheSilly 58facd2ad0 (Markdown) Make headers more aesthetically pleasing 2024-04-11 14:49:13 -04:00
RandyTheSilly d85abd6b37 (Markdown) Add new, more consistent header design 2024-04-10 22:30:42 -04:00
RandyTheSilly 1b27121c26 (Markdown) More clearly identify code blocks 2024-04-10 21:32:17 -04:00
RandyTheSilly 6b0ad509f5 (Markdown) Use full terminal width for horizontal rulers 2024-04-10 20:16:39 -04:00
RandyTheSilly 09eec99fe1 Lay groundwork for multiple color-scheme support 2024-04-10 17:03:37 -04:00
RandyTheSilly 13352ec2b4 Wrap markdown text at full terminal width 2024-04-05 18:48:48 -04:00
RandyTheSilly 34a01f3688 Do not surround in-line code with spaces 2024-04-05 15:37:02 -04:00
RandyTheSilly 3e37ae8173 Support hard line breaks in markdown notes 2024-04-05 14:18:35 -04:00
RandyTheSilly ad7e90c43e Break out of switch after printing notes (no need to check additional lines) 2024-04-05 12:57:57 -04:00
RandyTheSilly 074e74b622 Build default Glamour style into binary 2024-04-04 19:57:22 -04:00
RandyTheSilly 8c5109e904 Commit WIP glamour style 2024-04-04 18:28:40 -04:00
RandyTheSilly dce483909b Implement initial markdown notes support with Glamour (buggy, not ready for daily use) 2024-04-04 18:26:32 -04:00
RandyTheSilly 115e0a3e0f Implement Steam TOTP support using github.com/fortis/go-steam-totp 2024-03-22 20:53:08 -04:00
RandyTheSilly 5be819e9db Advertise TOTP support in printInfo.go, add to shell completions 2024-03-18 18:38:42 -04:00
RandyTheSilly aed342c42f Update README.md with current progress 2024-03-18 17:03:19 -04:00
RandyTheSilly 9af89d5c85 Implement initial TOTP support (secret in third notes line, will eventually have its own dedicated field) 2024-03-18 16:44:22 -04:00
RandyTheSilly 782f03e276 Better document new blank option="password" shortcut, order arguments in order of expected use, list passwords first in entry reader 2024-03-18 12:59:18 -04:00
RandyTheSilly f3d747a5af Revert use of ":" for options on Windows, use "-" but replace "-p" with "-pw" to avoid ambiguity, interpret no options as "password" 2024-03-17 17:32:13 -04:00
RandyTheSilly 4882dec678 Fix slice bounds errors when editing notes on short entries 2024-03-17 15:59:47 -04:00
RandyTheSilly 6a345d2206 Switch Windows to use ":" instead of "-" for options flags because PowerShell is horrible and interprets "-" as a named parameter 2024-03-14 17:01:12 -04:00
RandyTheSilly 7d91dc5e75 Specify that "mutn init" generates libmutton.ini 2024-03-08 13:15:16 -05:00
RandyTheSilly 81a4fca89d Use panic in editNote to prevent temp files from being left behind 2024-03-08 12:57:10 -05:00
RandyTheSilly 05a15260fd Strip carriage returns from user input 2024-03-08 12:48:19 -05:00
RandyTheSilly 4394020dd2 Properly close files to fix various issues on Windows (fixes GPG keygen, note temp files not being deleted) 2024-03-08 12:19:05 -05:00
RandyTheSilly f8bf12677f Better sanitize user input in inputInt 2024-03-08 11:23:08 -05:00
RandyTheSilly 8e1987f250 Disable sshyp-sync-shim on Windows 2024-03-08 10:43:00 -05:00
RandyTheSilly 5fc2ef81bc Add current UNIX timestamp to generated GPG ID, identify key based on it 2024-03-08 10:36:01 -05:00
RandyTheSilly cd61d3ada3 Manually select auto-generated GPG key due to inconsistent GPG output, use tempfile for gpg-gen 2024-03-08 00:46:22 -05:00
RandyTheSilly d552f03de1 Better detect if fallback editor needs to be used 2024-03-07 23:51:34 -05:00
RandyTheSilly 834b37abda Prevent EntryListGen errors from appearing in-line with header 2024-03-07 23:46:19 -05:00
RandyTheSilly 8fcb8958ce Exit after errors in EntryListGen 2024-03-07 23:43:35 -05:00
RandyTheSilly 27c70e84c8 Remove the gpg-gen file after use 2024-03-07 23:40:35 -05:00
RandyTheSilly 276da8222f Allow automatic generation of GPG keys 2024-03-07 23:35:38 -05:00
RandyTheSilly 7fc1c46018 Allow picking GPG key ID from a generated list 2024-03-07 22:48:57 -05:00
RandyTheSilly 93a1a2209c Implement temporary "init" functionality 2024-03-07 22:12:38 -05:00
RandyTheSilly 865490927b Fixed indentation in main help menu for "edit -r" 2024-03-07 20:38:25 -05:00
RandyTheSilly 8f315fe587 Add TEMPORARY sshyp-sync shim so that MUTN can be tested while native sync is under development 2024-03-07 20:35:24 -05:00
RandyTheSilly 7d5c960fcb Replace TODO comment to correspond with learned information 2024-03-07 20:20:30 -05:00
RandyTheSilly 80f1e27507 Implement note editing 2024-03-07 20:15:01 -05:00
RandyTheSilly c0d141a02e Allow generating new passwords for existing entries 2024-03-07 19:09:23 -05:00
RandyTheSilly b208ea415a Implement initial entry editing support (no notes editing or gen update) 2024-03-07 18:34:12 -05:00
RandyTheSilly e729953cab Implement entry/directory renaming/moving 2024-03-07 17:40:57 -05:00
RandyTheSilly 5bc0ff96c0 Do not print redundant newline after creating a notes-only entry 2024-03-07 16:09:54 -05:00
RandyTheSilly 349fd807b5 Implement password generation on new entries 2024-03-07 16:04:46 -05:00
RandyTheSilly 1982a5c0d6 Do not allow creating empty entries 2024-03-07 12:13:31 -05:00
RandyTheSilly 844b726343 Allow optionally adding notes to new password entries 2024-03-07 12:01:49 -05:00
RandyTheSilly e269b304cd More correctly use build constraints in entryList.go 2024-03-06 20:45:02 -05:00
RandyTheSilly 9606bf6af6 Implement notes editor (required rewrite of offline.ReadConfig) 2024-03-05 17:11:53 -05:00
RandyTheSilly f58c789c60 Implement initial entry adding (partial, missing notes support) 2024-03-05 14:09:50 -05:00
RandyTheSilly b09a1c8132 Greatly reduce code duplication in clipboard implementations 2024-03-03 23:26:39 -05:00
RandyTheSilly e822bd89dc Implement password hiding in entry readouts 2024-03-01 22:11:59 -05:00
RandyTheSilly 3ed3424adc Re-write argument parsing, implement skeleton of copy functionality 2024-03-01 21:09:56 -05:00
RandyTheSilly 1ffd375950 Implement initial entry readout formatting 2024-03-01 18:26:05 -05:00
RandyTheSilly 775d7e605b Do not trim file extensions from entries (file extensions are no longer expected) 2024-03-01 14:07:53 -05:00
RandyTheSilly 61ca2fffa9 Fix initial entry reader shortcut on Windows 2024-03-01 13:47:28 -05:00
RandyTheSilly cdf1b0863e Replace remaining ANSI escape codes with constants 2024-02-27 12:01:35 -05:00
RandyTheSilly e7b3a21cf7 Implement ReadConfig for reading ~/.config/libmutton/libmutton.ini 2024-02-27 11:48:02 -05:00
RandyTheSilly b5cb7f02e1 Fix awkward wording, clarify extension support 2024-02-26 17:16:09 -05:00
RandyTheSilly 3c6eed63ba Split into separate packages 2024-02-26 16:58:39 -05:00
RandyTheSilly 0b9d854a90 Fix incorrect method of simplifying directory headers 2024-01-30 22:06:46 -05:00
RandyTheSilly 4ccae3e5a8 Initial code commit 2024-01-16 14:35:34 -05:00
Randall Winkhart 53e0799a4a Initial commit 2024-01-16 12:33:11 -05:00
61 changed files with 509 additions and 2100 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
/mutn
/mutn.exe
/libmuttonserver
/libmuttonserver.exe
/main
/main.exe
/version.go
output
1output
+35 -23
View File
@@ -2,7 +2,7 @@
---
Pronounced as: "mutton", "muh·tn"
MUTN is a simple, self-hosted, SSH-synchronized password and note manager based on libmutton. It is the successor to [sshyp](https://github.com/rwinkhart/sshyp).
MUTN is a simple, self-hosted, SSH-synchronized password and note manager based on [libmutton](https://github.com/rwinkhart/libmutton). It is the successor to [sshyp](https://github.com/rwinkhart/sshyp).
> [!WARNING]
>It is your responsibility to assess the security and stability of MUTN and to ensure it meets your needs before using it.
@@ -16,31 +16,43 @@ MUTN is a simple, self-hosted, SSH-synchronized password and note manager based
MUTN aims to make it as easy as possible to manage passwords and notes via CLI across multiple devices in a secure, self-hosted fashion.
# Installation/Building
See the [installation guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/install.md).
See the [installation guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/install.md).
Additionally, MUTN is available as a source package ("[mutn](https://aur.archlinux.org/packages/mutn)") on the AUR.
After installing, please review the [usage guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/usage.md).
# Roadmap
#### Release v0.2.1
- [ ] Only run getSSHClient once to prevent being asked for keyfile password multiple times
- [ ] After this, handle all errors in client.go
- [ ] Ensure all config files and entry files are created with 0600 permissions
- [ ] Add fail-specific error codes
- [ ] Split into separate repos
1. libmutton
2. libmutton-server
3. MUTN
#### Release v0.3.0
- [ ] Replace Glamour with a more minimal Markdown renderer (likely custom)
#### Release v0.4.0
- [ ] Swap to native (cascade) encryption (custom)
- [ ] Implement "netpin" (quick-unlock) with new encryption
#### Release v0.5.0
- [ ] Password aging support
- [ ] Append UNIX timestamp to entry names
- [ ] Add yellow/red dot indicators to entry list readout for when passwords should be changed
#### Release v0.6.0
### Release v0.3.0
- [ ] libmutton v0.3.0
- [ ] Add refresh/re-encrypt functionality
- [ ] Re-implement init menu
- [ ] Implement tweak menu
- [ ] Add refresh/re-encrypt functionality
#### Release v1.0.0 - Distribution packages
- [ ] Bump Glamour version and switch to fully-compliant Markdown (do not preserve new lines)
- [x] Add experimental build option for building with [BEAN](https://github.com/Trojan2021/BEAN) instead of Glamour
### Release v0.4.0
- [ ] Evaluate defaulting to building w/Bean over Glamour
- [ ] Verify having Glamour in go.mod does not impact binary size/speed (drop it if it does)
### Release v0.5.0
- [ ] libmutton v0.4.0
- [ ] Password aging support
- [ ] Append UNIX timestamp to entry names
- [ ] Trim timestamps to allow for vanity entry names in the following cases:
- [ ] Argument parsing
- [ ] Shell completions
- [ ] Entry list readout
- [ ] Add yellow/red dot indicators to entry list readout for when passwords should be changed
### Release v0.6.0
- [ ] libmutton v0.5.0
- [ ] Swap to native (cascading) encryption
- [ ] Implement "netpin" (quick-unlock) with new encryption
### Release v1.0.0 - Distribution packages
- [ ] Evaluate implementing custom types/interfaces (where applicable)
- [ ] Create packaging scripts
- [x] Stable source PKGBUILD
- [x] Stable source APKBUILD
- [ ] Debian/Ubuntu
- [ ] Fedora
- [ ] FreeBSD
- [ ] Windows installer
- Perform extensive testing
-4
View File
@@ -1,4 +0,0 @@
#!/bin/sh
gofmt -l -w -s ./src/cli/*.go ./src/backend/*.go ./mutn.go ./libmuttonserver.go
git commit -am "$1"
git push
+25 -3
View File
@@ -1,4 +1,4 @@
.TH MUTN 1 "06 August 2024" "v0.2.0" "MUTN man page"
.TH MUTN 1 "13 December 2024" "v0.2.4" "MUTN man page"
.SH NAME
\fBmutn\fR - Simple, self-hosted, SSH-synchronized password and note management based on libmutton. It is the successor to sshyp.
@@ -144,8 +144,30 @@ Once this has been done, you may proceed with the client setup:
...and then restart your shell.
.SH EXIT CODES
TBD
.SH EXIT CODES (defined by libmutton)
0: no error
101: read error
102: write error
103: sync process error
104: server connection error
105: target not found
106: target already exists
107: target wrong type (file/directory)
108: decryption error
109: encryption error
110: clipboard error
111: other error
.SH AUTHOR
Randall Winkhart (https://github.com/rwinkhart)
+112 -3
View File
@@ -1,4 +1,113 @@
**WARNING: AS MUTN HAS NOT YET REACHED v1.0.0, [BREAKING CHANGES](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/breaking.md) IN FUTURE UPDATES ARE PLANNED**
**WARNING: AS LIBMUTTON HAS NOT YET REACHED v1.0.0, [BREAKING CHANGES](https://github.com/rwinkhart/libmutton/blob/main/wiki/breaking.md) IN FUTURE UPDATES ARE PLANNED**
**MUTN v0.2.4**
Built with libmutton v0.2.4
December 13, 2024
# The Tripe Transmission Update - Patch 4
This release updates libmutton to v0.2.4 and includes only a minor tweak and some dependency bumps.
## IMPORTANT
- This release includes a dependency bump to address a high-severity CVE (CVE-2024-45337) - Please update as soon as possible!
## Changes
- A build option/tag was added (`BEAN`) for building with experimental [BEAN](https://github.com/Trojan2021/BEAN) Markdown rendering support (instead of Glamour)
- Note that the BEAN Markdown renderer is a new project and is **not** near complete
- The pre-compiled binaries provided below do **not** make use of this new build tag (they are still Glamour-based)
- From libmutton v0.2.4:
- The MIME type of data copied to the clipboard on UNIX-like systems (X11 and Wayland) is now statically set to "text/plain" to avoid potential issues with type inference
## Dependencies
- Bumps (direct and indirect)
- Go: v1.23.2 => 1.23.4
- github.com/rwinkhart/libmutton: v0.2.3 => v0.2.4
- github.com/charmbracelet/x/ansi: v0.4.0 => v0.5.2
- github.com/pkg/sftp: v1.13.6 => v1.13.7
- golang.org/x/crypto: v0.28.0 => v0.31.0
- golang.org/x/net: v0.30.0 => v0.32.0
- golang.org/x/sys: v0.26.0 => v0.28.0
- golang.org/x/term: v0.25.0 => v0.27.0
---
**MUTN v0.2.3**
Built with libmutton v0.2.3
October 19, 2024
# The Tripe Transmission Update - Patch 3
This release updates libmutton to v0.2.3 to fix a minor bug causing the client to make a request to the server under an inappropriate condition.
## Fixes
- From libmutton v0.2.3:
- Fixed renaming/moving an entry/folder to an invalid path still having clients request the operation on the server
## Dependencies
- Bumps (direct and indirect)
- Go: v1.22.6 => 1.23.2
- github.com/rwinkhart/libmutton: v0.2.2 => v0.2.3
- github.com/yuin/goldmark: v1.7.4 => v1.7.8
- github.com/yuin/goldmark-emoji: v1.0.3 => v1.0.4
- golang.org/x/crypto: v0.26.0 => v0.28.0
- golang.org/x/net: v0.28.0 => v0.30.0
- golang.org/x/sys: v0.24.0 => v0.26.0
- golang.org/x/term: v0.23.0 => v0.25.0
---
**MUTN v0.2.2**
Built with libmutton v0.2.2
August 20, 2024
# The Tripe Transmission Update - Patch 2
This release updates libmutton to v0.2.2 to address a regression from v0.2.1. Additionally, a Windows-only entry adding bug has been fixed.
## Fixes
- From libmutton v0.2.2:
- Edited entries are no longer improperly synced if their line count is reduced
- (8c1b986e20bf8e02b4b27e18748f7677be2b2743) Adding new entries from Windows now works as intended
## Dependencies
- Bumps (direct and indirect)
- github.com/rwinkhart/libmutton: v0.2.1 => v0.2.2
---
**MUTN v0.2.1**
Built with libmutton v0.2.1
August 13, 2024
# The Tripe Transmission Update - Patch 1
This release marks the completion of splitting MUTN and [libmutton](https://github.com/rwinkhart/libmutton) into separate repositories. The server binary must now be downloaded from the [libmutton releases page](https://github.com/rwinkhart/libmutton/releases).
Please see the [installation guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/install.md) for updated instructions.
## Breaking Changes
- The server binary must also be updated to v0.2.1 (grab it [here](https://github.com/rwinkhart/libmutton/releases/tag/v0.2.1))
## Features
- From libmutton v0.2.1:
- MUTN will now remove the previous device ID from the server when creating a new one
- Exit codes are now specific to the type of error encountered
## Fixes
- From libmutton v0.2.1:
- The user is no longer prompted for their ssh keyfile passphrase multiple times during synchronization
- Config/entry files are now created with 0600 permissions
- The TOTP copy message is no longer unnecessarily verbose
- Function documentation is now properly formatted for display on pkg.go.dev
## Dependencies
- Bumps (direct and indirect)
- golang.org/x/sys: v0.23.0 => v0.24.0
- New (direct)
- github.com/rwinkhart/libmutton: v0.2.1
- Was previously included in this repo
---
**MUTN v0.2.0**
August 06, 2024
@@ -55,11 +164,11 @@ Compared to v0.1.0, this version adds fully native SSH synchronization with self
- github.com/pkg/sftp: v1.13.6
## Installation Notes
Though this is the initial public debut, it is still an overall early release of MUTN/libmutton. Because of this, no distribution packages are provided as of yet. Please see the [install guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/install.md) for help installing or building MUTN in its current state (as well as getting started).
Though this is the initial public debut, it is still an overall early release of MUTN/libmutton. Because of this, no distribution packages are provided as of yet. MUTN is, however, available as a source package from the AUR as "mutn". Please see the [install guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/install.md) for help installing or building MUTN in its current state (as well as getting started).
Note that libmuttonserver, libmutton, and MUTN have not yet been separated into their own respective repos (this will be done for v0.2.1). As such, libmuttonserver is built with the `noMarkdown` build tag to avoid pulling in Glamour and its dependencies.
It is highly recommended to also install the relevant [shell completions](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/completions.md).
It is highly recommended to also install the relevant [shell completions](https://github.com/rwinkhart/MUTN/blob/main/wiki/completions.md).
---
+15 -11
View File
@@ -1,15 +1,12 @@
module github.com/rwinkhart/MUTN
go 1.22.6
go 1.23.4
require (
github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514
github.com/charmbracelet/glamour v0.7.0
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727
github.com/pkg/sftp v1.13.6
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481
golang.org/x/crypto v0.26.0
golang.org/x/term v0.23.0
gopkg.in/ini.v1 v1.67.0
github.com/rwinkhart/libmutton v0.2.4
golang.org/x/term v0.27.0
)
require (
@@ -17,7 +14,9 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/boombuler/barcode v1.0.2 // indirect
github.com/charmbracelet/x/ansi v0.5.2 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
@@ -27,10 +26,15 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/sftp v1.13.7 // indirect
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rwinkhart/convertroman v0.2.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/yuin/goldmark v1.7.4 // indirect
github.com/yuin/goldmark-emoji v1.0.3 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
github.com/yuin/goldmark v1.7.8 // indirect
github.com/yuin/goldmark-emoji v1.0.4 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sys v0.28.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
+37 -19
View File
@@ -1,3 +1,5 @@
github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514 h1:PbqBQdkQ51VLfwemHdp3DqDAeMoPqzGSK39ZtFHJLG0=
github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514/go.mod h1:Xkl7xpjhrhefSpFAJEc1uNIarmVU+EFASB8VLODTOsA=
github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE=
github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=
@@ -13,6 +15,8 @@ github.com/boombuler/barcode v1.0.2 h1:79yrbttoZrLGkL/oOI8hBrUKucwOL0oOjUgEguGMc
github.com/boombuler/barcode v1.0.2/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng=
github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps=
github.com/charmbracelet/x/ansi v0.5.2 h1:dEa1x2qdOZXD/6439s+wF7xjV+kZLu/iN00GuXXrU9E=
github.com/charmbracelet/x/ansi v0.5.2/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -42,8 +46,8 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pkg/sftp v1.13.6 h1:JFZT4XbOU7l77xGSpOdW+pwIMqP044IyjXX6FGyEKFo=
github.com/pkg/sftp v1.13.6/go.mod h1:tz1ryNURKu77RL+GuCzmoJYxQczL3wLNNpPWagdg4Qk=
github.com/pkg/sftp v1.13.7 h1:uv+I3nNJvlKZIQGSr8JVQLNHFU9YhhNpvC14Y6KgmSM=
github.com/pkg/sftp v1.13.7/go.mod h1:KMKI0t3T6hfA+lTR/ssZdunHo+uwq7ghoN09/FSu3DY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 h1:FkxbO331O7mS5EJkP+MCi0o2gswh/Aezs+//NmefrR8=
@@ -52,6 +56,10 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rwinkhart/convertroman v0.2.0 h1:otUm939eXT77q/Lr31mJtMwVWEw0RjEUB71gO65h9OM=
github.com/rwinkhart/convertroman v0.2.0/go.mod h1:Af6HqvX0EIM4Y3HcnNXbbRey1dLasGB7WU0+3Cowgmw=
github.com/rwinkhart/libmutton v0.2.4 h1:Uu/Xjgeau1YiEztTaEeVQONopXuGVKty+gIb/xA6jQ8=
github.com/rwinkhart/libmutton v0.2.4/go.mod h1:PdB+cyRsd3F4Uwxx8EJCRraJTwbvvrynY9iQVr/V+Wg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -61,45 +69,55 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
github.com/yuin/goldmark-emoji v1.0.3 h1:aLRkLHOuBR2czCY4R8olwMjID+tENfhyFDMCRhbIQY4=
github.com/yuin/goldmark-emoji v1.0.3/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
github.com/yuin/goldmark-emoji v1.0.4 h1:vCwMkPZSNefSUnOW2ZKRUjBSD5Ok3W78IXhGxxAEF90=
github.com/yuin/goldmark-emoji v1.0.4/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
-92
View File
@@ -1,92 +0,0 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/cli"
"github.com/rwinkhart/MUTN/src/sync"
)
func main() {
args := os.Args
if len(args) < 2 {
helpServer()
}
// check if stdin was provided
stdinInfo, _ := os.Stdin.Stat()
stdinPresent := stdinInfo.Mode()&os.ModeNamedPipe != 0
var stdin []string
if stdinPresent {
// read stdin, appending each line to the stdin slice
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
stdin = append(stdin, scanner.Text())
}
}
switch args[1] {
case "fetch":
// print all information needed for syncing to stdout for interpretation by the client
// stdin[0] is expected to be the device ID
sync.GetRemoteDataFromServer(stdin[0])
case "rename":
// move an entry to a new location before using fallthrough to add its previous iteration to the deletions directory
// stdin[0] is evaluated after fallthrough
// stdin[1] is expected to be the OLD incomplete target location with FSPath representing path separators - always pass in UNIX format
// stdin[2] is expected to be the NEW incomplete target location with FSPath representing path separators - always pass in UNIX format
sync.RenameLocal(strings.ReplaceAll(stdin[1], sync.FSPath, "/"), strings.ReplaceAll(stdin[2], sync.FSPath, "/"), true)
fallthrough // fallthrough to add the old entry to the deletions directory
case "shear":
// shear an entry from the server and add it to the deletions directory
// stdin[0] is expected to be the device ID
// stdin[1] is expected to be the incomplete target location with FSPath representing path separators - always pass in UNIX format
sync.ShearLocal(strings.ReplaceAll(stdin[1], sync.FSPath, "/"), stdin[0])
case "addfolder":
// add a new folder to the server
// stdin[0] is expected to be the incomplete target location with FSPath representing path separators - always pass in UNIX format
sync.AddFolderLocal(strings.ReplaceAll(stdin[0], sync.FSPath, "/"))
case "register":
// register a new device ID
// stdin[0] is expected to be the device ID
_, _ = os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + stdin[0]) // error ignored; failure unlikely to occur if init was successful; "register" is not a user-facing argument and thus the error would not be visible
// print EntryRoot and bool indicating OS type to stdout for client to store in config
fmt.Print(backend.EntryRoot + sync.FSSpace + strconv.FormatBool(backend.IsWindows))
case "init":
// create the necessary directories for libmuttonserver to function
backend.DirInit(false)
_ = os.MkdirAll(backend.ConfigDir+backend.PathSeparator+"deletions", 0700) // error ignored; failure would have occurred by this point in backend.DirInit
fmt.Println("libmuttonserver directories initialized")
case "version":
versionServer()
default:
helpServer()
}
}
func helpServer() {
fmt.Print(cli.AnsiBold + "\nlibmuttonserver | Copyright (c) 2024 Randall Winkhart\n" + backend.AnsiReset + `
This software exists under the MIT license; you may redistribute it under certain conditions.
This program comes with absolutely no warranty; type "libmuttonserver version" for details.
` + cli.AnsiBold + "Usage:" + backend.AnsiReset + ` libmuttonserver <argument>
` + cli.AnsiBold + "Arguments (user):" + backend.AnsiReset + `
help Bring up this menu
version Display version and license information
init Create the necessary directories for libmuttonserver to function` + "\n\n")
os.Exit(0)
}
func versionServer() {
cli.MITLicense()
fmt.Print(cli.AnsiBold + "\n\n libmuttonserver" + backend.AnsiReset + " Version " + backend.LibmuttonVersion + `
Copyright (c) 2024 Randall Winkhart` + "\n\n")
}
+9 -9
View File
@@ -5,9 +5,9 @@ import (
"os"
"strings"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/cli"
"github.com/rwinkhart/MUTN/src/sync"
"github.com/rwinkhart/libmutton/core"
"github.com/rwinkhart/libmutton/sync"
)
func main() {
@@ -25,7 +25,7 @@ func main() {
if strings.HasPrefix(args[1], "/") {
// store location of target entry
targetLocation := backend.TargetLocationFormat(args[1])
targetLocation := core.TargetLocationFormat(args[1])
// entry reader shortcut (if no other arguments are supplied)
if argsCount == 2 {
@@ -38,7 +38,7 @@ func main() {
case "show", "-s":
cli.EntryReaderDecrypt(targetLocation, false)
case "copy":
backend.CopyArgument(args[0], targetLocation, 0)
core.CopyArgument(args[0], targetLocation, 0)
case "edit":
cli.EditEntryField(targetLocation, true, 0)
case "gen":
@@ -82,7 +82,7 @@ func main() {
default:
cli.HelpCopy()
}
backend.CopyArgument(args[0], targetLocation, field)
core.CopyArgument(args[0], targetLocation, field)
case "edit":
var field int // indicates which (numbered) field to edit
switch args[3] {
@@ -97,8 +97,8 @@ func main() {
case "note", "-n":
field = 4
case "rename", "-r":
backend.TargetIsFile(targetLocation, true, 0) // ensure location exists before prompting for new location
cli.RenameCli(args[1]) // pass the incomplete path as the server and all clients (reading from the deletions directory) will have a different home directory
core.TargetIsFile(targetLocation, true, 0) // ensure location exists before prompting for new location
cli.RenameCli(args[1]) // pass the incomplete path as the server and all clients (reading from the deletions directory) will have a different home directory
default:
cli.HelpEdit()
}
@@ -158,13 +158,13 @@ func main() {
} else {
switch args[1] {
case "clipclear":
backend.ClipClearArgument()
core.ClipClearArgument()
case "sync":
sync.RunJob(true)
case "init":
cli.TempInitCli()
case "tweak":
fmt.Println(backend.AnsiError + "\"tweak\" is not yet implemented" + backend.AnsiReset)
fmt.Println(core.AnsiError + "\"tweak\" is not yet implemented" + core.AnsiReset)
os.Exit(0)
case "copy":
cli.HelpCopy()
+16 -8
View File
@@ -1,9 +1,9 @@
#!/bin/sh
# get version number from LibmuttonVersion
# get version number from cli package
cd ..
printf 'package main\nimport (\n"fmt"\n"github.com/rwinkhart/MUTN/src/backend"\n)\nfunc main() {\nfmt.Println(backend.LibmuttonVersion)\n}' > ./version.go
version=$(go run ./version.go)
printf 'package main\nimport (\n"fmt"\n"github.com/rwinkhart/MUTN/src/cli"\n)\nfunc main() {\nfmt.Println(cli.MUTNVersion)\n}' > ./version.go
version=$(go run -ldflags="-s -w" -tags noMarkdown ./version.go)
rm ./version.go
cd ./packaging
@@ -15,14 +15,22 @@ else
fi
# ensure output directory exists
mkdir -p ./output
mkdir -p ./1output
case "$1" in
pkgbuild-git-stable)
. ./pkgbuild-git-stable.sh
create_pkgbuild_git_stable
release-binaries)
. ./resources/release-binaries.sh
create_release_binaries
;;
pkgbuild-git-stable-optimized)
. ./resources/pkgbuild-git-stable-optimized.sh
create_pkgbuild_git_stable_optimized
;;
apkbuild-source-stable-optimized)
. ./resources/apkbuild-source-stable-optimized.sh
create_apkbuild_source_stable_optimized
;;
*)
printf '\nusage: package.sh [target] <revision>\n\ntargets: pkgbuild-git-stable\n\n'
printf '\nusage: package.sh [target] <revision>\n\ntargets: release-binaries pkgbuild-git-stable-optimized apkbuild-source-stable-optimized\n\n'
;;
esac
@@ -0,0 +1,61 @@
#!/bin/sh
create_apkbuild_source_stable_optimized() {
printf '\nGenerating APKBUILD...\n'
local source="https://github.com/rwinkhart/MUTN/archive/refs/tags/v"$version".tar.gz"
local checksum=$(curl -sL "$source" | sha512sum | cut -d ' ' -f1)
printf "# Maintainer: Randall Winkhart <idgr@tutanota.com>
pkgname=mutn
pkgver="$version"
pkgrel="$((revision-1))"
pkgdesc='A simple, self-hosted, SSH-synchronized password/note manager for the CLI (based on libmutton)'
arch='all'
url='https://github.com/rwinkhart/MUTN'
license='MIT'
depends='gnupg'
makedepends='busybox go'
options='!check net'
source=\"\$pkgname-\$pkgver.tar.gz::"$source"\"
build() {
cd \${srcdir}/MUTN-\$pkgver
# compress man page
gzip -kf ./docs/man
# determine microarchitecture feature level
case \$CARCH in
'x86_64')
cpuFlags=\$(grep -E 'flags\s+:\s' /proc/cpuinfo)
if [ ! -z \"\$(echo \"\$cpuFlags\" | grep 'avx512f')\" ]; then
export GOAMD64=v4
elif [ ! -z \"\$(echo \"\$cpuFlags\" | grep 'avx2')\" ]; then
export GOAMD64=v3
elif [ ! -z \"\$(echo \"\$cpuFlags\" | grep 'sse4_2')\" ]; then
export GOAMD64=v2
else
export GOAMD64=v1
fi
;;
# TODO check aarch64 feature level
esac
# compile binary
CGO_ENABLED=1 go build -ldflags=\"-s -w\" -trimpath ./mutn.go
}
package() {
cd \${srcdir}/MUTN-\$pkgver
install -Dm755 ./mutn \${pkgdir}/usr/bin/mutn
install -Dm644 ./LICENSE \${pkgdir}/usr/share/licenses/mutn/LICENSE
install -Dm644 ./completions/zsh/_mutn \${pkgdir}/usr/share/zsh/site-functions/_mutn
install -Dm644 ./completions/bash/mutn \${pkgdir}/usr/share/bash-completion/completions/mutn
install -Dm644 ./docs/man.gz \${pkgdir}/usr/share/man/man1/mutn.1.gz
}
sha512sums=\"
$checksum \$pkgname-\$pkgver.tar.gz
\"
" > 1output/APKBUILD
printf '\nAPKBUILD generated\n\n'
}
@@ -1,17 +1,18 @@
#!/bin/sh
create_pkgbuild_git_stable() {
printf '\ngenerating PKGBUILD...\n'
create_pkgbuild_git_stable_optimized() {
printf '\nGenerating PKGBUILD...\n'
local source="git+https://github.com/rwinkhart/MUTN.git#tag=v\${pkgver}"
printf "# Maintainer: Randall Winkhart <idgr at tutanota dot com>
pkgname=mutn
pkgver="$version"
pkgrel="$revision"
pkgdesc='A simple, self-hosted, SSH-synchronized password/note manager based on libmutton'
pkgdesc='A simple, self-hosted, SSH-synchronized password/note manager for the CLI (based on libmutton)'
arch=('x86_64' 'i686' 'i486' 'pentium4' 'aarch64' 'armv7h' 'riscv64')
url='https://github.com/rwinkhart/MUTN'
license=('MIT')
makedepends=(go util-linux)
depends=(gnupg)
makedepends=(go grep gzip)
optdepends=(
'wl-clipboard: Wayland clipboard support'
'xclip: X11 clipboard support'
@@ -21,15 +22,20 @@ source=(\""$source"\")
sha512sums=(SKIP)
build() {
cd \${srcdir}/MUTN
# compress man page
gzip -kf ./docs/man
# determine microarchitecture feature level
case \$CARCH in
'x86_64')
lscpuOutput=\$(lscpu | grep Flags)
if [ -z \"\$(echo \$lscpuOutput | grep avx512f)\" ]; then
cpuFlags=\$(grep -E 'flags\s+:\s' /proc/cpuinfo)
if [ ! -z \"\$(grep 'avx512f' <<< \"\$cpuFlags\")\" ]; then
export GOAMD64=v4
elif [ -z \"\$(echo \$lscpuOutput | grep avx2)\" ]; then
elif [ ! -z \"\$(grep 'avx2' <<< \"\$cpuFlags\")\" ]; then
export GOAMD64=v3
elif [ -z \"\$(echo \$lscpuOutput | grep sse4_2)\" ]; then
elif [ ! -z \"\$(grep 'sse4_2' <<< \"\$cpuFlags\")\" ]; then
export GOAMD64=v2
else
export GOAMD64=v1
@@ -38,7 +44,7 @@ build() {
# TODO check aarch64 feature level
esac
cd \${srcdir}/MUTN
# compile binary
CGO_ENABLED=1 go build -ldflags=\"-s -w\" -trimpath ./mutn.go
}
@@ -48,7 +54,8 @@ package() {
install -Dm644 ./LICENSE \${pkgdir}/usr/share/licenses/mutn/LICENSE
install -Dm644 ./completions/zsh/_mutn \${pkgdir}/usr/share/zsh/site-functions/_mutn
install -Dm644 ./completions/bash/mutn \${pkgdir}/usr/share/bash-completion/completions/mutn
install -Dm644 ./docs/man.gz \${pkgdir}/usr/share/man/man1/mutn.1.gz
}
" > output/PKGBUILD
" > 1output/PKGBUILD
printf '\nPKGBUILD generated\n\n'
}
+11
View File
@@ -0,0 +1,11 @@
#!/bin/sh
create_release_binaries() {
printf '\nGenerating release binaries...\n'
cd ..
GOOS=linux CGO_ENABLED=0 GOAMD64=v1 go build -o ./packaging/1output/mutn-linux-x86_64_v1 -ldflags="-s -w" -trimpath ./mutn.go
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o ./packaging/1output/mutn-linux-aarch64 -ldflags="-s -w" -trimpath ./mutn.go
GOOS=windows CGO_ENABLED=0 GOAMD64=v1 go build -o ./packaging/1output/mutn-windows-x86_64_v1.exe -ldflags="-s -w" -trimpath ./mutn.go
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -o ./packaging/1output/mutn-windows-aarch64.exe -ldflags="-s -w" -trimpath ./mutn.go
cd ./packaging
}
-17
View File
@@ -1,17 +0,0 @@
package backend
import (
"os"
)
// global variables used across multiple files
var (
Home, _ = os.UserHomeDir()
)
// global constants used across multiple files
const (
AnsiError = "\033[38;5;9m"
AnsiReset = "\033[0m"
LibmuttonVersion = "0.2.0" // untagged releases feature a letter suffix corresponding to the eventual release version, e.g "0.2.A" -> "0.2.0", "0.2.B" -> "0.2.1"
)
-20
View File
@@ -1,20 +0,0 @@
//go:build !windows
package backend
// EntryRoot path to libmutton entry directory
var EntryRoot = Home + "/.local/share/libmutton"
var ConfigDir = Home + "/.config/libmutton"
var ConfigPath = ConfigDir + "/libmutton.ini"
// PathSeparator defines the character used to separate directories in a path (platform-specific)
const (
PathSeparator = "/"
IsWindows = false
)
// enableVirtualTerminalProcessing is a dummy function on UNIX-like systems (only needed on Windows)
// TODO remove after migration off of GPG, as pinentry is responsible for disabling ANSI escape sequence interpretation
func enableVirtualTerminalProcessing() {
return
}
-31
View File
@@ -1,31 +0,0 @@
//go:build windows
package backend
import (
"os"
"syscall"
)
// EntryRoot path to libmutton entry directory
var EntryRoot = Home + "\\AppData\\Local\\libmutton\\entries"
var ConfigDir = Home + "\\AppData\\Local\\libmutton\\config"
var ConfigPath = ConfigDir + "\\libmutton.ini"
// PathSeparator defines the character used to separate directories in a path (platform-specific)
const (
PathSeparator = "\\"
IsWindows = true
)
// enableVirtualTerminalProcessing ensures ANSI escape sequences are interpreted properly on Windows
// TODO remove after migration off of GPG, as pinentry is responsible for disabling ANSI escape sequence interpretation
func enableVirtualTerminalProcessing() {
stdout := syscall.Handle(os.Stdout.Fd())
var originalMode uint32
syscall.GetConsoleMode(stdout, &originalMode)
originalMode |= 0x0004
syscall.MustLoadDLL("kernel32").MustFindProc("SetConsoleMode").Call(uintptr(stdout), uintptr(originalMode))
}
-86
View File
@@ -1,86 +0,0 @@
package backend
import (
"fmt"
"os"
"gopkg.in/ini.v1"
)
// loadConfig loads the libmutton.ini file and returns the configuration
// utility function for ParseConfig and WriteConfig, do not call directly
func loadConfig() *ini.File {
cfg, err := ini.Load(ConfigPath)
if err != nil {
fmt.Println(AnsiError + "Failed to load libmutton.ini: " + err.Error() + AnsiReset)
os.Exit(1)
}
return cfg
}
// ParseConfig reads the libmutton.ini file and returns a slice of values for the specified keys
// requires requestedValues: a slice of arrays (length 2) each containing a section and a key name
// requires missingValueError: an error message to display if a key is missing a value, set to "" for auto-generated or "0" to exit/return silently with code 0
// returns config: a slice of values for the specified keys
func ParseConfig(valuesRequested [][2]string, missingValueError string) []string {
cfg := loadConfig()
var config []string
for _, pair := range valuesRequested {
value := cfg.Section(pair[0]).Key(pair[1]).String()
// ensure specified key has a value
if value == "" {
switch missingValueError {
case "":
fmt.Println(AnsiError + "Failed to find value for key \"" + pair[1] + "\" in section \"[" + pair[0] + "]\" in libmutton.ini" + AnsiReset)
case "0":
Exit(0)
default:
fmt.Println(AnsiError + missingValueError + AnsiReset)
}
os.Exit(1)
}
config = append(config, value)
}
return config
}
// WriteConfig writes the provided key-value pairs under the specified section headers in the libmutton.ini file
// requires valuesToWrite: a slice of arrays (length 3) each containing a section, a key name, and a value
func WriteConfig(valuesToWrite [][3]string, append bool) {
var cfg *ini.File
if append {
// load existing ini file
cfg = loadConfig()
} else {
// create empty ini container
cfg = ini.Empty()
}
// set all specified key-value pairs in their respective sections
var section *ini.Section
for _, trio := range valuesToWrite {
if cfg.Section(trio[0]) == nil {
// create and aquire section if it doesn't exist
section, _ = cfg.NewSection(trio[0])
} else {
// acquire existing section
section = cfg.Section(trio[0])
}
// set key-value pair
section.Key(trio[1]).SetValue(trio[2])
}
// save to libmutton.ini
err := cfg.SaveTo(ConfigPath)
if err != nil {
fmt.Println(AnsiError + "Failed to save libmutton.ini: " + err.Error() + AnsiReset)
os.Exit(1)
}
}
-91
View File
@@ -1,91 +0,0 @@
package backend
import (
"bufio"
"fmt"
"os"
"strings"
"time"
steamtotp "github.com/fortis/go-steam-totp"
"github.com/pquerna/otp/totp"
)
// CopyArgument copies a field from an entry to the clipboard
func CopyArgument(executableName, targetLocation string, field int) {
if isFile, _ := TargetIsFile(targetLocation, true, 2); isFile {
decryptedEntry := DecryptGPG(targetLocation)
var copySubject string // will store data to be copied
// ensure field exists in entry
if len(decryptedEntry) > field {
// ensure field is not empty
if decryptedEntry[field] == "" {
fmt.Println(AnsiError + "Field is empty" + AnsiReset)
os.Exit(1)
}
if field != 2 {
copySubject = decryptedEntry[field]
} else { // TOTP mode
var secret string // stores secret for TOTP generation
var forSteam bool // indicates whether to generate TOTP in Steam format
if strings.HasPrefix(decryptedEntry[2], "steam@") {
secret = decryptedEntry[2][6:]
forSteam = true
} else {
secret = decryptedEntry[2]
}
fmt.Println("TOTP code has been copied to the clipboard - your clipboard will be kept up to date with the current code until this process is closed")
for { // keep field copied to clipboard, refresh on 30-second intervals
currentTime := time.Now()
copyField("", GenTOTP(secret, currentTime, forSteam))
// sleep until next 30-second interval
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
}
}
} else {
fmt.Println(AnsiError + "Field does not exist in entry" + AnsiReset)
os.Exit(1)
}
// copy field to clipboard, launch clipboard clearing process
copyField(executableName, copySubject)
}
}
// ClipClearArgument is called to clear the clipboard after 30 seconds if the contents have not been modified
func ClipClearArgument() {
// read previous clipboard contents from stdin
clipScanner := bufio.NewScanner(os.Stdin)
if clipScanner.Scan() {
oldContents := clipScanner.Text()
clipClear(oldContents)
} else {
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
}
}
// GenTOTP generates a TOTP token from a secret (supports standard and Steam TOTP)
func GenTOTP(secret string, time time.Time, forSteam bool) string {
var totpToken string
var err error
if forSteam {
totpToken, err = steamtotp.GenerateAuthCode(secret, time)
} else {
totpToken, err = totp.GenerateCode(secret, time)
}
if err != nil {
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
os.Exit(1)
}
return totpToken
}
-59
View File
@@ -1,59 +0,0 @@
//go:build darwin
package backend
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
)
// TODO MacOS support is entirely untested - I would appreciate feedback on this implementation
// copyField copies a field from an entry to the clipboard
func copyField(executableName, copySubject string) {
cmd := exec.Command("pbcopy")
writeToStdin(cmd, copySubject)
err := cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
// launch clipboard clearing process if executableName is provided
if executableName != "" {
cmd = exec.Command(executableName, "clipclear")
writeToStdin(cmd, copySubject)
err = cmd.Start()
if err != nil {
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
os.Exit(1)
}
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
}
}
// clipClear is called in a separate process to clear the clipboard after 30 seconds
func clipClear(oldContents string) {
time.Sleep(30 * time.Second)
cmd := exec.Command("pbpaste")
newContents, err := cmd.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to read clipboard contents: " + err.Error() + AnsiReset)
os.Exit(1)
}
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
cmd = exec.Command("pbcopy")
writeToStdin(cmd, "")
err = cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
}
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
}
-57
View File
@@ -1,57 +0,0 @@
//go:build linux && termux
package backend
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
)
// copyField copies a field from an entry to the clipboard
func copyField(executableName, copySubject string) {
cmd := exec.Command("termux-clipboard-set")
writeToStdin(cmd, copySubject)
err := cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
// launch clipboard clearing process if executableName is provided
if executableName != "" {
cmd = exec.Command(executableName, "clipclear")
writeToStdin(cmd, copySubject)
err = cmd.Start()
if err != nil {
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
os.Exit(1)
}
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
}
}
// clipClear is called in a separate process to clear the clipboard after 30 seconds
func clipClear(oldContents string) {
time.Sleep(30 * time.Second)
cmd := exec.Command("termux-clipboard-get")
newContents, err := cmd.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to read clipboard contents: " + err.Error() + AnsiReset)
os.Exit(1)
}
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
cmd = exec.Command("termux-clipboard-set")
writeToStdin(cmd, "")
err = cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
}
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
}
-81
View File
@@ -1,81 +0,0 @@
//go:build !windows && !darwin && !termux && !wsl
package backend
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
)
// copyField copies a field from an entry to the clipboard
func copyField(executableName, copySubject string) {
var envSet bool // track whether environment variables are set
var cmd *exec.Cmd
// determine whether to use wl-copy (Wayland) or xclip (X11)
if _, envSet = os.LookupEnv("WAYLAND_DISPLAY"); envSet {
cmd = exec.Command("wl-copy")
} else if _, envSet = os.LookupEnv("DISPLAY"); envSet {
cmd = exec.Command("xclip", "-sel", "c")
} else {
fmt.Println(AnsiError + "Clipboard platform could not be determined - note that the clipboard does not function in a raw TTY" + AnsiReset)
os.Exit(1)
}
writeToStdin(cmd, copySubject)
err := cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
// launch clipboard clearing process if executableName is provided
if executableName != "" {
cmd = exec.Command(executableName, "clipclear")
writeToStdin(cmd, copySubject)
err = cmd.Start()
if err != nil {
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
os.Exit(1)
}
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
}
}
// clipClear is called in a separate process to clear the clipboard after 30 seconds
func clipClear(oldContents string) {
time.Sleep(30 * time.Second)
// determine clipboard tool to use (wl-clipboard VS xclip)
var envSet bool
var cmdClear, cmdPaste *exec.Cmd
if _, envSet = os.LookupEnv("WAYLAND_DISPLAY"); envSet {
cmdClear = exec.Command("wl-copy", "-c")
cmdPaste = exec.Command("wl-paste")
} else if _, envSet = os.LookupEnv("DISPLAY"); envSet {
cmdClear = exec.Command("xclip", "-i", "/dev/null", "-sel", "c")
cmdPaste = exec.Command("xclip", "-o", "-sel", "c")
} else {
fmt.Println(AnsiError + "Clipboard platform could not be determined - neither $WAYLAND_DISPLAY nor $DISPLAY are set" + AnsiReset)
os.Exit(1)
}
// read current clipboard contents
newContents, err := cmdPaste.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to read clipboard contents: " + err.Error() + AnsiReset)
os.Exit(1)
}
// clear clipboard if contents have not been modified
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
err = cmdClear.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
}
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
}
-55
View File
@@ -1,55 +0,0 @@
//go:build windows || (linux && wsl)
package backend
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
)
// copyField copies a field from an entry to the clipboard
func copyField(executableName, copySubject string) {
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", strings.ReplaceAll(copySubject, "'", "''")))
err := cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
// launch clipboard clearing process if executableName is provided
if executableName != "" {
cmd = exec.Command(executableName, "clipclear")
writeToStdin(cmd, copySubject)
err = cmd.Start()
if err != nil {
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
os.Exit(1)
}
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
}
}
// clipClear is called in a separate process to clear the clipboard after 30 seconds
func clipClear(oldContents string) {
time.Sleep(30 * time.Second)
cmd := exec.Command("powershell.exe", "-c", "Get-Clipboard")
newContents, err := cmd.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to read clipboard contents: " + err.Error() + AnsiReset)
os.Exit(1)
}
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
cmd = exec.Command("powershell.exe", "-c", "Set-Clipboard")
err = cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
}
}
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
}
-25
View File
@@ -1,25 +0,0 @@
package backend
// GetOldEntryData decrypts and returns old entry data (with all required lines present)
func GetOldEntryData(targetLocation string, field int) []string {
// ensure targetLocation exists
TargetIsFile(targetLocation, true, 2)
// read old entry data
unencryptedEntry := DecryptGPG(targetLocation)
// return the old entry data with all required lines present
if field > 0 {
return EnsureSliceLength(unencryptedEntry, field)
} else {
return unencryptedEntry
}
}
// EnsureSliceLength ensures slice is long enough to contain the specified index
func EnsureSliceLength(slice []string, index int) []string {
for len(slice) <= index {
slice = append(slice, "")
}
return slice
}
-9
View File
@@ -1,9 +0,0 @@
//go:build !returnOnExit
package backend
import "os"
func Exit(code int) {
os.Exit(code)
}
-7
View File
@@ -1,7 +0,0 @@
//go:build returnOnExit
package backend
func Exit(code int) {
return code
}
-39
View File
@@ -1,39 +0,0 @@
package backend
import (
"fmt"
"os"
"os/exec"
"strings"
)
// TODO GPG support is a temporary feature - it will be replaced with a different encryption scheme in the future
// DecryptGPG decrypts a GPG-encrypted file and returns the contents as a slice of (trimmed) strings
func DecryptGPG(targetLocation string) []string {
cmd := exec.Command("gpg", "--pinentry-mode", "loopback", "-q", "-d", targetLocation)
output, err := cmd.Output()
// ensure ANSI escape sequences are interpreted properly on Windows
enableVirtualTerminalProcessing()
if err != nil {
fmt.Println(AnsiError + "Failed to decrypt \"" + targetLocation + "\" - ensure it is a valid GPG-encrypted file and that you entered your passphrase correctly" + AnsiReset)
os.Exit(1)
}
outputSlice := strings.Split(string(output), "\n")
return outputSlice
}
// EncryptGPG encrypts a slice of strings using GPG and returns the encrypted data as a byte slice
func EncryptGPG(input []string) []byte {
cmd := exec.Command("gpg", "-q", "-r", ParseConfig([][2]string{{"LIBMUTTON", "gpgID"}}, "")[0], "-e")
writeToStdin(cmd, strings.Join(input, "\n"))
encryptedBytes, err := cmd.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to encrypt data - ensure that your GPG key is valid and that you have a valid GPG ID set in libmutton.ini" + AnsiReset)
os.Exit(1)
}
return encryptedBytes
}
-82
View File
@@ -1,82 +0,0 @@
package backend
import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"time"
)
// GpgUIDListGen generates a list of all GPG key IDs on the system and returns them as a slice of strings
func GpgUIDListGen() []string {
cmd := exec.Command("gpg", "-k", "--with-colons")
gpgOutputBytes, _ := cmd.Output()
gpgOutputLines := strings.Split(string(gpgOutputBytes), "\n")
var uidSlice []string
for _, line := range gpgOutputLines {
if strings.HasPrefix(line, "uid") {
uid := strings.Split(line, ":")[9]
uidSlice = append(uidSlice, uid)
}
}
return uidSlice
}
// GpgKeyGen generates a new GPG key and returns the key ID
func GpgKeyGen() string {
gpgGenTempFile := CreateTempFile()
defer func(name string) {
_ = os.Remove(name) // error ignored; if the file could be created, it can probably be removed
}(gpgGenTempFile.Name())
// create and write gpg-gen file
unixTime := strconv.FormatInt(time.Now().Unix(), 10)
_, _ = gpgGenTempFile.WriteString(strings.Join([]string{"Key-Type: eddsa", "Key-Curve: ed25519", "Key-Usage: sign", "Subkey-Type: ecdh", "Subkey-Curve: cv25519", "Subkey-Usage: encrypt", "Name-Real: libmutton-" + unixTime, "Name-Comment: gpg-libmutton", "Name-Email: github.com/rwinkhart/libmutton", "Expire-Date: 0"}, "\n")) // error ignored; if the file could be created, it can probably be written to
// close gpg-gen file
_ = gpgGenTempFile.Close() // error ignored; if the file could be created, it can probably be closed
// generate GPG key based on gpg-gen file
cmd := exec.Command("gpg", "-q", "--batch", "--generate-key", gpgGenTempFile.Name())
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err := cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to generate GPG key: " + err.Error() + AnsiReset)
os.Exit(1)
}
return "libmutton-" + unixTime + " (gpg-libmutton) <github.com/rwinkhart/libmutton>"
}
// DirInit creates the libmutton directories
func DirInit(preserveOldConfigDir bool) {
// create EntryRoot
err := os.MkdirAll(EntryRoot, 0700)
if err != nil {
fmt.Println(AnsiError + "Failed to create \"" + EntryRoot + "\":" + err.Error() + AnsiReset)
os.Exit(1)
}
// remove existing config directory (if it exists and not in append mode)
if !preserveOldConfigDir {
_, isAccessible := TargetIsFile(ConfigDir, false, 1)
if isAccessible {
err = os.RemoveAll(ConfigDir)
if err != nil {
fmt.Println(AnsiError + "Failed to remove existing config directory: " + err.Error() + AnsiReset)
os.Exit(1)
}
}
}
// create config directory w/devices subdirectory
err = os.MkdirAll(ConfigDir+PathSeparator+"devices", 0700)
if err != nil {
fmt.Println(AnsiError + "Failed to create \"" + ConfigDir + "\":" + err.Error() + AnsiReset)
os.Exit(1)
}
}
-8
View File
@@ -1,8 +0,0 @@
//go:build !windows
package backend
// TargetLocationFormat returns the full location of an entry (given the name) formatted for the current platform
func TargetLocationFormat(targetLocationIncomplete string) string {
return EntryRoot + targetLocationIncomplete
}
-10
View File
@@ -1,10 +0,0 @@
//go:build windows
package backend
import "strings"
// TargetLocationFormat returns the full location of an entry (given the name) formatted for the current platform
func TargetLocationFormat(targetLocationIncomplete string) string {
return EntryRoot + strings.ReplaceAll(targetLocationIncomplete, "/", PathSeparator)
}
-157
View File
@@ -1,157 +0,0 @@
package backend
import (
"crypto/rand"
"fmt"
"io"
"math"
"math/big"
"os"
"os/exec"
"strings"
)
// TargetIsFile TargetStatusCheck checks if the targetLocation is a file, directory, or is inaccessible
// failCondition: 0 = fail on inaccessible, 1 = fail on inaccessible/file, 2 = fail on inaccessible/directory
// returns: isFile, isAccessible
func TargetIsFile(targetLocation string, errorOnFail bool, failCondition uint8) (bool, bool) {
targetInfo, err := os.Stat(targetLocation)
if err != nil {
if errorOnFail {
fmt.Println(AnsiError + "Failed to access \"" + targetLocation + "\" - ensure it exists and has the correct permissions" + AnsiReset)
os.Exit(1)
} else {
return false, false
}
}
if targetInfo.IsDir() {
if errorOnFail && failCondition == 2 {
fmt.Println(AnsiError + "\"" + targetLocation + "\" is a directory" + AnsiReset)
os.Exit(1)
}
return false, true
} else {
if errorOnFail && failCondition == 1 {
fmt.Println(AnsiError + "\"" + targetLocation + "\" is a file" + AnsiReset)
os.Exit(1)
}
return true, true
}
}
// WriteEntry writes entryData to an encrypted file at targetLocation
func WriteEntry(targetLocation string, entryData []string, verifyEntryDoesNotExist bool) {
if verifyEntryDoesNotExist {
_, isAccessible := TargetIsFile(targetLocation, false, 0)
if isAccessible {
fmt.Println(AnsiError + "Target location already exists" + AnsiReset)
os.Exit(1)
}
}
encryptedBytes := EncryptGPG(entryData)
err := os.WriteFile(targetLocation, encryptedBytes, 0600)
if err != nil {
fmt.Println(AnsiError + "Failed to write to file: " + err.Error() + AnsiReset)
os.Exit(1)
}
}
// writeToStdin writes a string to a command's stdin
func writeToStdin(cmd *exec.Cmd, input string) {
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(AnsiError + "Failed to access stdin for system command: " + err.Error() + AnsiReset)
os.Exit(1)
}
go func() {
defer func(stdin io.WriteCloser) {
_ = stdin.Close() // error ignored; if stdin could be accessed, it can probably be closed
}(stdin)
_, _ = io.WriteString(stdin, input)
}()
}
// CreateTempFile creates a temporary file and returns a pointer to it
func CreateTempFile() *os.File {
tempFile, err := os.CreateTemp("", "*.markdown")
if err != nil {
fmt.Println(AnsiError + "Failed to create temporary file: " + err.Error() + AnsiReset)
os.Exit(1)
}
return tempFile
}
// RemoveTrailingEmptyStrings removes empty strings from the end of a slice
func RemoveTrailingEmptyStrings(slice []string) []string {
for i := len(slice) - 1; i >= 0; i-- {
if slice[i] != "" {
return slice[:i+1]
}
}
return []string{}
}
// StringGen generates a random string of a specified length and complexity
// safeForFileName: if true, the generated string will only contain special characters that are safe for file names (only impacts complex strings)
// complexity: minimum percentage of special characters to be returned in the generated string (only impacts complex strings)
func StringGen(length int, complex bool, complexity float64, safeForFileName bool) string {
var actualSpecialChars int // track the number of special characters in the generated string
var minSpecialChars int // track the minimum number of special characters to accept
var extendedCharset string // additions to character set used for complex strings
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // default character set used for all strings
const extendedCharsetFiles = "!#$%&'()+,-.;=@[]^_`{}~" // additional special characters for complex strings (safe in file names)
const extendedCharsetPassword = "\"*:><?/\\|" // additional special characters for complex strings (NOT safe in file names)
if complex {
minSpecialChars = int(math.Round(float64(length) * complexity)) // determine minimum number of special characters to accept
if !safeForFileName {
extendedCharset = extendedCharsetFiles + extendedCharsetPassword
} else {
extendedCharset = extendedCharsetFiles
}
charset += extendedCharset
}
// loop until a string of the desired complexity is generated
for {
// generate a random string
result := make([]byte, length)
for i := range result {
val, _ := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
result[i] = charset[val.Int64()]
}
// return early if the string is not complex
if !complex {
return string(result)
}
// count the number of special characters in the generated string
for _, char := range string(result) {
if strings.ContainsRune(extendedCharset, char) {
actualSpecialChars++
}
}
// return the generated string if it contains enough special characters
if actualSpecialChars >= minSpecialChars {
return string(result)
}
// reset special character counter
fmt.Println("Regenerating string until desired complexity is achieved...")
actualSpecialChars = 0
}
}
// EntryIsNotEmpty iterates through entryData and returns true if any line is not empty
func EntryIsNotEmpty(entryData []string) bool {
for _, line := range entryData {
if line != "" {
return true
}
}
return false
}
+2 -2
View File
@@ -6,13 +6,13 @@ import (
"golang.org/x/term"
)
// global variables used across multiple files
var (
width, _, _ = term.GetSize(int(os.Stdout.Fd()))
)
// global constants used across multiple files
const (
MUTNVersion = "0.2.4" // untagged releases feature a letter suffix corresponding to the eventual release version, e.g "0.2.A" -> "0.2.0", "0.2.B" -> "0.2.1"
AnsiBold = "\033[1m"
ansiBlackOnWhite = "\033[38;5;0;48;5;15m"
)
+8 -8
View File
@@ -5,21 +5,21 @@ import (
"os"
"strings"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/libmutton/core"
)
// AddEntry creates a new entry at targetLocation by taking user input via CLI prompts
// entryType: 0 = standard (password), 1 = auto-generated password, 2 = note
// AddEntry creates a new entry at targetLocation by taking user input via CLI prompts.
// Requires: entryType (0 = standard password entry, 1 = auto-generated password entry, 2 = note-only entry).
func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
// ensure target location does not already exist
_, isAccessible := backend.TargetIsFile(targetLocation, false, 0)
_, isAccessible := core.TargetIsFile(targetLocation, false, 0)
if isAccessible {
fmt.Println(backend.AnsiError + "Target location already exists" + backend.AnsiReset)
os.Exit(1)
fmt.Println(core.AnsiError + "Target location already exists" + core.AnsiReset)
os.Exit(core.ErrorTargetExists)
}
// ensure target containing directory exists and is a directory (not a file)
backend.TargetIsFile(targetLocation[:strings.LastIndex(targetLocation, "/")], true, 1)
core.TargetIsFile(targetLocation[:strings.LastIndex(targetLocation, core.PathSeparator)], true, 1)
var unencryptedEntry []string
@@ -31,7 +31,7 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
if entryType == 0 {
password = inputHidden("Password:")
} else {
password = backend.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
password = core.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
}
totp := inputHidden("TOTP secret:")
+17 -17
View File
@@ -8,11 +8,11 @@ import (
"reflect"
"strings"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync"
"github.com/rwinkhart/libmutton/core"
"github.com/rwinkhart/libmutton/sync"
)
// RenameCli renames an entry at oldLocationIncomplete to a new location (user input) on both the client and the server
// RenameCli renames an entry at oldLocationIncomplete to a new location (user input) on both the client and the server.
func RenameCli(oldLocationIncomplete string) {
// prompt user for new location and rename
newLocationIncomplete := input("New location:")
@@ -21,10 +21,10 @@ func RenameCli(oldLocationIncomplete string) {
// exit is done from sync.RenameRemoteFromClient
}
// EditEntryField edits a field of an entry at targetLocation (user input)
// EditEntryField edits a field of an entry at targetLocation (user input).
func EditEntryField(targetLocation string, hideSecrets bool, field int) {
// fetch old entry data (with all required lines present)
unencryptedEntry := backend.GetOldEntryData(targetLocation, field)
unencryptedEntry := core.GetOldEntryData(targetLocation, field)
// edit the field
switch field {
@@ -44,8 +44,8 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
// edit the note
editedNote, noteEdited := editNote(noteData)
if !noteEdited { // exit early if the note was not edited
fmt.Println(backend.AnsiError + "Entry is unchanged" + backend.AnsiReset)
os.Exit(1)
fmt.Println(core.AnsiError + "Entry is unchanged" + core.AnsiReset)
os.Exit(0)
}
unencryptedEntry = append(nonNoteData, editedNote...)
}
@@ -54,28 +54,28 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false)
}
// GenUpdate generates a new password for an entry at targetLocation (user input)
// GenUpdate generates a new password for an entry at targetLocation (user input).
func GenUpdate(targetLocation string, hideSecrets bool) {
// fetch old entry data
unencryptedEntry := backend.GetOldEntryData(targetLocation, 0)
unencryptedEntry := core.GetOldEntryData(targetLocation, 0)
// generate a new password
unencryptedEntry[0] = backend.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
unencryptedEntry[0] = core.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
// write and preview the modified entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false)
}
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty)
// returns the edited note and a boolean indicating whether the note was edited
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty).
// Returns the edited note and a boolean indicating whether the note was edited.
func editNote(baseNote []string) ([]string, bool) {
tempFile := backend.CreateTempFile()
tempFile := core.CreateTempFile()
defer func(name string) {
_ = os.Remove(name) // error ignored; if the file could be created, it can probably be removed
}(tempFile.Name())
// fetch the user's text editor
editor := backend.ParseConfig([][2]string{{"MUTN", "textEditor"}}, "")[0]
editor := core.ParseConfig([][2]string{{"MUTN", "textEditor"}}, "")[0]
// write baseNote to tempFile (if it is not empty)
if len(baseNote) > 0 {
@@ -94,13 +94,13 @@ func editNote(baseNote []string) ([]string, bool) {
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
panic(backend.AnsiError + "Failed to write note with " + editor + backend.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
panic(core.AnsiError + "Failed to write note with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
}
// open the tempFile for reading
tempFile, err = os.Open(tempFile.Name())
if err != nil {
panic(backend.AnsiError + "Failed to read note written with " + editor + backend.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
panic(core.AnsiError + "Failed to read note written with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
}
// read the edited note from the tempFile
@@ -114,7 +114,7 @@ func editNote(baseNote []string) ([]string, bool) {
_ = tempFile.Close() // error ignored; if the file could be opened, it can probably be closed
// remove trailing empty strings from the edited note
note = backend.RemoveTrailingEmptyStrings(note)
note = core.RemoveTrailingEmptyStrings(note)
// trim trailing whitespace from each note line
for i, line := range note {
+12 -11
View File
@@ -2,20 +2,21 @@ package cli
import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync"
"os"
"strings"
"github.com/rwinkhart/libmutton/core"
"github.com/rwinkhart/libmutton/sync"
)
// global constants used only in this file
// ANSI color constants used only in this file
const (
ansiAlternateEntryColor = "\033[38;5;8m"
ansiDirectoryHeader = "\033[38;5;7;48;5;8m"
ansiEmptyDirectoryWarning = "\033[38;5;11m"
)
// calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories) - also subtracts "old" text from directory header
// determineIndentation calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories); also subtracts "old" text from directory header.
func determineIndentation(skippedDirList []bool, dirList []string, currentDirIndex int) (int, string) {
var subtractor int // tracks how much to subtract from expected indentation multiplier
var lastPrefixIndex int // tracks the index (in both skippedDirList and dirList) of the last displayed parent directory
@@ -45,7 +46,7 @@ func determineIndentation(skippedDirList []bool, dirList []string, currentDirInd
return indent, trimmedDirectory
}
// processing for printing file entries (determines color, line wrapping, and prints)
// printFileEntry handles processing for printing file entries (determines color, wraps lines, and prints).
func printFileEntry(entry string, lastSlash, charCounter, indent int, colorAlternator int8) (int, int8) {
// determine color to print fileEntryName (alternate each time function is run)
var colorCode string
@@ -71,17 +72,17 @@ func printFileEntry(entry string, lastSlash, charCounter, indent int, colorAlter
}
// print fileEntryName to screen
fmt.Printf("%s%s%s ", colorCode, fileEntryName, backend.AnsiReset)
fmt.Printf("%s%s%s ", colorCode, fileEntryName, core.AnsiReset)
return charCounter, colorAlternator
}
// EntryListGen generates and displays full libmutton entry list
// EntryListGen generates and displays the full libmutton entry list.
func EntryListGen() {
fileList, dirList := sync.WalkEntryDir()
// print header bar w/total entry count
fmt.Print("\n"+ansiBlackOnWhite, len(fileList), " libmutton entries:"+backend.AnsiReset)
fmt.Print("\n"+ansiBlackOnWhite, len(fileList), " libmutton entries:"+core.AnsiReset)
// dirList iteration
dirListLength := len(dirList) // save length for multiple references below
@@ -127,7 +128,7 @@ func EntryListGen() {
containsFiles = true
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
indent, vanityDirectory = determineIndentation(skippedDirList, dirList, i) // calculate the final indentation multiplier
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+backend.AnsiReset+"\n", vanityDirectory)
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+core.AnsiReset+"\n", vanityDirectory)
}
charCounter, colorAlternator = printFileEntry(file, lastSlash, charCounter, indent, colorAlternator)
@@ -139,8 +140,8 @@ func EntryListGen() {
if dirListLength > 1 { // and directories besides the root-level exist... display directory header and empty directory warning
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
indent, vanityDirectory = determineIndentation(skippedDirList, dirList, i) // calculate the final indentation multiplier
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+backend.AnsiReset+"\n", vanityDirectory)
fmt.Print(strings.Repeat(" ", indent*2) + ansiEmptyDirectoryWarning + "-empty directory-" + backend.AnsiReset)
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+core.AnsiReset+"\n", vanityDirectory)
fmt.Print(strings.Repeat(" ", indent*2) + ansiEmptyDirectoryWarning + "-empty directory-" + core.AnsiReset)
} else { // warn if the only thing that exists is the root-level directory
fmt.Print("\n\nNothing's here! For help creating your first entry, run \"mutn help\".")
}
+16 -18
View File
@@ -3,15 +3,14 @@ package cli
import (
"fmt"
"os"
"strings"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync"
"github.com/rwinkhart/libmutton/core"
"github.com/rwinkhart/libmutton/sync"
)
const ansiShownPassword = "\033[38;5;10m"
// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format
// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format.
func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) {
fmt.Println()
@@ -21,43 +20,42 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) {
// if the first field (password) is not empty, print it
if decryptedEntry[0] != "" {
if !hideSecrets {
fmt.Print(ansiDirectoryHeader + "Password:" + backend.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + backend.AnsiReset + "\n\n")
fmt.Print(ansiDirectoryHeader + "Password:" + core.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + core.AnsiReset + "\n\n")
} else {
fmt.Print(ansiDirectoryHeader + "Password:" + backend.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + backend.AnsiReset + "\n\n")
fmt.Print(ansiDirectoryHeader + "Password:" + core.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + core.AnsiReset + "\n\n")
}
}
case 1:
// if the second field (username) is not empty, print it
if decryptedEntry[1] != "" {
fmt.Print(ansiDirectoryHeader + "Username:" + backend.AnsiReset + "\n" + decryptedEntry[1] + "\n\n")
fmt.Print(ansiDirectoryHeader + "Username:" + core.AnsiReset + "\n" + decryptedEntry[1] + "\n\n")
}
case 2:
// if the third field (TOTP secret) is not empty, print it
if decryptedEntry[2] != "" {
if !hideSecrets {
fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + backend.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[2] + backend.AnsiReset + "\n\n")
fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + core.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[2] + core.AnsiReset + "\n\n")
} else {
fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + backend.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + backend.AnsiReset + "\n\n")
fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + core.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + core.AnsiReset + "\n\n")
}
}
case 3:
// if the fourth field (url) is not empty, print it
if decryptedEntry[3] != "" {
fmt.Print(ansiDirectoryHeader + "URL:" + backend.AnsiReset + "\n" + decryptedEntry[3] + "\n\n")
fmt.Print(ansiDirectoryHeader + "URL:" + core.AnsiReset + "\n" + decryptedEntry[3] + "\n\n")
}
case 4:
// print the notes header
fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset)
fmt.Println(ansiDirectoryHeader + "Notes:" + core.AnsiReset)
// combine remaining fields into a single string (to support Markdown rendering)
var notesSlice []string
var noteLines []string
for ; field < len(decryptedEntry); field++ {
notesSlice = append(notesSlice, decryptedEntry[field])
noteLines = append(noteLines, decryptedEntry[field])
}
joinedString := strings.Join(notesSlice, "\n")
// print notes to stdout
renderNote(&joinedString)
renderNote(noteLines)
// break after notes have been printed
break
@@ -71,10 +69,10 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) {
os.Exit(0)
}
// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader
// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader.
func EntryReaderDecrypt(targetLocation string, hideSecrets bool) {
if isFile, _ := backend.TargetIsFile(targetLocation, true, 2); isFile {
EntryReader(backend.DecryptGPG(targetLocation), hideSecrets, false) // never sync if decrypting straight to EntryReader, as this means the entry could not have been modified
if isFile, _ := core.TargetIsFile(targetLocation, true, 2); isFile {
EntryReader(core.DecryptGPG(targetLocation), hideSecrets, false) // never sync if decrypting straight to EntryReader, as this means the entry could not have been modified
}
// do not exit, as this is the job of EntryReader
}
+14
View File
@@ -0,0 +1,14 @@
//go:build !noMarkdown && BEAN
package cli
import (
"fmt"
bean "github.com/Trojan2021/BEAN/render"
)
// renderNote renders the notes section of an entry (in Markdown) to stdout.
func renderNote(noteLines []string) {
fmt.Println(bean.RenderMarkdown(noteLines, width))
}
+4 -3
View File
@@ -4,9 +4,10 @@ package cli
import (
"fmt"
"strings"
)
// renderNote prints the notes section of an entry to stdout (when Markdown rendering is disabled)
func renderNote(note *string) {
fmt.Print("\n" + *note + "\n\n")
// renderNote prints the notes section of an entry to stdout (when Markdown rendering is disabled).
func renderNote(noteLines []string) {
fmt.Print("\n" + strings.Join(noteLines, "\n") + "\n\n")
}
@@ -1,17 +1,19 @@
//go:build !noMarkdown
//go:build !noMarkdown && !BEAN
package cli
import (
"fmt"
"strings"
"github.com/charmbracelet/glamour"
)
// renderNote renders the notes section of an entry (in Markdown) to stdout
func renderNote(note *string) {
// renderNote renders the notes section of an entry (in Markdown) to stdout.
func renderNote(noteLines []string) {
note := strings.Join(noteLines, "\n")
r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width))
markdownNotesString, _ := r.Render(*note)
markdownNotesString, _ := r.Render(note)
// print markdown-rendered notes
fmt.Print(markdownNotesString)
+17 -17
View File
@@ -6,23 +6,23 @@ import (
"os"
"strconv"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync"
"github.com/rwinkhart/libmutton/core"
"github.com/rwinkhart/libmutton/sync"
)
// TempInitCli initializes the MUTN environment based on user input (will be replaced with a TUI menu)
// TempInitCli initializes the MUTN environment based on user input.
func TempInitCli() {
// gpgID
var gpgID string
if inputBinary("Auto-generate GPG key?") {
gpgID = backend.GpgKeyGen()
gpgID = core.GpgKeyGen()
} else {
// select GPG key from menu
uidSlice := backend.GpgUIDListGen()
uidSlice := core.GpgUIDListGen()
gpgIDInt := inputMenuGen("Select GPG key:", uidSlice)
if gpgIDInt == 0 {
fmt.Println(backend.AnsiError + "No GPG keys found - please generate one" + backend.AnsiReset)
os.Exit(1)
fmt.Println(core.AnsiError + "No GPG keys found - please generate one" + core.AnsiReset)
os.Exit(core.ErrorTargetNotFound)
}
gpgID = uidSlice[gpgIDInt-1]
}
@@ -34,7 +34,7 @@ func TempInitCli() {
configSSH := inputBinary("Configure SSH settings (for synchronization)?")
if configSSH {
// necessary SSH info
fmt.Println(AnsiBold + "\nNote:" + backend.AnsiReset + " Only key-based authentication is supported (keys may optionally be passphrase-protected).\nThe remote server must already be in your ~" + backend.PathSeparator + ".ssh" + backend.PathSeparator + "known_hosts file.")
fmt.Println(AnsiBold + "\nNote:" + core.AnsiReset + " Only key-based authentication is supported (keys may optionally be passphrase-protected).\nThe remote server must already be in your ~" + core.PathSeparator + ".ssh" + core.PathSeparator + "known_hosts file.")
sshUser := input("Remote SSH username:")
sshPort := input("Remote SSH port:")
sshIP := input("Remote SSH IP/domain:")
@@ -43,32 +43,32 @@ func TempInitCli() {
var sshKey string
var sshKeyIsFile bool
for !sshKeyIsFile {
fallbackSSHKey := backend.Home + backend.PathSeparator + ".ssh" + backend.PathSeparator + "id_ed25519"
fallbackSSHKey := core.Home + core.PathSeparator + ".ssh" + core.PathSeparator + "id_ed25519"
sshKey = cmp.Or(expandPathWithHome(input("SSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey)
sshKeyIsFile, _ = backend.TargetIsFile(sshKey, false, 0)
sshKeyIsFile, _ = core.TargetIsFile(sshKey, false, 0)
if !sshKeyIsFile {
fmt.Println(backend.AnsiError + "SSH identity file not found: " + sshKey + backend.AnsiReset)
fmt.Println(core.AnsiError+"SSH identity file not found:", sshKey+core.AnsiReset)
}
}
sshKeyProtected := inputBinary("Is the identity file password-protected?")
// initialize libmutton directories
backend.DirInit(false)
oldDeviceID := core.DirInit(false)
// write config file (temporarily assigns sshEntryRoot and sshIsWindows to null to pass initial device ID registration)
backend.WriteConfig([][3]string{{"MUTN", "textEditor", textEditor}, {"LIBMUTTON", "gpgID", gpgID}, {"LIBMUTTON", "sshUser", sshUser}, {"LIBMUTTON", "sshIP", sshIP}, {"LIBMUTTON", "sshPort", sshPort}, {"LIBMUTTON", "sshKey", sshKey}, {"LIBMUTTON", "sshKeyProtected", strconv.FormatBool(sshKeyProtected)}, {"LIBMUTTON", "sshEntryRoot", "null"}, {"LIBMUTTON", "sshIsWindows", "null"}}, false)
core.WriteConfig([][3]string{{"MUTN", "textEditor", textEditor}, {"LIBMUTTON", "gpgID", gpgID}, {"LIBMUTTON", "sshUser", sshUser}, {"LIBMUTTON", "sshIP", sshIP}, {"LIBMUTTON", "sshPort", sshPort}, {"LIBMUTTON", "sshKey", sshKey}, {"LIBMUTTON", "sshKeyProtected", strconv.FormatBool(sshKeyProtected)}, {"LIBMUTTON", "sshEntryRoot", "null"}, {"LIBMUTTON", "sshIsWindows", "false"}}, false)
// generate and register device ID
sshEntryRoot, sshIsWindows := sync.DeviceIDGen()
sshEntryRoot, sshIsWindows := sync.DeviceIDGen(oldDeviceID)
// update config file with sshEntryRoot and sshIsWindows
backend.WriteConfig([][3]string{{"LIBMUTTON", "sshEntryRoot", sshEntryRoot}, {"LIBMUTTON", "sshIsWindows", sshIsWindows}}, true)
core.WriteConfig([][3]string{{"LIBMUTTON", "sshEntryRoot", sshEntryRoot}, {"LIBMUTTON", "sshIsWindows", sshIsWindows}}, true)
} else {
// initialize libmutton directories
backend.DirInit(false)
core.DirInit(false)
// write config file
backend.WriteConfig([][3]string{{"MUTN", "textEditor", textEditor}, {"LIBMUTTON", "gpgID", gpgID}}, false)
core.WriteConfig([][3]string{{"MUTN", "textEditor", textEditor}, {"LIBMUTTON", "gpgID", gpgID}}, false)
}
}
+33 -31
View File
@@ -4,23 +4,23 @@ import (
"fmt"
"os"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/libmutton/core"
)
// global constants used only in this file
// ANSI color constants used only in this file
const (
ansiVersionMeat = "\033[38;2;157;0;6m"
ansiVersionOutline = "\033[38;2;131;165;152m"
)
func HelpMain() {
fmt.Print(AnsiBold + "\nMUTN | Copyright (c) 2024 Randall Winkhart\n" + backend.AnsiReset + `
fmt.Print(AnsiBold + "\nMUTN | Copyright (c) 2024 Randall Winkhart\n" + core.AnsiReset + `
This software exists under the MIT license; you may redistribute it under certain conditions.
This program comes with absolutely no warranty; type "mutn version" for details.
` + AnsiBold + "Usage:" + backend.AnsiReset + ` mutn [/<entry name> [argument] [option]] | [argument]
` + AnsiBold + "Usage:" + core.AnsiReset + ` mutn [/<entry name> [argument] [option]] | [argument]
` + AnsiBold + "Arguments:" + backend.AnsiReset + `
` + AnsiBold + "Arguments:" + core.AnsiReset + `
help Bring up this menu
version Display version and license information
init Set up MUTN (generates libmutton.ini)
@@ -31,7 +31,7 @@ This program comes with absolutely no warranty; type "mutn version" for details.
shear Delete an existing entry
sync Manually sync the entry directory
` + AnsiBold + "Options:" + backend.AnsiReset + `
` + AnsiBold + "Options:" + core.AnsiReset + `
copy:
password|-pw|<blank> Copy the password in an entry to your clipboard
username|-u Copy the username in an entry to your clipboard
@@ -52,17 +52,17 @@ This program comes with absolutely no warranty; type "mutn version" for details.
note|-n Add a note entry
folder|-f Add a new folder for entries
` + AnsiBold + "Tip 1:" + backend.AnsiReset + ` You can quickly read an entry with "mutn /<entry name>"
` + AnsiBold + "Tip 2:" + backend.AnsiReset + ` Type "mutn" (no arguments/options) to view a list of saved entries
` + AnsiBold + "Tip 3:" + backend.AnsiReset + ` Provide "add", "edit", "copy", or "gen" as the only argument to receive more specific help
` + AnsiBold + "Tip 4:" + backend.AnsiReset + " Using \"add\", \"edit\", or \"copy\" without specifying an option (field) will default to \"password\"\n\n")
` + AnsiBold + "Tip 1:" + core.AnsiReset + ` You can quickly read an entry with "mutn /<entry name>"
` + AnsiBold + "Tip 2:" + core.AnsiReset + ` Type "mutn" (no arguments/options) to view a list of saved entries
` + AnsiBold + "Tip 3:" + core.AnsiReset + ` Provide "add", "edit", "copy", or "gen" as the only argument to receive more specific help
` + AnsiBold + "Tip 4:" + core.AnsiReset + " Using \"add\", \"edit\", or \"copy\" without specifying an option (field) will default to \"password\"\n\n")
os.Exit(0)
}
func HelpAdd() {
fmt.Print(AnsiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> add <option>
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> add <option>
` + AnsiBold + "Options:" + backend.AnsiReset + `
` + AnsiBold + "Options:" + core.AnsiReset + `
add:
password|-pw|<blank> Add a password entry
note|-n Add a note entry
@@ -71,9 +71,9 @@ func HelpAdd() {
}
func HelpEdit() {
fmt.Print(AnsiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> edit <option>
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> edit <option>
` + AnsiBold + "Options:" + backend.AnsiReset + `
` + AnsiBold + "Options:" + core.AnsiReset + `
edit:
password|-pw|<blank> Change the password in an entry
username|-u Change the username in an entry
@@ -85,9 +85,9 @@ func HelpEdit() {
}
func HelpCopy() {
fmt.Print(AnsiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> copy <option>
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> copy <option>
` + AnsiBold + "Options:" + backend.AnsiReset + `
` + AnsiBold + "Options:" + core.AnsiReset + `
copy:
password|-pw|<blank> Copy the password in an entry to your clipboard
username|-u Copy the username in an entry to your clipboard
@@ -98,18 +98,18 @@ func HelpCopy() {
}
func HelpGen() {
fmt.Print(AnsiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> gen [option]
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> gen [option]
` + AnsiBold + "Options:" + backend.AnsiReset + `
` + AnsiBold + "Options:" + core.AnsiReset + `
gen:
update|-u Generate a password for an existing entry
` + AnsiBold + "Tip:" + backend.AnsiReset + " If no options are provided, a new password entry is generated\n\n")
` + AnsiBold + "Tip:" + core.AnsiReset + " If no options are provided, a new password entry is generated\n\n")
os.Exit(0)
}
func MITLicense() {
fmt.Print(AnsiBold + "\n MIT License" + backend.AnsiReset + `
fmt.Print(AnsiBold + "\n MIT License" + core.AnsiReset + `
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
@@ -141,18 +141,20 @@ func Version() {
MITLicense()
fmt.Print("\n\n MUTN is a simple, self-hosted,\n SSH-synchronized password manager based on libmutton\n\n" +
" .. ..\n" +
" /()\\''.''. " + ansiVersionMeat + "♥♥♥♥" + backend.AnsiReset + " .''.''/()\\ _)\n" +
" _. : * " + ansiVersionMeat + "♥♥♥♥♥♥ ♥♥♥♥♥♥♥♥" + backend.AnsiReset + " * : <[◎]|_|=\n" +
" }-}-*] `..'..' " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥♥♥♥♥" + backend.AnsiReset + " `..'..' |\n" +
" ◎-◎ // \\\\ " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥" + backend.AnsiReset + " // \\\\ /|\\\n" +
" /()\\''.''. " + ansiVersionMeat + "♥♥♥♥" + core.AnsiReset + " .''.''/()\\ _)\n" +
" _. : * " + ansiVersionMeat + "♥♥♥♥♥♥ ♥♥♥♥♥♥♥♥" + core.AnsiReset + " * : <[◎]|_|=\n" +
" }-}-*] `..'..' " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥♥♥♥♥" + core.AnsiReset + " `..'..' |\n" +
" ◎-◎ // \\\\ " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥" + core.AnsiReset + " // \\\\ /|\\\n" +
ansiVersionOutline + "<><><><><><><><><><><><><><>-<><><><><><><><><><><><><><>\n" +
"\\" + ansiBlackOnWhite + " " + backend.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " MUTN Version " + backend.LibmuttonVersion + " " + backend.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " The Tripe Transmission Update " + backend.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " " + backend.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " Copyright (c) 2024 Randall Winkhart " + backend.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " " + backend.AnsiReset + ansiVersionOutline + "/\n" +
"<><><><><><><><><><><><><><>-<><><><><><><><><><><><><><>\n" + backend.AnsiReset +
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " MUTN v" + MUTNVersion + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " The Tripe Transmission Update " + core.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " Built with libmutton v" + core.LibmuttonVersion + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " Copyright (c) 2024 Randall Winkhart " + core.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
"<><><><><><><><><><><><><><>-<><><><><><><><><><><><><><>\n" + core.AnsiReset +
"\n For more information, see:\n\n" +
" https://github.com/rwinkhart/MUTN\n" +
" https://github.com/rwinkhart/libmutton\n\n")
+17 -17
View File
@@ -6,11 +6,11 @@ import (
"os"
"strings"
"github.com/rwinkhart/MUTN/src/backend"
"golang.org/x/crypto/ssh/terminal"
"github.com/rwinkhart/libmutton/core"
"golang.org/x/term"
)
// input prompts the user for input and returns the input as a string
// input prompts the user for input and returns the input as a string.
func input(prompt string) string {
fmt.Print("\n" + prompt + " ")
reader := bufio.NewReader(os.Stdin)
@@ -18,17 +18,17 @@ func input(prompt string) string {
return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces
}
// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal
// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal.
func inputHidden(prompt string) string {
fmt.Print("\n" + prompt + " ")
byteInput, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
byteInput, _ := term.ReadPassword(int(os.Stdin.Fd()))
password := string(byteInput)
fmt.Println()
return password
}
// inputInt prompts the user for input and returns the input as an integer
// a maxValue of 0 will cause the function to return 0, an error - a negative maxValue will disable the maxValue check
// inputInt prompts the user for input and returns the input as an integer.
// A maxValue of 0 will cause the function to return 0, an error - a negative maxValue will disable the maxValue check.
func inputInt(prompt string, maxValue int) int {
if maxValue == 0 {
return 0
@@ -45,7 +45,7 @@ func inputInt(prompt string, maxValue int) int {
}
}
// inputBinary prompts the user with a yes/no question and returns the response as a boolean
// inputBinary prompts the user with a yes/no question and returns the response as a boolean.
func inputBinary(prompt string) bool {
reader := bufio.NewReader(os.Stdin)
fmt.Print("\n" + prompt + " (y/N) ")
@@ -56,7 +56,7 @@ func inputBinary(prompt string) bool {
return false
}
// inputMenuGen prompts the user with a menu and returns the user's choice as an integer
// inputMenuGen prompts the user with a menu and returns the user's choice as an integer.
func inputMenuGen(prompt string, options []string) int {
for i, option := range options {
fmt.Printf("%d. %s\n", i+1, option)
@@ -64,21 +64,21 @@ func inputMenuGen(prompt string, options []string) int {
return inputInt(prompt, len(options))
}
// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied)
// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied).
func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets, verifyEntryDoesNotExist bool) {
if backend.EntryIsNotEmpty(unencryptedEntry) {
if core.EntryIsNotEmpty(unencryptedEntry) {
// write the entry to the target location
backend.WriteEntry(targetLocation, unencryptedEntry, verifyEntryDoesNotExist)
core.WriteEntry(targetLocation, unencryptedEntry, verifyEntryDoesNotExist)
// preview the entry
fmt.Println(AnsiBold + "\nEntry Preview:" + backend.AnsiReset)
fmt.Println(AnsiBold + "\nEntry Preview:" + core.AnsiReset)
EntryReader(unencryptedEntry, hideSecrets, true)
} else {
fmt.Println(backend.AnsiError + "No data supplied for entry" + backend.AnsiReset)
os.Exit(1)
fmt.Println(core.AnsiError + "No data supplied for entry" + core.AnsiReset)
os.Exit(core.ErrorTargetNotFound)
}
}
// expandPathWithHome, given a path (as a string) containing "~", returns the path with "~" expanded to the user's home directory
// expandPathWithHome, given a path (as a string) containing "~", returns the path with "~" expanded to the user's home directory.
func expandPathWithHome(path string) string {
return strings.Replace(path, "~", backend.Home, 1)
return strings.Replace(path, "~", core.Home, 1)
}
-13
View File
@@ -1,13 +0,0 @@
package sync
import "github.com/rwinkhart/MUTN/src/backend"
// define field separator constants
const (
FSSpace = "\u259d" // ▝ space/list separator
FSPath = "\u259e" // ▞ path separator
FSMisc = "\u259f" // ▟ misc. field separator (if \u259d is already used)
)
// rootLength stores length of backend.EntryRoot string
var rootLength = len(backend.EntryRoot)
-477
View File
@@ -1,477 +0,0 @@
package sync
import (
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/pkg/sftp"
"github.com/rwinkhart/MUTN/src/backend"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"
)
// global constants used only in this file
const (
ansiDelete = "\033[38;5;1m"
ansiDownload = "\033[38;5;2m"
ansiUpload = "\033[38;5;4m"
)
// getSSHClient returns an SSH client connection to the server (also returns the remote EntryRoot as a string and the server's OS as a bool - IsWindows)
// only supports key-based authentication (passphrases are supported for CLI-based implementations)
func getSSHClient(manualSync bool) (*ssh.Client, string, bool) {
// get SSH config info, exit if not configured (displaying an error if the sync job was called manually)
var sshUserConfig []string
var missingValueError string
if manualSync {
missingValueError = joinErrorWithEXE("SSH settings not configured - run \"", " init\" to configure")
} else {
missingValueError = "0"
}
sshUserConfig = backend.ParseConfig([][2]string{{"LIBMUTTON", "sshUser"}, {"LIBMUTTON", "sshIP"}, {"LIBMUTTON", "sshPort"}, {"LIBMUTTON", "sshKey"}, {"LIBMUTTON", "sshKeyProtected"}, {"LIBMUTTON", "sshEntryRoot"}, {"LIBMUTTON", "sshIsWindows"}}, missingValueError)
var user, ip, port, keyFile, keyFileProtected, entryRoot string
var isWindows bool
for i, key := range sshUserConfig {
switch i {
case 0:
user = key
case 1:
ip = key
case 2:
port = key
case 3:
keyFile = key
case 4:
keyFileProtected = key
case 5:
entryRoot = key
case 6:
isWindows, _ = strconv.ParseBool(key)
}
}
// read private key
key, err := os.ReadFile(keyFile)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - unable to read private key file:", keyFile+backend.AnsiReset)
os.Exit(1)
}
// parse private key
var parsedKey ssh.Signer
if keyFileProtected != "true" {
parsedKey, err = ssh.ParsePrivateKey(key)
} else {
parsedKey, err = ssh.ParsePrivateKeyWithPassphrase(key, inputKeyFilePassphrase())
}
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to parse private key:", keyFile+backend.AnsiReset)
os.Exit(1)
}
// read known hosts file
hostKeyCallback, err := knownhosts.New(backend.Home + backend.PathSeparator + ".ssh" + backend.PathSeparator + "known_hosts")
if err != nil {
fmt.Println(backend.AnsiError + "Sync failed - Unable to read known hosts file:" + err.Error() + backend.AnsiReset)
os.Exit(1)
}
// configure SSH client
sshConfig := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(parsedKey),
},
HostKeyCallback: hostKeyCallback,
}
// connect to SSH server
sshClient, err := ssh.Dial("tcp", ip+":"+port, sshConfig)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to connect to remote server:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
return sshClient, entryRoot, isWindows
}
// GetSSHOutput runs a command over SSH and returns the output as a string
// TODO run getSSHClient() only ONCE (from RunJob) - this saves re-creating the client AND prevents prompting for keyfile passphrase multiple times
func GetSSHOutput(cmd, stdin string, manualSync bool) string {
sshClient, _, _ := getSSHClient(manualSync)
defer sshClient.Close()
// create a session
sshSession, err := sshClient.NewSession()
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to establish SSH session:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// provide stdin data for session
sshSession.Stdin = strings.NewReader(stdin)
// run the provided command
var output []byte
output, err = sshSession.CombinedOutput(cmd)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to run SSH command:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// convert the output to a string and remove leading/trailing whitespace
outputString := string(output)
outputString = strings.TrimSpace(outputString)
return outputString
}
// getRemoteDataFromClient returns a map of remote entries to their modification times, a list of remote folders, a list of queued deletions, and the current server+client times as UNIX timestamps
func getRemoteDataFromClient(manualSync bool) (map[string]int64, []string, []string, int64, int64) {
// get remote output over SSH
clientDeviceID, _ := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices")
if len(clientDeviceID) == 0 {
if manualSync {
fmt.Println(joinErrorWithEXE("Sync failed - No device ID found; run \"", " init\" to generate a device ID"))
os.Exit(1)
} else {
backend.Exit(0) // exit silently if the sync job was called automatically, as the user may just be in offline mode
}
}
clientTime := time.Now().Unix() // get client time now to avoid accuracy issues caused by unpredictable sync time
output := GetSSHOutput("libmuttonserver fetch", clientDeviceID[0].Name(), manualSync)
// split output into slice based on occurrences of FSSpace
outputSlice := strings.Split(output, FSSpace)
// parse output/re-form lists
if len(outputSlice) != 5 { // ensure information from server is complete
fmt.Println(backend.AnsiError + "Sync failed - Unable to fetch remote data; server returned an unexpected response" + backend.AnsiReset)
os.Exit(1)
}
serverTime, _ := strconv.ParseInt(outputSlice[0], 10, 64)
entries := strings.Split(outputSlice[1], FSMisc)[1:]
modsStrings := strings.Split(outputSlice[2], FSMisc)[1:]
folders := strings.Split(outputSlice[3], FSMisc)[1:]
deletions := strings.Split(outputSlice[4], FSMisc)[1:]
// convert the mod times to int64
var mods []int64
for _, modString := range modsStrings {
mod, _ := strconv.ParseInt(modString, 10, 64)
mods = append(mods, mod)
}
// map remote entries to their modification times
entryModMap := make(map[string]int64)
for i, entry := range entries {
entryModMap[entry] = mods[i]
}
return entryModMap, folders, deletions, serverTime, clientTime
}
// getLocalData returns a map of local entries to their modification times
func getLocalData() map[string]int64 {
// get a list of all entries
entries, _ := WalkEntryDir()
// get a list of all entry modification times
modList := getModTimes(entries)
// map the entries to their modification times
entryModMap := make(map[string]int64)
for i, entry := range entries {
entryModMap[entry] = modList[i]
}
// return the lists
return entryModMap
}
// targetLocationFormatSFTP formats the target location to match the remote server's entry directory and path separator
func targetLocationFormatSFTP(targetName, serverEntryRoot string, serverIsWindows bool) string {
if !serverIsWindows {
return serverEntryRoot + targetName
} else {
return serverEntryRoot + strings.ReplaceAll(targetName, "/", "\\")
}
}
// sftpSync takes two slices of entries (one for downloads and one for uploads) and syncs them between the client and server using SFTP
func sftpSync(downloadList, uploadList []string, manualSync bool) {
// establish an SSH connection for transfers
sshClient, sshEntryRoot, sshIsWindows := getSSHClient(manualSync)
defer sshClient.Close()
// create an SFTP client
sftpClient, err := sftp.NewClient(sshClient)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to establish SFTP session:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
defer sftpClient.Close()
// iterate over the download list
var filesTransferred bool
for _, entryName := range downloadList {
filesTransferred = true // set a flag to indicate that files have been downloaded (used to determine whether to print a gap between download and upload messages)
fmt.Println("Downloading " + ansiDownload + entryName + backend.AnsiReset)
// store path to remote entry
remoteEntryFullPath := targetLocationFormatSFTP(entryName, sshEntryRoot, sshIsWindows)
// save modification time of remote file
var fileInfo os.FileInfo
fileInfo, err = sftpClient.Stat(remoteEntryFullPath)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to get remote file info (mod time):", err.Error()+backend.AnsiReset)
os.Exit(1)
}
modTime := fileInfo.ModTime()
// open remote file
var remoteFile *sftp.File
remoteFile, err = sftpClient.Open(remoteEntryFullPath)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to open remote file:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// store path to local entry
localEntryFullPath := backend.TargetLocationFormat(entryName)
// create local file
var localFile *os.File
localFile, err = os.Create(localEntryFullPath)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to create local file:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// download the file
_, err = remoteFile.WriteTo(localFile)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to download remote file:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// close the files
remoteFile.Close()
localFile.Close()
// set the modification time of the local file to match the value saved from the remote file (from before the download)
err = os.Chtimes(localEntryFullPath, time.Now(), modTime)
}
if filesTransferred {
fmt.Println() // add a gap between download and upload messages
}
// iterate over the upload list
filesTransferred = false
for _, entryName := range uploadList {
filesTransferred = true // set a flag to indicate that files have been uploaded (used to determine whether to print a gap between upload and sync complete messages)
fmt.Println("Uploading " + ansiUpload + entryName + backend.AnsiReset)
// store path to local entry
localEntryFullPath := backend.TargetLocationFormat(entryName)
// save modification time of local file
var fileInfo os.FileInfo
fileInfo, err = os.Stat(localEntryFullPath)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to get local file info (mod time):", err.Error()+backend.AnsiReset)
os.Exit(1)
}
modTime := fileInfo.ModTime()
// open local file
var localFile *os.File
localFile, err = os.Open(localEntryFullPath)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to open local file:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// store path to remote entry
remoteEntryFullPath := targetLocationFormatSFTP(entryName, sshEntryRoot, sshIsWindows)
// create remote file
var remoteFile *sftp.File
remoteFile, err = sftpClient.Create(remoteEntryFullPath)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to create remote file ("+remoteEntryFullPath+"):", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// upload the file
_, err = localFile.WriteTo(remoteFile)
if err != nil {
fmt.Println(backend.AnsiError+"Sync failed - Unable to upload local file:", err.Error()+backend.AnsiReset)
os.Exit(1)
}
// close the files
localFile.Close()
remoteFile.Close()
// set the modification time of the remote file to match the value saved from the local file (from before the upload)
err = sftpClient.Chtimes(remoteEntryFullPath, time.Now(), modTime)
}
if filesTransferred {
fmt.Println() // add a gap between upload and sync complete messages
}
}
// syncLists determines which entries need to be downloaded and uploaded for synchronizations and calls sftpSync with this information
// using maps means that syncing will be done in an arbitrary order, but it is a worthy tradeoff for speed and simplicity
func syncLists(localEntryModMap, remoteEntryModMap map[string]int64, manualSync bool, serverTime int64, clientTime int64) {
// initialize slices to store entries that need to be downloaded or uploaded
var downloadList, uploadList []string
// ensure client and server times are synchronized
var timeSynced = true
timeDiff := serverTime - clientTime
if timeDiff < -45 || timeDiff > 45 {
timeSynced = false
fmt.Print(backend.AnsiError + "Client and server clocks are out of sync.\n\nPlease ensure both clocks are correct before attempting to sync again.\n\nA dry sync output will be printed below (if any operations would have been performed). It is strongly recommended to review it and manually update the modification times as applicable to ensure the correct version of each entry is kept.\n\nIf the client's clock is at fault, update the modification times of any entries pending upload, even if the correct (upload) operation is being performed on them. Failure to do so could result in entries being uploaded to the server with the incorrect modification times (could result in data loss).\n\n" + backend.AnsiReset)
}
// iterate over client entries
for entry, localModTime := range localEntryModMap {
// check if the entry is present in the server map
if remoteModTime, present := remoteEntryModMap[entry]; present {
// entry exists on both client and server, compare mod times
if remoteModTime > localModTime {
fmt.Println(ansiDownload+entry+backend.AnsiReset, "is newer on server, adding to download list")
downloadList = append(downloadList, entry)
} else if remoteModTime < localModTime {
fmt.Println(ansiUpload+entry+backend.AnsiReset, "is newer on client, adding to upload list")
uploadList = append(uploadList, entry)
}
// remove entry from remoteEntryModMap (process of elimination)
delete(remoteEntryModMap, entry)
} else {
fmt.Println(ansiUpload+entry+backend.AnsiReset, "does not exist on server, adding to upload list")
uploadList = append(uploadList, entry)
}
}
// iterate over remaining entries in remoteEntryModMap
for entry := range remoteEntryModMap {
fmt.Println(ansiDownload+entry+backend.AnsiReset, "does not exist on client, adding to download list")
downloadList = append(downloadList, entry)
}
// call sftpSync with the download and upload lists
if timeSynced && (max(len(downloadList), len(uploadList)) > 0) { // only call sftpSync if there are entries to download or upload
fmt.Println() // add a gap between list-add messages and the actual sync messages from sftpSync
sftpSync(downloadList, uploadList, manualSync)
} else if !timeSynced {
// do not call sftpSync if the client and server times are out of sync
backend.Exit(1)
}
fmt.Println("Client is synchronized with server")
}
// deletionSync removes entries from the client that have been deleted on the server (multi-client deletion)
func deletionSync(deletions []string) {
var filesDeleted bool
for _, deletion := range deletions {
filesDeleted = true // set a flag to indicate that files have been deleted (used to determine whether to print a gap between deletion and other messages)
fmt.Println(ansiDelete+deletion+backend.AnsiReset, "has been sheared, removing locally (if it exists)")
os.RemoveAll(backend.TargetLocationFormat(deletion))
}
if filesDeleted {
fmt.Println() // add a gap between deletion and other messages
}
}
// ShearRemoteFromClient removes the target file or directory from the local system and calls the server to remove it remotely and add it to the deletions list
// can safely be called in offline mode, as well, so this is the intended interface for shearing (ShearLocal should only be used directly by the server binary)
func ShearRemoteFromClient(targetLocationIncomplete string) {
deviceID := ShearLocal(targetLocationIncomplete, "") // remove the target from the local system and get the device ID of the client
if deviceID != "" { // ensure a device ID exists (online mode)
// call the server to remotely shear the target and add it to the deletions list
GetSSHOutput("libmuttonserver shear", deviceID+"\n"+
strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, FSPath), false)
}
backend.Exit(0) // sync is not required after shearing since the target has already been removed from the local system
}
// RenameRemoteFromClient renames oldLocationIncomplete to newLocationIncomplete on the local system and calls the server to perform the rename remotely and add the old target to the deletions list
// can safely be called in offline mode, as well, so this is the intended interface for renaming (RenameLocal should only be used directly by the server binary)
func RenameRemoteFromClient(oldLocationIncomplete, newLocationIncomplete string) {
RenameLocal(oldLocationIncomplete, newLocationIncomplete, false) // move the target on the local system
deviceIDList := genDeviceIDList()
if len(*deviceIDList) > 0 { // ensure a device ID exists (online mode)
// call the server to move the target on the remote system and add the old target to the deletions list
GetSSHOutput("libmuttonserver rename",
(*deviceIDList)[0].Name()+"\n"+
strings.ReplaceAll(oldLocationIncomplete, backend.PathSeparator, FSPath)+"\n"+
strings.ReplaceAll(newLocationIncomplete, backend.PathSeparator, FSPath), false)
}
backend.Exit(0)
}
// AddFolderRemoteFromClient creates a new entry-containing directory on the local system and calls the server to create the folder remotely
// can safely be called in offline mode, as well, so this is the intended interface for adding folders (AddFolderLocal should only be used directly by the server binary)
func AddFolderRemoteFromClient(targetLocationIncomplete string) {
AddFolderLocal(targetLocationIncomplete) // add the folder on the local system
GetSSHOutput("libmuttonserver addfolder", strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, FSPath), false) // call the server to create the folder remotely
backend.Exit(0)
}
// folderSync creates folders on the client (from the given list of folder names)
func folderSync(folders []string) {
for _, folder := range folders {
// store the full local path of the folder
folderFullPath := backend.TargetLocationFormat(folder)
// check if folder already exists
isFile, isAccessible := backend.TargetIsFile(folderFullPath, false, 1)
if !isFile && !isAccessible {
os.MkdirAll(folderFullPath, 0700)
} else if isFile {
fmt.Println(backend.AnsiError + "Sync failed - Failed to create folder \"" + folder + "\" - a file with the same name already exists" + backend.AnsiReset)
os.Exit(1)
}
}
}
// RunJob runs the SSH sync job
func RunJob(manualSync bool) {
// fetch remote lists
remoteEntryModMap, remoteFolders, deletions, serverTime, clientTime := getRemoteDataFromClient(manualSync)
// sync folders
folderSync(remoteFolders)
// sync deletions
deletionSync(deletions)
// fetch local lists
localEntryModMap := getLocalData()
// sync new and updated entries
syncLists(localEntryModMap, remoteEntryModMap, manualSync, serverTime, clientTime)
// exit program after successful sync
backend.Exit(0)
}
-124
View File
@@ -1,124 +0,0 @@
package sync
import (
"fmt"
"io/fs"
"os"
"strings"
"github.com/rwinkhart/MUTN/src/backend"
)
// getModTimes returns a list of all entry modification times
func getModTimes(entryList []string) []int64 {
var modList []int64
for _, file := range entryList {
modTime, _ := os.Stat(backend.TargetLocationFormat(file))
modList = append(modList, modTime.ModTime().Unix())
}
return modList
}
// genDeviceIDList returns a pointer to a slice of all registered device IDs
func genDeviceIDList() *[]fs.DirEntry {
// create a slice of all registered devices
deviceIDList, err := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices")
if err != nil {
fmt.Println(backend.AnsiError + "Failed to read the devices directory: " + err.Error() + backend.AnsiReset)
os.Exit(1)
}
return &deviceIDList
}
// ShearLocal removes the target file or directory from the local system
// returns: deviceID (on client), for use in ShearRemoteFromClient
// if the local system is a server, it will also add the target to the deletions list for all clients (except the requesting client)
// this function should only be used directly by the server binary
func ShearLocal(targetLocationIncomplete, clientDeviceID string) string {
// determine if running on a server
var onServer bool
if clientDeviceID != "" {
onServer = true
}
deviceIDList := genDeviceIDList()
// add the sheared target (incomplete, vanity) to the deletions list (if running on a server)
if onServer {
for _, device := range *deviceIDList {
if device.Name() != clientDeviceID {
_, err := os.Create(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + device.Name() + FSSpace + strings.ReplaceAll(targetLocationIncomplete, "/", FSPath))
if err != nil {
// do not print error as there is currently no way of seeing server-side errors
// failure to add the target to the deletions list will exit the program and result in a client re-uploading the target (non-critical)
os.Exit(1)
}
}
}
}
// get the full targetLocation path and remove the target
targetLocationComplete := backend.TargetLocationFormat(targetLocationIncomplete)
if !onServer { // error if target does not exist on client, needed because os.RemoveAll does not return an error if target does not exist
backend.TargetIsFile(targetLocationComplete, true, 0)
}
err := os.RemoveAll(targetLocationComplete)
if err != nil {
fmt.Println(backend.AnsiError + "Failed to remove local target: " + err.Error() + backend.AnsiReset)
os.Exit(1)
}
if !onServer && len(*deviceIDList) > 0 { // return the device ID if running on the client and a device ID exists (online mode)
return (*deviceIDList)[0].Name()
}
return ""
// do not exit program, as this function is used as part of ShearRemoteFromClient
}
// RenameLocal renames oldLocationIncomplete to newLocationIncomplete on the local system
// this function should only be used directly by the server binary
func RenameLocal(oldLocationIncomplete, newLocationIncomplete string, verifyOldLocationExists bool) {
// get full paths for both locations
oldLocation := backend.TargetLocationFormat(oldLocationIncomplete)
newLocation := backend.TargetLocationFormat(newLocationIncomplete)
if verifyOldLocationExists {
backend.TargetIsFile(oldLocation, true, 0)
}
// ensure newLocation does not exist
_, isAccessible := backend.TargetIsFile(newLocation, false, 0)
if isAccessible {
fmt.Println(backend.AnsiError + "\"" + newLocation + "\" already exists" + backend.AnsiReset)
os.Exit(1)
}
// rename oldLocation to newLocation
err := os.Rename(oldLocation, newLocation)
if err != nil {
fmt.Println(backend.AnsiError + "Failed to rename - does the target containing directory exist?" + backend.AnsiReset)
}
// do not exit program, as this function is used as part of RenameRemoteFromClient
}
// AddFolderLocal creates a new entry-containing directory on the local system
// this function should only be used directly by the server binary
func AddFolderLocal(targetLocationIncomplete string) {
// get the full targetLocation path and create the target
targetLocationComplete := backend.TargetLocationFormat(targetLocationIncomplete)
err := os.Mkdir(targetLocationComplete, 0700)
if err != nil {
if os.IsExist(err) {
fmt.Println(backend.AnsiError + "Directory already exists" + backend.AnsiReset)
os.Exit(1)
} else {
fmt.Println(backend.AnsiError + "Failed to create directory: " + err.Error() + backend.AnsiReset)
os.Exit(1)
}
}
// do not exit program, as this function is used as part of AddFolderRemoteFromClient
}
-54
View File
@@ -1,54 +0,0 @@
//go:build !windows
package sync
import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"io/fs"
"os"
"path/filepath"
)
// WalkEntryDir walks the entry directory and returns lists of all files and directories found (two separate lists)
// regardless of platform, all paths are stored with forward slashes (UNIX-style)
func WalkEntryDir() ([]string, []string) {
// define file/directory containing slices so that they may be accessed by the anonymous WalkDir function
var fileList []string
var dirList []string
// walk entry directory
_ = filepath.WalkDir(backend.EntryRoot,
func(fullPath string, entry fs.DirEntry, err error) error {
// check for errors encountered while walking directory
if err != nil {
if os.IsNotExist(err) {
fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+os.Args[0], "init"+"\" to create it"+backend.AnsiReset)
} else {
// otherwise, print the source of the error
fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset)
}
os.Exit(1)
}
// trim root path from each path before storing
trimmedPath := fullPath[rootLength:]
// append the path to the appropriate slice
if !entry.IsDir() {
fileList = append(fileList, trimmedPath)
} else {
dirList = append(dirList, trimmedPath)
}
return nil
})
return fileList, dirList
}
// joinErrorWithEXE joins and returns the two strings it is provided (in error format) with the executable name inserted between them
func joinErrorWithEXE(firstHalf, secondHalf string) string {
return backend.AnsiError + firstHalf + os.Args[0] + secondHalf + backend.AnsiReset
}
-55
View File
@@ -1,55 +0,0 @@
//go:build windows
package sync
import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"io/fs"
"os"
"path/filepath"
"strings"
)
// WalkEntryDir walks the entry directory and returns lists of all files and directories found (two separate lists)
// regardless of platform, all paths are stored with forward slashes (UNIX-style)
func WalkEntryDir() ([]string, []string) {
// define file/directory containing slices so that they may be accessed by the anonymous WalkDir function
var fileList []string
var dirList []string
// walk entry directory
_ = filepath.WalkDir(backend.EntryRoot,
func(fullPath string, entry fs.DirEntry, err error) error {
// check for errors encountered while walking directory
if err != nil {
if os.IsNotExist(err) {
fmt.Println(joinErrorWithEXE("The entry directory does not exist - run \"", " init"+"\" to create it"))
} else {
// otherwise, print the source of the error
fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset)
}
os.Exit(1)
}
// trim root path from each path before storing and replace backslashes with forward slashes
trimmedPath := strings.ReplaceAll(fullPath[rootLength:], "\\", "/")
// append the path to the appropriate slice
if !entry.IsDir() {
fileList = append(fileList, trimmedPath)
} else {
dirList = append(dirList, trimmedPath)
}
return nil
})
return fileList, dirList
}
// joinErrorWithEXE joins and returns the two strings it is provided (in error format) with the executable name inserted between them
func joinErrorWithEXE(firstHalf, secondHalf string) string {
return backend.AnsiError + firstHalf + os.Args[0][strings.LastIndex(os.Args[0], "\\")+1:] + secondHalf + backend.AnsiReset
}
-32
View File
@@ -1,32 +0,0 @@
package sync
import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"time"
"github.com/rwinkhart/MUTN/src/backend"
)
// DeviceIDGen generates a new client device ID and registers it with the server
// device IDs are only needed for online synchronization
// device IDs are guaranteed unique as the current UNIX time is appended to them
// returns the remote EntryRoot and OS type (OS type is a bool: backend.IsWindows)
func DeviceIDGen() (string, string) {
deviceIDPrefix, _ := os.Hostname()
deviceIDSuffix := backend.StringGen(rand.Intn(32)+48, true, 0.2, true) + "-" + strconv.FormatInt(time.Now().Unix(), 10)
deviceID := deviceIDPrefix + "-" + deviceIDSuffix
_, err := os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server)
if err != nil {
fmt.Println(backend.AnsiError + "Failed to create local device ID file: " + err.Error() + backend.AnsiReset)
}
// register device ID with server and fetch remote EntryRoot and OS type
//manualSync is true so the user is alerted if device ID registration fails
sshEntryRootSSHIsWindows := strings.Split(GetSSHOutput("libmuttonserver register", deviceID, true), FSSpace)
return sshEntryRootSSHIsWindows[0], sshEntryRootSSHIsWindows[1]
}
-16
View File
@@ -1,16 +0,0 @@
package sync
import (
"fmt"
"golang.org/x/crypto/ssh/terminal"
"os"
)
// inputKeyFilePassphrase prompts the user for a passphrase for an SSH key file
// TODO support non-CLI implementations
func inputKeyFilePassphrase() []byte {
fmt.Print("\nEnter passphrase for your SSH keyfile: ")
passphrase, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
return passphrase
}
-59
View File
@@ -1,59 +0,0 @@
package sync
import (
"fmt"
"os"
"strings"
"time"
"github.com/rwinkhart/MUTN/src/backend"
)
// GetRemoteDataFromServer prints to stdout the remote entries, mod times, folders, and deletions
// lists in output are separated by FSSpace
// output is meant to be captured over SSH for interpretation by the client
func GetRemoteDataFromServer(clientDeviceID string) {
entryList, dirList := WalkEntryDir()
modList := getModTimes(entryList)
deletionsList, err := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "deletions")
if err != nil {
fmt.Println(backend.AnsiError + "Failed to read the deletions directory: " + err.Error() + backend.AnsiReset)
os.Exit(1)
}
// print the current UNIX timestamp to stdout
fmt.Print(time.Now().Unix())
// print the lists to stdout
// entry list
fmt.Print(FSSpace)
for _, entry := range entryList {
fmt.Print(FSMisc + entry)
}
// modification time list
fmt.Print(FSSpace)
for _, mod := range modList {
fmt.Print(FSMisc)
fmt.Print(mod)
}
// directory/folder list
fmt.Print(FSSpace)
for _, dir := range dirList {
fmt.Print(FSMisc + dir)
}
// deletions list
fmt.Print(FSSpace)
for _, deletion := range deletionsList {
// print deletion if it is relevant to the current client device
affectedIDTargetLocationIncomplete := strings.Split(deletion.Name(), FSSpace)
if affectedIDTargetLocationIncomplete[0] == clientDeviceID {
fmt.Print(FSMisc + strings.ReplaceAll(affectedIDTargetLocationIncomplete[1], FSPath, "/"))
// assume successful client deletion and remove deletions file (if assumption is somehow false, worst case scenario is that the client will re-upload the deleted entry)
_ = os.Remove(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + deletion.Name()) // error ignored; function not run from a user-facing argument and thus the error would not be visible
}
}
}
-8
View File
@@ -1,8 +0,0 @@
## Installation
MUTN is still in early development and thus no installation packages are officially distributed.
For now, please [compile from source](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/build.md).
After compiling and placing the binaries in your $PATH, it is highly recommended to also download and correctly place/source the relevant [shell completions scripts](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/completions.md).
Please see the [usage guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/usage.md) for help getting started.
+1
View File
@@ -6,3 +6,4 @@
- [Extra blank lines after nested list items](https://github.com/charmbracelet/glamour/issues/102)
- [Incorrect wrapping of text in lists](https://github.com/charmbracelet/glamour/issues/56)
- [Excessive binary size and increased program startup time](https://github.com/charmbracelet/glamour/issues/288)
- Relevant [libmutton bugs](https://github.com/rwinkhart/libmutton/blob/main/wiki/bugs.md)
+2 -4
View File
@@ -1,13 +1,11 @@
## Building
This repository is currently home to both the MUTN client and the general libmutton server software.
Official binaries are stripped of debug info for size and built without CGO (except for distribution packages) for portability, as follows:
```
CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath ./mutn.go
CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath ./libmuttonserver.go
```
Additionally, some custom build tags can be used to create different binaries. The following tags are not used in official builds:
- `noMarkdown`: Creates a binary without Markdown support (much smaller binary size and faster launch time)
- `BEAN`: Creates a binary with the experimental [BEAN](https://github.com/Trojan2021/BEAN) Markdown renderer in place of Glamour
- `noMarkdown`: Creates a binary without Markdown support (much smaller binary size and faster launch time VS Glamour)
- `wsl`: Allows creating a Linux binary that can interact with the Windows clipboard (for WSL)
- `termux`: Allows creating a Linux binary that can interact with the Termux clipboard (for Android)
+17
View File
@@ -0,0 +1,17 @@
## Installation
MUTN is still in early development and thus no installation packages are officially distributed.
For now, please manually install the binaries from the [latest release](https://github.com/rwinkhart/MUTN/releases) or [compile from source](https://github.com/rwinkhart/MUTN/blob/main/wiki/build.md). All pre-built binaries were compiled with CGO disabled and thus are libc-independent.
Additionally, MUTN is available as a source package ("[mutn](https://aur.archlinux.org/packages/mutn)") on the AUR.
Please note that the server binary (available in [libmutton releases](https://github.com/rwinkhart/libmutton/releases)) must be called "libmuttonserver" in order for clients to successfully reach it.
After placing the binaries in your $PATH, it is highly recommended to also download and correctly place/source the relevant [shell completions scripts](https://github.com/rwinkhart/MUTN/blob/main/wiki/completions.md).
Please see the [usage guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/usage.md) for help getting started.
### Dependencies (required for all installations)
- GnuPG command-line utility (`gpg` command; will not be required in the future) for encryption/decryption
- A text editor (preferably CLI-based) for writing entry notes
- A private key for SSH key-based authentication is required to use MUTN/libmutton in online/synced mode
-10
View File
@@ -1,10 +0,0 @@
## Planned Breaking Changes
Leading up to the v1.0.0 release, breaking changes are both expected and planned. These changes are expected to require manual intervention from the end-user, and thus MUTN/libmutton should not be used prior to v1.0.0 if this is not acceptable.
These changes include, but may expand beyond the following:
- Migration to Go-native encryption (no reliance on GnuPG)
- Will be based on symmetrical encryption
- Will eventually allow combining multiple common encryption algorithms (cascading encryption)
- Password aging data will be stored for each entry (to remind the user when it is time to change passwords)
- Will be included in entry names or in external file (to prevent needing to decrypt entries to access this information)
-7
View File
@@ -1,7 +0,0 @@
## Known Bugs - libmutton
- On Windows, GPG is sometimes (seems unpredictable) incredibly slow to start (often after a reboot), leading to many operations seemingly hanging
- **This will be addressed** in the migration off of GPG that will take place before v1.0.0
- If a client is reconfigured to use a new device ID, the old one will remain present on the server. This will not cause any immediate issues, however it will lead to the server creating unnecessary deletions files for the old device ID. Currently, it is recommended to manually delete the old device ID from the server's "devices" directory.
- **This will be addressed** in v0.2.1
- Using a password-protected SSH identity file will prompt for the key's password multiple times when syncing
- **This will be addressed** in v0.2.1
-11
View File
@@ -1,11 +0,0 @@
## Clipboard Troubleshooting + Clipboard Manager Rant
### Clipboard managers can break libmutton-based password managers
***
The intended way for libmutton to interact with the system clipboard is for it to clear it 30 seconds after copying a field. **Unfortunately, this does not work by default on all systems due to the prevalence of clipboard managers.**
Clipboard managers save a history of what has been copied to the clipboard, which is already a big enough issue on its own for people who copy sensitive information to their clipboard. Some **clipboard managers simply will not allow the clipboard to be empty** and will replace its contents with the last copied item if you attempt to clear it. One such naughty clipboard manager is **KDE Klipper**, which comes **packaged into KDE Plasma** and is typically **enabled by default** on most distributions. Due to this behavior, **KDE Klipper breaks libmutton's clipboard clearing functionality** and should not be left enabled.
It is likely other popular clipboard managers exhibit this behavior. I noticed it with KDE Klipper, which is what prompted me to create this wiki page. **Clipboard managers should not be enabled by default in any environment** or distribution due to their **potential security implications**.
### Termux cannot clear the clipboard from the background
***
If using libmutton on Termux (Android), the clipboard may not successfully be cleared after the 30 second timeout period if Termux is not actively in the foreground when the sleep timer expires. This is an unfortunate side-effect of running on Android and cannot be easily fixed. Due to Termux being at the bottom of the platform support priority list, I will not be investing time into working around this.
-49
View File
@@ -1,49 +0,0 @@
## Developer Guide (for third-party libmutton-based clients)
**Important Notice**: libmutton is in early development and is currently a moving target to develop off of. Feel free to jump in early, but greater change stability will be met with release v1.0.0. Check [here](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/breaking.md) for planned breaking changes.
libmutton was designed to be usable as a library for building other compatible password managers off of. [MUTN](https://github.com/rwinkhart/MUTN) is the official reference CLI password manager, however libmutton can be implemented in many other unique ways.
All functionality in the `backend` and `sync` packages are designed to be used in other implementations.
If any functionality in these two packages proves to be difficult to implement in a third-party client, please open an issue so that it can be addressed.
## Build Tags
Custom build tags can (and sometimes must) be used to achieve desired results.
These are as follows:
- `returnOnExit`: If making an interactive interface (GUI/TUI/interactive CLI), you probably need to use this build tag. Without it, your entire program will exit after any given operation is completed. This behavior is only desired for non-interactive CLI implementations, such as MUTN. Currently, errors will result in the program exiting **even with this build tag**. This may be changed in the future (under evaluation).
- `wsl`: Allows creating a Linux binary that can interact with the Windows clipboard (for WSL)
- `termux`: Allows creating a Linux binary that can interact with the Termux clipboard (for Android)
## Required Arguments
libmutton-based password manager clients should accept at least one specific required argument, as well as another recommended one:
- `clipclear`: This argument is required for correct functionality. In order to clear the clipboard on a timer, libmutton-based password managers call another instance of their executable with the `clipclear` argument (e.g. `mutn clipclear`) with the intended clipboard contents provided via STDIN. If after 30 seconds the clipboard contents have not changed, they are cleared. Please accept a `clipclear` argument that is processed before the launch of any interactive interface. All this argument needs to do is call `backend.ClipClearArgument()`.
- `init`: This argument is optional, but recommended for CLI interfaces. Some error messages request the user to use the `init` argument to fix configuration issues. If the argument does not exist, this may confuse the user.
## Configuration
libmutton-based password manager clients should all share the same INI configuration file.
On UNIX-like systems, this is located at `~/.config/libmutton/libmutton.ini`. On Windows, it is located at `~\AppData\Local\libmutton\config\libmutton.ini`.
### Base `libmutton.ini` Layout
The current base layout of `libmutton.ini` will change leading up to release v1.0.0. As of right now, the specification is as follows:
```
[LIBMUTTON]
gpgID = <gpg key id>
sshUser = <remote user>
sshIP = <remote ip>
sshPort = <remote ssh port>
sshKey = <ssh private key identity file path>
sshKeyProtected = <true/false>
sshEntryRoot = <remote entry root>
sshIsWindows = <true/false>
```
If creating a third-party client that requires extra configuration to be stored, please use the same file and create a new INI section for your application-specific configuration, e.g.:
```
[THIRD-PARTY-CLIENT-NAME]
configKey = <value>
```
This ensures that a user can use multiple client applications with the same configuration while avoiding conflicts.
# Relevant Bugs Affecting Third-Party Implementations
- Password-protected SSH identity files currently only prompt for password entry in the CLI, and thus they are not yet supported in GUI/TUI implementations
-8
View File
@@ -1,8 +0,0 @@
## Migrating From Other Password Managers
**Important Notice**: The libmutton entry format is not final and has two [breaking changes planned prior to release v1.0.0](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/breaking.md). This guide will be updated accordingly.
### pass
libmutton-based password managers *currently* use GnuPG encryption and an entry format similar to that of [pass](https://www.passwordstore.org/). Because of this, any entries in `pass` format can simply be dropped into `~/.local/share/libmutton`.
### sshyp
sshyp, though also `pass`-compatible, makes some changes to the entry format that take effect once the entry has been imported. The changes made by sshyp are not compatible with libmutton, and as such sshyp entries must be converted before they can be used. A script for doing that has been created and is available in the sshyp extension store. Simply run `sshyp tweak`, go to the "extension management" menu, and download the "export-to-libmutton" extension. After doing this, the `sshyp export` command can be used to export entries in libmutton format.
### Other
The formats for many other password managers can be converted to the `pass` format with community scripts. Some of these scripts are listed [here](https://www.passwordstore.org/#migration). Once converted, entries can be dropped into `~/.local/share/libmutton`.
-24
View File
@@ -1,24 +0,0 @@
## MUTN Wiki
### MUTN-specific Information
[Installation](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/install.md)
[Building](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/build.md)
[Setup/Usage](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/usage.md)
[Shell Completions Troubleshooting](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/completions.md)
[Known Bugs](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/bugs.md)
---
### libmutton Information (will likely be moved to libmutton repository in the future)
[Planned Breaking Changes](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/breaking.md)
[Migrating From Other Password Managers](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/migration.md)
[Clipboard Troubleshooting](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/clipboard.md)
[Developer Guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/developers.md)
[Known Bugs](https://github.com/rwinkhart/MUTN/blob/main/wiki/libmutton/bugs.md)
+2 -2
View File
@@ -8,13 +8,13 @@ libmutton operates on a client-server model, and thus sync support requires you
For security reasons, libmutton deliberately does not support password-based SSH authentication; you must use key-based authentication to connect to your server (password-protected keys are also supported). You are responsible for setting up SSH connectivity on your own.
The libmutton server software is shipped as its own dedicated binary and must be installed on the server and configured with `libmuttonserver init`.
The libmutton server software is shipped as its own dedicated binary (in [libmutton releases](https://github.com/rwinkhart/libmutton/releases)) and must be installed on the server and configured with `libmuttonserver init`. The server binary _**MUST**_ be in your $PATH and _**MUST**_ be named "libmuttonserver" for clients to successfully reach it.
Once this has been done, you may proceed with the client setup:
1. Install MUTN
2. Run `mutn init` and follow the prompts
3. If you already have entries on the server, sync them using `mutn sync`
4. Optionally, shell completions (Bash, ZSH, and PowerShell 7+) can be [enabled with your shell's respective method](https://github.com/rwinkhart/MUTN/blob/main/wiki/MUTN/completions.md)
4. Optionally, shell completions (Bash, ZSH, and PowerShell 7+) can be [enabled with your shell's respective method](https://github.com/rwinkhart/MUTN/blob/main/wiki/completions.md)
### Tips
#### Operating on Passwords