Put directly the pem in the json configuration

This commit is contained in:
Yaacov Akiba Slama
2023-01-09 22:23:58 +02:00
parent 001b4a5dbd
commit 1cb49f2896
2 changed files with 14 additions and 21 deletions

View File

@@ -1,7 +1,8 @@
package itest package itest
import ( import (
"encoding/base64" "encoding/hex"
"encoding/json"
"fmt" "fmt"
"log" "log"
"os" "os"
@@ -48,12 +49,11 @@ func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
} }
lightningNode := lntest.NewLndNode(h, m, name, args...) lightningNode := lntest.NewLndNode(h, m, name, args...)
lnd := fmt.Sprintf( j, _ := json.Marshal(map[string]string{
`{ "address": "%s", "cert": "%s", "macaroon": "%x" }`, "address": lightningNode.GrpcHost(),
lightningNode.GrpcHost(), "cert": lightningNode.TlsCert(),
base64.StdEncoding.EncodeToString(lightningNode.TlsCert()), "macaroon": hex.EncodeToString(lightningNode.Macaroon())})
lightningNode.Macaroon(), lnd := string(j)
)
lspBase, err := newLspd(h, name, &lnd, nil) lspBase, err := newLspd(h, name, &lnd, nil)
if err != nil { if err != nil {
h.T.Fatalf("failed to initialize lspd") h.T.Fatalf("failed to initialize lspd")
@@ -113,12 +113,11 @@ func (c *LndLspNode) Start() {
split := strings.Split(string(scriptFile), "\n") split := strings.Split(string(scriptFile), "\n")
for i, s := range split { for i, s := range split {
if strings.HasPrefix(s, "export NODES") { if strings.HasPrefix(s, "export NODES") {
ext := fmt.Sprintf( j, _ := json.Marshal(map[string]string{
`"lnd": { "address": "%s", "cert": "%s", "macaroon": "%x" }}]'`, "address": c.lightningNode.GrpcHost(),
c.lightningNode.GrpcHost(), "cert": c.lightningNode.TlsCert(),
base64.StdEncoding.EncodeToString(c.lightningNode.TlsCert()), "macaroon": hex.EncodeToString(c.lightningNode.Macaroon())})
c.lightningNode.Macaroon(), ext := fmt.Sprintf(`"lnd": %s}]`, string(j))
)
start, _, _ := strings.Cut(s, `"lnd"`) start, _, _ := strings.Cut(s, `"lnd"`)
split[i] = start + ext split[i] = start + ext

View File

@@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"crypto/x509" "crypto/x509"
"encoding/base64"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"log" "log"
@@ -26,19 +25,14 @@ type LndClient struct {
} }
func NewLndClient(conf *LndConfig) (*LndClient, error) { func NewLndClient(conf *LndConfig) (*LndClient, error) {
cert, err := base64.StdEncoding.DecodeString(conf.Cert) _, err := hex.DecodeString(conf.Macaroon)
if err != nil {
return nil, fmt.Errorf("failed to decode cert: %w", err)
}
_, err = hex.DecodeString(conf.Macaroon)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to decode macaroon: %w", err) return nil, fmt.Errorf("failed to decode macaroon: %w", err)
} }
// Creds file to connect to LND gRPC // Creds file to connect to LND gRPC
cp := x509.NewCertPool() cp := x509.NewCertPool()
if !cp.AppendCertsFromPEM(cert) { if !cp.AppendCertsFromPEM([]byte(conf.Cert)) {
return nil, fmt.Errorf("credentials: failed to append certificates") return nil, fmt.Errorf("credentials: failed to append certificates")
} }
creds := credentials.NewClientTLSFromCert(cp, "") creds := credentials.NewClientTLSFromCert(cp, "")