Skip to content

Commit

Permalink
added enhanced logging
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRoettges committed Dec 1, 2023
1 parent 46d2c88 commit 1a5989c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions configparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/pem"
"fmt"
"github.com/gr33nbl00d/caddy-revocation-validator/config"
"io/ioutil"
"os"
"time"
)

Expand Down Expand Up @@ -164,7 +164,7 @@ func parseTrustedCrlSignerCerts(crlConfig *config.CRLConfig) error {
}

func parseCertFromFile(certFile string) (*x509.Certificate, error) {
certBytes, err := ioutil.ReadFile(certFile)
certBytes, err := os.ReadFile(certFile)
if err != nil {
return nil, err
}
Expand All @@ -174,7 +174,7 @@ func parseCertFromFile(certFile string) (*x509.Certificate, error) {
}
certificate, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not parse certificate from file #{certFile}", err)

Check failure on line 177 in configparser.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.19)

fmt.Errorf call has arguments but no formatting directives

Check failure on line 177 in configparser.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.20)

fmt.Errorf call has arguments but no formatting directives

Check failure on line 177 in configparser.go

View workflow job for this annotation

GitHub Actions / build (macos-latest, 1.19)

fmt.Errorf call has arguments but no formatting directives

Check failure on line 177 in configparser.go

View workflow job for this annotation

GitHub Actions / build (macos-latest, 1.20)

fmt.Errorf call has arguments but no formatting directives

Check failure on line 177 in configparser.go

View workflow job for this annotation

GitHub Actions / build (windows-latest, 1.19)

fmt.Errorf call has arguments but no formatting directives

Check failure on line 177 in configparser.go

View workflow job for this annotation

GitHub Actions / build (windows-latest, 1.20)

fmt.Errorf call has arguments but no formatting directives
}
return certificate, nil
}
Expand Down
7 changes: 6 additions & 1 deletion crl/crlrepository/crlrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func (R *Repository) updateCRL(identifier string) error {
}

func (R *Repository) updateCrlEntry(entry *Entry, newChains *core.CertificateChains) (err error) {
R.logger.Info("updating crl " + entry.CRLLoader.GetDescription())
var store crlstore.CRLStore
tempFileName, err := R.createTempFile()
if err != nil {
Expand All @@ -291,6 +292,7 @@ func (R *Repository) updateCrlEntry(entry *Entry, newChains *core.CertificateCha
defer os.Remove(tempFileName)

var chains = newChains

points, storedChains, err := R.getCrlUpdateInformation(entry, err)
if err != nil {
return err
Expand All @@ -302,6 +304,7 @@ func (R *Repository) updateCrlEntry(entry *Entry, newChains *core.CertificateCha
if err != nil {
return err
}
R.logger.Info("loading crl " + entry.CRLLoader.GetDescription())
err = loader.LoadCRL(tempFileName)
if err != nil {
return err
Expand All @@ -316,7 +319,7 @@ func (R *Repository) updateCrlEntry(entry *Entry, newChains *core.CertificateCha
}

var processor = crlstore.CRLPersisterProcessor{CRLStore: store}

R.logger.Info("parsing crl loaded from " + entry.CRLLoader.GetDescription())
err = processor.UpdateCRLLocations(points)
if err != nil {
return err
Expand All @@ -326,6 +329,7 @@ func (R *Repository) updateCrlEntry(entry *Entry, newChains *core.CertificateCha
if err != nil {
return err
}
R.logger.Info("verify crl signature of crl " + entry.CRLLoader.GetDescription())
signatureCert, err := verifyCRLSignature(result, chains)
if err != nil {
R.setLastSignatureVerifyFailed(entry, result)
Expand All @@ -344,6 +348,7 @@ func (R *Repository) updateCrlEntry(entry *Entry, newChains *core.CertificateCha
R.deleteEntrySync(identifier)
return err
}
R.logger.Info("finished updating crl " + entry.CRLLoader.GetDescription())
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions crl/crlrevocationchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ func (c *CRLRevocationChecker) Provision(crlConfig *config.CRLConfig, logger *za

logger.Info("creating crl certificate chains")
chains := core.NewCertificateChains(nil, crlConfig.TrustedSignatureCerts)
logger.Info("adding crl entries from crl_urls config")
err = c.addCrlUrlsFromConfig(chains)
if err != nil {
return err
}
logger.Info("adding crl entries from crl_files config")
err = c.addCrlFilesFromConfig(chains)
if err != nil {
return err
Expand Down Expand Up @@ -101,6 +103,7 @@ func (c *CRLRevocationChecker) addCrlUrlsFromConfig(chains *core.CertificateChai
return err
}
//update in case chains have changed
c.logger.Info("Updating crl from location " + crlUrl)
err = c.crlRepository.UpdateCRL(&crlLocations, chains)
if err != nil {
return err
Expand All @@ -119,6 +122,7 @@ func (c *CRLRevocationChecker) addCrlFilesFromConfig(chains *core.CertificateCha
return err
}
//update in case chains have changed
c.logger.Info("Updating crl from location " + crlFile)
err = c.crlRepository.UpdateCRL(&crlLocations, chains)
if err != nil {
return err
Expand Down

0 comments on commit 1a5989c

Please sign in to comment.