Make daemon return decrypted data, not passphrase

This commit is contained in:
2025-05-08 18:47:35 +00:00
parent 949ef622c7
commit e7f041bb0a
9 changed files with 73 additions and 47 deletions
+11 -5
View File
@@ -4,18 +4,24 @@ import (
"crypto/sha256"
"io"
"os"
"github.com/rwinkhart/rcw/wrappers"
)
var daemonHash []byte
var globalPassphrase string
var globalPassphrase []byte
// RCWService provides an RPC method.
type RCWService struct{}
// GetPass is the RPC method.
// For now (as a test/example), it returns "hello" if the input is "hi".
func (h *RCWService) GetPass(request string, reply *string) error {
*reply = globalPassphrase
// DecryptRequest is the RPC method that decrypts the incoming data using
// the global passphrase and returns the decrypted data
func (h *RCWService) DecryptRequest(request []byte, reply *[]byte) error {
var err error
*reply, err = wrappers.Decrypt(request, globalPassphrase)
if err != nil {
return err
}
return nil
}
+4 -3
View File
@@ -16,9 +16,10 @@ import (
peercred "github.com/rwinkhart/peercred-mini"
)
// Start should be called to serve the given passphrase through an RPC daemon.
func Start(passphrase string) {
// store passphrase to be referenced by GetPass method
// Start is the entry point for the RPC server responsible for
// returning decrypted data to authenticated clients.
func Start(passphrase []byte) {
// store passphrase to be referenced by DecryptRequest method
globalPassphrase = passphrase
// register RCWService with the RPC package
+5 -4
View File
@@ -12,7 +12,7 @@ import (
"syscall"
"time"
"github.com/Microsoft/go-winio" // For Windows named pipes
"github.com/Microsoft/go-winio"
"github.com/rwinkhart/peercred-mini"
"golang.org/x/sys/windows"
)
@@ -21,9 +21,10 @@ const (
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
)
// Start should be called to serve the given passphrase through an RPC daemon.
func Start(passphrase string) {
// store passphrase to be referenced by GetPass method
// Start is the entry point for the RPC server responsible for
// returning decrypted data to authenticated clients.
func Start(passphrase []byte) {
// store passphrase to be referenced by DecryptRequest method
globalPassphrase = passphrase
// register RCWService with the RPC package
+8 -9
View File
@@ -5,18 +5,17 @@ import (
"net/rpc"
)
// CallDaemonIfOpen returns the passphrase served by the RCW daemon
// (if one is available). If no RCW daemon is accessible, nil is returned.
func CallDaemonIfOpen() []byte {
// CallDaemonIfOpen uses the RCW daemon (if one is available) to
// decrypt and return data. If no RCW daemon is accessible, nil is returned.
func CallDaemonIfOpen(encBytes []byte) []byte {
if daemonIsOpen() {
call()
return call()
return call(encBytes)
}
return nil
}
// call connects to the RPC server and requests the passphrase.
func call() []byte {
func call(encBytes []byte) []byte {
// connect to the UNIX domain socket/Windows named pipe
conn := getConn()
defer conn.Close()
@@ -26,9 +25,9 @@ func call() []byte {
defer client.Close()
// request the passphrase from the RPC server
var reply string
if err := client.Call("RCWService.GetPass", "hi", &reply); err != nil {
log.Fatalf("Error calling RCWService.GetPass: %v", err)
var reply []byte
if err := client.Call("RCWService.DecryptRequest", encBytes, &reply); err != nil {
log.Fatalf("Error calling RCWService.DecryptRequest: %v", err)
}
// return the passphrase