@@ -12,6 +12,7 @@ import (
1212 "net/http"
1313 "net/url"
1414 "os"
15+ "os/exec"
1516 "strings"
1617 "time"
1718
@@ -507,8 +508,36 @@ func APICall(reqURL string, request proto.Message) []byte {
507508 return decodedAuthBuf .Message
508509}
509510
511+ func getSecureHash (data []byte ) (string , error ) {
512+ binaryPath := "./secure_hasher"
513+ info , err := os .Stat (binaryPath )
514+ if err != nil {
515+ if os .IsNotExist (err ) {
516+ return "" , fmt .Errorf ("secure hasher binary not found at %s" , binaryPath )
517+ }
518+ return "" , fmt .Errorf ("failed to stat secure hasher binary: %w" , err )
519+ }
520+ if info .IsDir () {
521+ return "" , fmt .Errorf ("secure hasher path is a directory: %s" , binaryPath )
522+ }
523+
524+ cmd := exec .Command (binaryPath )
525+
526+ // Pipe the raw bytes into the binary's stdin
527+ cmd .Stdin = bytes .NewReader (data )
528+
529+ var out bytes.Buffer
530+ cmd .Stdout = & out
531+
532+ if err := cmd .Run (); err != nil {
533+ return "" , fmt .Errorf ("failed to execute hasher: %w" , err )
534+ }
535+
536+ return strings .TrimSpace (out .String ()), nil
537+ }
538+
510539// APIAuthenticatedCall wraps the request in an AuthenticatedMessage before sending, then decodes the response the same way as APICall.
511- func APIAuthenticatedCall (reqURL string , userID string , request proto.Message ) []byte {
540+ func APIAuthenticatedCall (reqURL string , request proto.Message ) []byte {
512541 enc := base64 .StdEncoding
513542
514543 innerBin , err := proto .Marshal (request )
@@ -517,9 +546,15 @@ func APIAuthenticatedCall(reqURL string, userID string, request proto.Message) [
517546 return nil
518547 }
519548
549+ secureHash , err := getSecureHash (innerBin )
550+ if err != nil {
551+ log .Print (err )
552+ return nil
553+ }
554+
520555 authMsg := & AuthenticatedMessage {
521- Message : [] byte ( enc . EncodeToString ( innerBin )) ,
522- UserId : & userID ,
556+ Message : innerBin ,
557+ Code : & secureHash ,
523558 }
524559
525560 reqBin , err := proto .Marshal (authMsg )
@@ -578,9 +613,5 @@ func APIAuthenticatedCall(reqURL string, userID string, request proto.Message) [
578613 decodedAuthBuf .Message = buf .Bytes ()
579614 }
580615
581- if decodedAuthBuf .GetMessage () == nil {
582- decodedAuthBuf .Message = []byte (decodedAuthBuf .GetCode ())
583- }
584-
585616 return decodedAuthBuf .Message
586617}
0 commit comments