Attempt to fix unexpected EOF on Solaris

This commit is contained in:
2026-05-29 19:04:38 -04:00
parent ba4a2c8396
commit 8318b2e325
5 changed files with 39 additions and 11 deletions
+7 -3
View File
@@ -2,6 +2,7 @@ package daemon
import ( import (
"crypto/sha256" "crypto/sha256"
"errors"
"io" "io"
"os" "os"
@@ -35,10 +36,13 @@ func (h *RCWService) EncryptRequest(decBytes []byte, reply *[]byte) error {
} }
// getFileHash returns the SHA256 hash of the file at the given path. // getFileHash returns the SHA256 hash of the file at the given path.
func getFileHash(path string) []byte { func getFileHash(path string) ([]byte, error) {
file, _ := os.Open(path) file, err := os.Open(path)
if err != nil {
return nil, errors.New("unable to read path (" + path + ") for hashing: " + err.Error())
}
defer file.Close() defer file.Close()
hash := sha256.New() hash := sha256.New()
io.Copy(hash, file) io.Copy(hash, file)
return hash.Sum(nil) return hash.Sum(nil), nil
} }
+1 -1
View File
@@ -2,4 +2,4 @@
package daemon package daemon
const pidPathFile = "execname" const pidPathFile = "path/a.out"
+15 -3
View File
@@ -24,12 +24,16 @@ func Start(password []byte) {
globalPassword = password globalPassword = password
// register RCWService with the RPC package // register RCWService with the RPC package
if err := rpc.Register(&RCWService{}); err != nil { err := rpc.Register(&RCWService{})
if err != nil {
log.Fatalf("Error registering RPC service: %v", err) log.Fatalf("Error registering RPC service: %v", err)
} }
// store the hash of the daemon binary // store the hash of the daemon binary
daemonHash = getFileHash(binPath) daemonHash, err = getFileHash(binPath)
if err != nil {
log.Fatalf("Error hashing daemon binary: %v", err)
}
// listen on the Unix domain socket // listen on the Unix domain socket
listener, err := net.Listen("unix", socketPath) listener, err := net.Listen("unix", socketPath)
@@ -80,7 +84,15 @@ func handleConn(conn net.Conn, sigChan chan os.Signal) {
// check if the RPC call is coming from an identical binary and from the same user // check if the RPC call is coming from an identical binary and from the same user
callingBinPath := pidToPath(ucred.PID) callingBinPath := pidToPath(ucred.PID)
if ucred.UID == strconv.Itoa(os.Getuid()) && bytes.Equal(getFileHash(callingBinPath), daemonHash) { callingBinHash, err := getFileHash(callingBinPath)
if err != nil {
// calling binary hash failure
conn.Close()
log.Printf("Failed to hash calling binary: PID(%d), UID(%s), Path(%s) - %v", ucred.PID, ucred.UID, callingBinPath, err)
sigChan <- syscall.SIGTERM // this zeroizes globalPassword and triggers os.Exit(0)
return // explicitly return to avoid race
}
if ucred.UID == strconv.Itoa(os.Getuid()) && bytes.Equal(callingBinHash, daemonHash) {
// valid client; hand off the connection to the RPC server // valid client; hand off the connection to the RPC server
rpc.ServeConn(conn) rpc.ServeConn(conn)
} else { } else {
+15 -3
View File
@@ -29,12 +29,16 @@ func Start(password []byte) {
globalPassword = password globalPassword = password
// register RCWService with the RPC package // register RCWService with the RPC package
if err := rpc.Register(&RCWService{}); err != nil { err := rpc.Register(&RCWService{})
if err != nil {
log.Fatalf("Error registering RPC service: %v", err) log.Fatalf("Error registering RPC service: %v", err)
} }
// store the hash of the daemon binary // store the hash of the daemon binary
daemonHash = getFileHash(binPath) daemonHash, err = getFileHash(binPath)
if err != nil {
log.Fatalf("Error hashing daemon binary: %v", err)
}
// configure the named pipe // configure the named pipe
pipeConfig := &winio.PipeConfig{ pipeConfig := &winio.PipeConfig{
@@ -104,7 +108,15 @@ func handleConn(conn net.Conn, sigChan chan os.Signal) {
// check if the RPC call is coming from an identical binary and from the same user // check if the RPC call is coming from an identical binary and from the same user
callingBinPath := pidToPath(uint32(ucred.PID)) callingBinPath := pidToPath(uint32(ucred.PID))
if ucred.UID == user.User.Sid.String() && bytes.Equal(getFileHash(callingBinPath), daemonHash) { callingBinHash, err := getFileHash(callingBinPath)
if err != nil {
// calling binary hash failure
conn.Close()
log.Printf("Failed to hash calling binary: PID(%d), UID(%s), Path(%s) - %v", ucred.PID, ucred.UID, callingBinPath, err)
sigChan <- os.Interrupt // this zeroizes globalPassword and triggers os.Exit(0)
return // explicitly return to avoid race
}
if ucred.UID == user.User.Sid.String() && bytes.Equal(callingBinHash, daemonHash) {
rpc.ServeConn(conn) rpc.ServeConn(conn)
} else { } else {
// invalid client; close the connection w/o a response, // invalid client; close the connection w/o a response,
+1 -1
View File
@@ -20,7 +20,7 @@ func GenSanityCheck(path string, password []byte, zeroizePassword bool) error {
func RunSanityCheck(path string, password []byte) error { func RunSanityCheck(path string, password []byte) error {
encBytes, err := os.ReadFile(path) encBytes, err := os.ReadFile(path)
if err != nil { if err != nil {
return errors.New("Failed to read sanity check file (" + path + ")") return errors.New("unable to read sanity check file (" + path + "): " + err.Error())
} }
decBytes, err := Decrypt(encBytes, password, false) decBytes, err := Decrypt(encBytes, password, false)
if err == nil { if err == nil {