Skip to content

client/rpcserver: fix cert handling in handlePostBond - #3624

Open
Share-coin wants to merge 1 commit into
decred:masterfrom
Share-coin:fix-postbond-cert-handling
Open

client/rpcserver: fix cert handling in handlePostBond#3624
Share-coin wants to merge 1 commit into
decred:masterfrom
Share-coin:fix-postbond-cert-handling

Conversation

@Share-coin

Copy link
Copy Markdown

Summary

handlePostBond doesn't convert form.Cert from a JSON string to []byte before use, unlike handleGetDEXConfig two functions above it (which does exactly this conversion, for exactly this reason).

bwctl's optionalTextFiles pre-reads a cert filepath argument into the certificate's raw content before sending it over RPC. handleGetDEXConfig's params struct types Cert as string and explicitly converts it to []byte before passing to core, so parseCert takes its []byte branch and uses the content directly.

core.PostBondForm.Cert is typed any, so it unmarshals as a plain Go string instead, and core.parseCert's string branch tries to re-read that 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 bwctl postbond <host> <bond> ... <certpath> actually works for registering a new DEX.

Test plan

  • go build ./client/rpcserver/... clean
  • gofmt -l clean
  • Reproduced the original bug and confirmed the fix live: bwctl postbond with a cert filepath failed with the misleading file-read error before this change, succeeded (real bond posted, confirmed on-chain) after

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant