Do not wait for RCWD socket file creation

This commit is contained in:
2025-05-08 19:42:42 -04:00
parent 008088e2d6
commit fb83d29a23
3 changed files with 24 additions and 18 deletions
+21 -15
View File
@@ -5,7 +5,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"time"
"github.com/rwinkhart/rcw/daemon" "github.com/rwinkhart/rcw/daemon"
"github.com/rwinkhart/rcw/wrappers" "github.com/rwinkhart/rcw/wrappers"
@@ -29,21 +28,34 @@ func DecryptFileToSlice(targetLocation string) []string {
} }
// decrypt data using RCW daemon // decrypt data using RCW daemon
launchRCWDProcess() passphrase := launchRCWDProcess()
return strings.Split(string(daemon.GetDec(encBytes)), "\n") if passphrase == nil {
// if daemon is already running, use it to decrypt the data
return strings.Split(string(daemon.GetDec(encBytes)), "\n")
}
// if the daemon is not already running, use wrappers.Decrypt
// directly to avoid waiting for socket file creation
decBytes, err := wrappers.Decrypt(encBytes, passphrase)
return strings.Split(string(decBytes), "\n")
} }
// EncryptBytes encrypts a byte slice using RCW and returns the encrypted data. // EncryptBytes encrypts a byte slice using RCW and returns the encrypted data.
func EncryptBytes(decBytes []byte) []byte { func EncryptBytes(decBytes []byte) []byte {
launchRCWDProcess() passphrase := launchRCWDProcess()
return daemon.GetEnc(decBytes) if passphrase == nil {
// if daemon is already running, use it to encrypt the data
return daemon.GetEnc(decBytes)
}
// if the daemon is not already running, use wrappers.Encrypt
// directly to avoid waiting for socket file creation
return wrappers.Encrypt(decBytes, passphrase)
} }
// launchRCWDProcess launches an RCW daemon to cache a passphrase. // launchRCWDProcess launches an RCW daemon to cache a passphrase.
// It returns immediately if the daemon appears to be already running. // If the daemon is not already running, it returns the passphrase (otherwise returns nil).
func launchRCWDProcess() { func launchRCWDProcess() []byte {
if daemon.IsOpen() { if daemon.IsOpen() {
return return nil
} }
var passphrase []byte var passphrase []byte
for { for {
@@ -58,11 +70,5 @@ func launchRCWDProcess() {
writeToStdin(cmd, string(passphrase)) writeToStdin(cmd, string(passphrase))
cmd.Start() cmd.Start()
// block until socket file is created return passphrase
for {
if daemon.IsOpen() {
break
}
time.Sleep(100 * time.Millisecond)
}
} }
+1 -1
View File
@@ -6,7 +6,7 @@ require (
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727 github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727
github.com/pkg/sftp v1.13.9 github.com/pkg/sftp v1.13.9
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481
github.com/rwinkhart/rcw v0.0.0-20250508202611-f447c8a28b43 github.com/rwinkhart/rcw v0.0.0-20250508234041-b49d9f1eea42
golang.design/x/clipboard v0.7.0 // only for Android builds golang.design/x/clipboard v0.7.0 // only for Android builds
golang.org/x/crypto v0.38.0 golang.org/x/crypto v0.38.0
gopkg.in/ini.v1 v1.67.0 gopkg.in/ini.v1 v1.67.0
+2 -2
View File
@@ -19,8 +19,8 @@ github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e84
github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
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 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/peercred-mini v0.0.0-20250407033241-c09add2eceea/go.mod h1:t+YkvAdnTKTrg4d469tw3K+GCUzX/Bja4h8yKjSIsGs=
github.com/rwinkhart/rcw v0.0.0-20250508202611-f447c8a28b43 h1:TFHU8EkCP0AxAExfA/k5TLfFt7Nja2AmPA1DdVzgRX8= github.com/rwinkhart/rcw v0.0.0-20250508234041-b49d9f1eea42 h1:/vsBCwHP22cmqrtjsRB1OcPcb+sckktdeFlHKmhzD54=
github.com/rwinkhart/rcw v0.0.0-20250508202611-f447c8a28b43/go.mod h1:6/TBegxRkK+FbGEmcxqDs4entuCX45cqpYOYKUv2MI0= 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 h1:KRbqimv9Eexf3VB2FrRAQ4v2fGGu7gt3ayMgdT0FNao=
github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 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= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=