diff --git a/go.mod b/go.mod index 91ab07f..f470016 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,13 @@ go 1.24.2 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.20250504220509-826d94bc4397 - github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5 + github.com/rwinkhart/libmutton v0.3.2-0.20250504234931-3404fc74823c + github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b golang.org/x/term v0.31.0 ) require ( + github.com/Microsoft/go-winio v0.6.2 // indirect github.com/alecthomas/chroma/v2 v2.16.0 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect @@ -31,6 +32,7 @@ require ( 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/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea // 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 diff --git a/go.sum b/go.sum index fbf89b2..dd44ffd 100644 --- a/go.sum +++ b/go.sum @@ -59,10 +59,14 @@ 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.3.2-0.20250504220509-826d94bc4397 h1:+Zlv62ZB7QTIFDNltMj6rm+7huo05N99BBWhoyVVJQc= -github.com/rwinkhart/libmutton v0.3.2-0.20250504220509-826d94bc4397/go.mod h1:9a4EYsPTLVI4Je7ql3jsMz7B9JP4PaRZSuTR/BctBIU= -github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5 h1:BX31d76TLGZqeukYECLFPkLD+SS/CAV12Lkdlc6UuGM= -github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5/go.mod h1:giXrq9o5a7bwMSuMvz+5bb2+qbM+zV4pXaG/SceXfLM= +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.20250504234931-3404fc74823c h1:DzLYC9xNqoJnoFe8rg+/n9XMNX7HOBoUUzlSDqIZZx0= +github.com/rwinkhart/libmutton v0.3.2-0.20250504234931-3404fc74823c/go.mod h1:XsXDBz9SQ8QHLkjdzviCcoI/cr7pUnISst+03MB+c8M= +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-20250504233845-9314852f061b h1:eWN9ogSzNE8KcFcoIBgrdgMCOUhxnV7m+SJ9Z3SCnPU= +github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b/go.mod h1:giXrq9o5a7bwMSuMvz+5bb2+qbM+zV4pXaG/SceXfLM= 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= diff --git a/mutn.go b/mutn.go index d42f235..5309cdd 100644 --- a/mutn.go +++ b/mutn.go @@ -158,6 +158,8 @@ func main() { switch args[1] { case "clipclear": core.ClipClearArgument() + case "startrcwd": + core.RCWDArgument() case "sync": cli.RunJobWrapper(true) case "init": diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index 000244e..afb4a4c 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -8,22 +8,33 @@ 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 user. -// TODO attempt to retrieve from RCW daemon +// 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 { - 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 + // 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 } - return passphrase + // 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.