diff --git a/pkg/config/tls.go b/pkg/config/tls.go index 4dd7dd6..58440d7 100644 --- a/pkg/config/tls.go +++ b/pkg/config/tls.go @@ -2,6 +2,7 @@ package config import ( "crypto/tls" + "errors" "path/filepath" ) @@ -12,6 +13,10 @@ func (s *SSLConfig) LoadPrivateKeyPair() (*tls.Certificate, error) { return nil, err } + if s.PrivateCRT == "" || s.PrivateKey == "" { + return nil, errors.New("missing private key or cert. Ensure config.yaml is up to date with the latest changes") + } + pair, err := tls.LoadX509KeyPair(filepath.Join(rootPath, s.PrivateCRT), filepath.Join(rootPath, s.PrivateKey)) return &pair, err } @@ -23,6 +28,10 @@ func (s *SSLConfig) LoadPublicKeyPair() (*tls.Certificate, error) { return nil, err } + if s.PublicCRT == "" || s.PublicKey == "" { + return nil, errors.New("missing public key or cert. Ensure config.yaml is up to date with the latest changes") + } + pair, err := tls.LoadX509KeyPair(filepath.Join(rootPath, s.PublicCRT), filepath.Join(rootPath, s.PublicKey)) return &pair, err } diff --git a/pkg/httpclient/httpclient.go b/pkg/httpclient/httpclient.go index cb86806..d21b708 100644 --- a/pkg/httpclient/httpclient.go +++ b/pkg/httpclient/httpclient.go @@ -186,27 +186,27 @@ func (c *HTTPClient) initialKeyPairs() error { c.nodeKeyPair, err = c.config.FullNode.SSL.LoadPrivateKeyPair() if err != nil { - return err + return fmt.Errorf("error loading full node config: %w", err) } c.farmerKeyPair, err = c.config.Farmer.SSL.LoadPrivateKeyPair() if err != nil { - return err + return fmt.Errorf("error loading farmer config: %w", err) } c.harvesterKeyPair, err = c.config.Harvester.SSL.LoadPrivateKeyPair() if err != nil { - return err + return fmt.Errorf("error loading harvester config: %w", err) } c.walletKeyPair, err = c.config.Wallet.SSL.LoadPrivateKeyPair() if err != nil { - return err + return fmt.Errorf("error loading wallet config: %w", err) } c.crawlerKeyPair, err = c.config.Seeder.CrawlerConfig.SSL.LoadPrivateKeyPair() if err != nil { - return err + return fmt.Errorf("error loading crawler config: %w", err) } return nil