From 2f34fc2c0cad489a4ac7c6033ae67a18b4c2c9e9 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 8 May 2025 19:44:51 -0400 Subject: [PATCH] Port to latest libmutton/rcw development versions --- go.mod | 18 +++++++++--------- go.sum | 28 ++++++++++++++-------------- mutn.go | 4 ++-- src/cli/1globals.go | 7 +++++++ src/cli/edit.go | 8 ++++---- src/cli/entryReader.go | 2 +- src/cli/utilitiesMisc.go | 28 +--------------------------- 7 files changed, 38 insertions(+), 57 deletions(-) diff --git a/go.mod b/go.mod index f9d0006..aaf53c3 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,12 @@ module github.com/rwinkhart/MUTN -go 1.24.2 +go 1.24.3 require ( github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514 github.com/charmbracelet/glamour v0.7.0 - github.com/rwinkhart/libmutton v0.3.2-0.20250505000457-f549b591c0cf - github.com/rwinkhart/rcw v0.0.0-20250505000323-5975c71b4f68 - golang.org/x/term v0.31.0 + github.com/rwinkhart/libmutton v0.3.2-0.20250508234242-fb83d29a23e0 + golang.org/x/term v0.32.0 ) require ( @@ -33,16 +32,17 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/rwinkhart/convertroman v0.2.0 // indirect github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea // indirect + github.com/rwinkhart/rcw v0.0.0-20250508234041-b49d9f1eea42 // indirect github.com/stretchr/testify v1.8.4 // indirect github.com/yuin/goldmark v1.7.10 // indirect github.com/yuin/goldmark-emoji v1.0.6 // indirect golang.design/x/clipboard v0.7.0 // indirect - golang.org/x/crypto v0.37.0 // indirect - golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0 // indirect - golang.org/x/image v0.26.0 // indirect - golang.org/x/mobile v0.0.0-20250408133729-978277e7eaf7 // indirect + golang.org/x/crypto v0.38.0 // indirect + golang.org/x/exp/shiny v0.0.0-20250506013437-ce4c2cf36ca6 // indirect + golang.org/x/image v0.27.0 // indirect + golang.org/x/mobile v0.0.0-20250506005352-78cd7a343bde // indirect golang.org/x/net v0.39.0 // indirect - golang.org/x/sys v0.32.0 // indirect + golang.org/x/sys v0.33.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect ) diff --git a/go.sum b/go.sum index 913fa4f..d96e2bd 100644 --- a/go.sum +++ b/go.sum @@ -61,12 +61,12 @@ github.com/rwinkhart/convertroman v0.2.0 h1:otUm939eXT77q/Lr31mJtMwVWEw0RjEUB71g github.com/rwinkhart/convertroman v0.2.0/go.mod h1:Af6HqvX0EIM4Y3HcnNXbbRey1dLasGB7WU0+3Cowgmw= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/rwinkhart/libmutton v0.3.2-0.20250505000457-f549b591c0cf h1:zbI8s76LFY7rFpVMASVJ0Xcf4S7wtxY4u3I0zZ6ULb4= -github.com/rwinkhart/libmutton v0.3.2-0.20250505000457-f549b591c0cf/go.mod h1:YrWPswaiINf2VGalvQU6AalQQN5kkWaIOagXEEeypF8= +github.com/rwinkhart/libmutton v0.3.2-0.20250508234242-fb83d29a23e0 h1:XoJyvbNJBU3HbYHlyYBh3VKzVad10wOZ/feFkBTvxWU= +github.com/rwinkhart/libmutton v0.3.2-0.20250508234242-fb83d29a23e0/go.mod h1:IW7espY4xtdVTd0/6THtmRadR+utzH1dDXcgrP3VqlM= github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea h1:VE2ti/AE4Y3kgnyK+J5c5hpddE+dKHpsFch3K2R6puQ= github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea/go.mod h1:t+YkvAdnTKTrg4d469tw3K+GCUzX/Bja4h8yKjSIsGs= -github.com/rwinkhart/rcw v0.0.0-20250505000323-5975c71b4f68 h1:2+mAXmmlt28JyyCdKih3UN4QWE8aZu2hzos8jH8J8cU= -github.com/rwinkhart/rcw v0.0.0-20250505000323-5975c71b4f68/go.mod h1:giXrq9o5a7bwMSuMvz+5bb2+qbM+zV4pXaG/SceXfLM= +github.com/rwinkhart/rcw v0.0.0-20250508234041-b49d9f1eea42 h1:/vsBCwHP22cmqrtjsRB1OcPcb+sckktdeFlHKmhzD54= +github.com/rwinkhart/rcw v0.0.0-20250508234041-b49d9f1eea42/go.mod h1:6/TBegxRkK+FbGEmcxqDs4entuCX45cqpYOYKUv2MI0= github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0 h1:KRbqimv9Eexf3VB2FrRAQ4v2fGGu7gt3ayMgdT0FNao= github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -89,14 +89,14 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= -golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= -golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0 h1:tMSqXTK+AQdW3LpCbfatHSRPHeW6+2WuxaVQuHftn80= -golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:ygj7T6vSGhhm/9yTpOQQNvuAUFziTH7RUiH74EoE2C8= -golang.org/x/image v0.26.0 h1:4XjIFEZWQmCZi6Wv8BoxsDhRU3RVnLX04dToTDAEPlY= -golang.org/x/image v0.26.0/go.mod h1:lcxbMFAovzpnJxzXS3nyL83K27tmqtKzIJpctK8YO5c= -golang.org/x/mobile v0.0.0-20250408133729-978277e7eaf7 h1:8MGTx39304caZ/OMsjPfuxUoDGI2tRas92F5x97tIYc= -golang.org/x/mobile v0.0.0-20250408133729-978277e7eaf7/go.mod h1:ftACcHgQ7vaOnQbHOHvXt9Y6bEPHrs5Ovk67ClwrPJA= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/exp/shiny v0.0.0-20250506013437-ce4c2cf36ca6 h1:OKqTTvTtXrxCm19HtttLTgySk+NUt9mcsKAq827Ltz4= +golang.org/x/exp/shiny v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:ygj7T6vSGhhm/9yTpOQQNvuAUFziTH7RUiH74EoE2C8= +golang.org/x/image v0.27.0 h1:C8gA4oWU/tKkdCfYT6T2u4faJu3MeNS5O8UPWlPF61w= +golang.org/x/image v0.27.0/go.mod h1:xbdrClrAUway1MUTEZDq9mz/UpRwYAkFFNUslZtcB+g= +golang.org/x/mobile v0.0.0-20250506005352-78cd7a343bde h1:klxJIHHSTIJItwhIaVT2EydFn+8urdz5cnisEO0Uy6I= +golang.org/x/mobile v0.0.0-20250506005352-78cd7a343bde/go.mod h1:T9M84Yhr+nZUSLopZMA95xrVLgn6hC6YwibPkqR8/hw= 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/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= @@ -128,8 +128,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= -golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= -golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= +golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= +golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= 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= diff --git a/mutn.go b/mutn.go index 5309cdd..a78725e 100644 --- a/mutn.go +++ b/mutn.go @@ -37,7 +37,7 @@ func main() { case "show", "-s": cli.EntryReaderDecrypt(targetLocation, false) case "copy": - core.CopyArgument(targetLocation, 0, cli.GetRCWPassphrase()) + core.CopyArgument(targetLocation, 0) case "edit": cli.EditEntryField(targetLocation, true, 0) case "gen": @@ -81,7 +81,7 @@ func main() { default: cli.HelpCopy() } - core.CopyArgument(targetLocation, field, cli.GetRCWPassphrase()) + core.CopyArgument(targetLocation, field) case "edit": var field int // indicates which (numbered) field to edit switch args[3] { diff --git a/src/cli/1globals.go b/src/cli/1globals.go index c9487af..46b0ae1 100644 --- a/src/cli/1globals.go +++ b/src/cli/1globals.go @@ -3,6 +3,7 @@ package cli import ( "os" + "github.com/rwinkhart/libmutton/core" "golang.org/x/term" ) @@ -16,3 +17,9 @@ const ( AnsiBold = "\033[1m" ansiBlackOnWhite = "\033[38;5;0;48;5;15m" ) + +func init() { + core.GetPassphrase = func() []byte { + return inputHidden("RCW Passphrase:") + } +} diff --git a/src/cli/edit.go b/src/cli/edit.go index 83a6b9b..4818af2 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -22,16 +22,16 @@ func RenameCli(oldLocationIncomplete string) { // 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 := core.GetOldEntryData(targetLocation, field, GetRCWPassphrase()) + unencryptedEntry := core.GetOldEntryData(targetLocation, field) // edit the field switch field { case 0: - unencryptedEntry[field] = string(GetRCWPassphrase()) + unencryptedEntry[field] = string(inputHidden("Password:")) case 1: unencryptedEntry[field] = input("Username:") case 2: - unencryptedEntry[field] = string(GetRCWPassphrase()) + unencryptedEntry[field] = string(inputHidden("TOTP secret:")) case 3: unencryptedEntry[field] = input("URL:") case 4: // edit notes fields @@ -54,7 +54,7 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) { // GenUpdate generates a new password for an entry at targetLocation (user input). func GenUpdate(targetLocation string, hideSecrets bool) { // fetch old entry data - unencryptedEntry := core.GetOldEntryData(targetLocation, 0, GetRCWPassphrase()) + unencryptedEntry := core.GetOldEntryData(targetLocation, 0) // generate a new password unencryptedEntry[0] = inputPasswordGen() diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index 0a9169f..b0e1514 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -71,7 +71,7 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) { // EntryReaderDecrypt is a wrapper for EntryReader that first decrypts an RCW-wrapped file before sending it to EntryReader. func EntryReaderDecrypt(targetLocation string, hideSecrets bool) { if isFile, _ := core.TargetIsFile(targetLocation, true, 2); isFile { - EntryReader(core.DecryptFileToSlice(targetLocation, GetRCWPassphrase()), hideSecrets, false) // never sync if decrypting straight to EntryReader, as this means the entry could not have been modified + EntryReader(core.DecryptFileToSlice(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 } diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index afb4a4c..fdd37df 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -8,35 +8,9 @@ import ( "github.com/rwinkhart/libmutton/core" "github.com/rwinkhart/libmutton/sync" - "github.com/rwinkhart/rcw/daemon" - "github.com/rwinkhart/rcw/wrappers" "golang.org/x/term" ) -// GetRCWPassphrase retrieves the RCW passphrase from the most accessible source. -// It first attempts to retrieve from the RCW daemon, then from user input. -// If it does not find an RCW daemon, it launches one to cache the passphrase. -func GetRCWPassphrase() []byte { - // request passphrase from RCW daemon - passphrase := daemon.CallDaemonIfOpen() - - // if no passphrase was retrieved, request it from the user - if passphrase == nil { - for { - passphrase = inputHidden("RCW Passphrase:") - err := wrappers.RunSanityCheck(core.ConfigDir+"/sanity.rcw", passphrase) - if err != nil { - fmt.Println(core.AnsiError + "Failed to encrypt - " + err.Error() + core.AnsiReset) - continue - } - break - } - // since no daemon was found earlier, start a new one - core.LaunchRCWDProcess(string(passphrase)) - } - return passphrase -} - // input prompts the user for input and returns the input as a string. func input(prompt string) string { fmt.Print("\n" + prompt + " ") @@ -111,7 +85,7 @@ func inputPasswordGen() string { func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets bool) { if core.EntryIsNotEmpty(unencryptedEntry) { // write the entry to the target location - core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n")), GetRCWPassphrase()) + core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n"))) // preview the entry fmt.Println(AnsiBold + "\nEntry Preview:" + core.AnsiReset) EntryReader(unencryptedEntry, hideSecrets, true)