Skip to content

Commit

Permalink
Merge pull request #12 from Chia-Network/better-cert-errors
Browse files Browse the repository at this point in the history
Add better errors when missing a cert in config
  • Loading branch information
cmmarslender authored Apr 19, 2022
2 parents 57bff53 + 474b9d9 commit 563b6a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions pkg/config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"crypto/tls"
"errors"
"path/filepath"
)

Expand All @@ -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
}
Expand All @@ -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
}
10 changes: 5 additions & 5 deletions pkg/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 563b6a3

Please sign in to comment.