From 770abf589c4598d035501e66bb8e4064ff2db7d5 Mon Sep 17 00:00:00 2001 From: TVHeroes Date: Sun, 9 Aug 2026 14:45:43 +0100 Subject: [PATCH] client/rpcserver: fix cert handling in handlePostBond form.Cert arrives from bwctl as a JSON string when a cert filepath is given on the command line - optionalTextFiles pre-reads the file into its raw content before sending, same as handleGetDEXConfig receives. handleGetDEXConfig explicitly converts that string to []byte before passing it to core, so parseCert takes its []byte branch and uses the content directly. handlePostBond does not do this conversion, so form.Cert (typed any) unmarshals as a plain Go string, and core.parseCert treats that string as a filepath and tries to re-read the PEM content as if it were a filename - always fails with a misleading "failed to read certificate file from -----BEGIN CERTIFICATE-----..." error. Adds the same string-to-[]byte conversion handleGetDEXConfig already does, so postbond with a cert filepath argument actually works. --- client/rpcserver/handlers.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/rpcserver/handlers.go b/client/rpcserver/handlers.go index 25392338f8..388f86aac6 100644 --- a/client/rpcserver/handlers.go +++ b/client/rpcserver/handlers.go @@ -1115,6 +1115,20 @@ func handlePostBond(s *RPCServer, msg *msgjson.Message) *msgjson.ResponsePayload exchCfg := exchInf[form.Addr] if exchCfg == nil { // Not already registered. + // + // form.Cert arrives as a JSON string - bwctl's optionalTextFiles + // pre-reads a cert filepath argument into the certificate's raw + // content before sending it, same as handleGetDEXConfig does + // above (which explicitly converts to []byte for this reason). + // core.PostBondForm.Cert is typed any, so it unmarshals as a Go + // string rather than []byte here, and core.parseCert then + // treats that string as a filepath and tries to re-read the PEM + // content as if it were a filename, which always fails. Convert + // to []byte here, matching handleGetDEXConfig, so parseCert + // takes its []byte branch instead. + if certStr, ok := form.Cert.(string); ok && certStr != "" { + form.Cert = []byte(certStr) + } var err error exchCfg, err = s.core.GetDEXConfig(form.Addr, form.Cert) if err != nil {