1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Merge pull request #27 from csaf-poc/stop-check-not-run

Do not report success on checks which were not performed.
This commit is contained in:
Fadi Abbud 2022-01-13 09:14:08 +01:00 committed by GitHub
commit c57de75dac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 11 deletions

View file

@ -107,8 +107,6 @@ func (wt whereType) String() string {
func newProcessor(opts *options) *processor { func newProcessor(opts *options) *processor {
return &processor{ return &processor{
opts: opts, opts: opts,
redirects: map[string]string{},
noneTLS: map[string]struct{}{},
alreadyChecked: map[string]whereType{}, alreadyChecked: map[string]whereType{},
builder: gval.Full(jsonpath.Language()), builder: gval.Full(jsonpath.Language()),
exprs: map[string]gval.Evaluable{}, exprs: map[string]gval.Evaluable{},
@ -116,12 +114,8 @@ func newProcessor(opts *options) *processor {
} }
func (p *processor) clean() { func (p *processor) clean() {
for k := range p.redirects { p.redirects = nil
delete(p.redirects, k) p.noneTLS = nil
}
for k := range p.noneTLS {
delete(p.noneTLS, k)
}
for k := range p.alreadyChecked { for k := range p.alreadyChecked {
delete(p.alreadyChecked, k) delete(p.alreadyChecked, k)
} }
@ -137,16 +131,14 @@ func (p *processor) clean() {
p.badIndices = nil p.badIndices = nil
p.badChanges = nil p.badChanges = nil
} }
func (p *processor) run(reporters []reporter, domains []string) (*Report, error) { func (p *processor) run(reporters []reporter, domains []string) (*Report, error) {
var report Report var report Report
domainsLoop:
for _, d := range domains { for _, d := range domains {
if err := p.checkDomain(d); err != nil { if err := p.checkDomain(d); err != nil {
if err == errContinue || err == errStop { if err == errContinue || err == errStop {
continue domainsLoop continue
} }
return nil, err return nil, err
} }
@ -198,6 +190,9 @@ func (p *processor) jsonPath(expr string, doc interface{}) (interface{}, error)
} }
func (p *processor) checkTLS(u string) { func (p *processor) checkTLS(u string) {
if p.noneTLS == nil {
p.noneTLS = map[string]struct{}{}
}
if x, err := url.Parse(u); err == nil && x.Scheme != "https" { if x, err := url.Parse(u); err == nil && x.Scheme != "https" {
p.noneTLS[u] = struct{}{} p.noneTLS[u] = struct{}{}
} }
@ -220,6 +215,9 @@ func (p *processor) checkRedirect(r *http.Request, via []*http.Request) error {
} }
url := r.URL.String() url := r.URL.String()
p.checkTLS(url) p.checkTLS(url)
if p.redirects == nil {
p.redirects = map[string]string{}
}
p.redirects[url] = path.String() p.redirects[url] = path.String()
if len(via) > 10 { if len(via) > 10 {
@ -249,6 +247,16 @@ func (p *processor) httpClient() *http.Client {
return p.client return p.client
} }
func use(s *[]string) {
if *s == nil {
*s = []string{}
}
}
func used(s []string) bool {
return s != nil
}
func (p *processor) badIntegrity(format string, args ...interface{}) { func (p *processor) badIntegrity(format string, args ...interface{}) {
p.badIntegrities = append(p.badIntegrities, fmt.Sprintf(format, args...)) p.badIntegrities = append(p.badIntegrities, fmt.Sprintf(format, args...))
} }
@ -345,6 +353,8 @@ func (p *processor) integrity(
} }
// Check if file is in the right folder. // Check if file is in the right folder.
use(&p.badFolders)
if date, err := p.jsonPath( if date, err := p.jsonPath(
`$.document.tracking.initial_release_date`, doc); err != nil { `$.document.tracking.initial_release_date`, doc); err != nil {
p.badFolder( p.badFolder(
@ -361,6 +371,8 @@ func (p *processor) integrity(
} }
// Check hashes // Check hashes
use(&p.badIntegrities)
for _, x := range []struct { for _, x := range []struct {
ext string ext string
hash []byte hash []byte
@ -401,6 +413,8 @@ func (p *processor) integrity(
sigFile := u + ".asc" sigFile := u + ".asc"
p.checkTLS(sigFile) p.checkTLS(sigFile)
use(&p.badSignatures)
if res, err = client.Get(sigFile); err != nil { if res, err = client.Get(sigFile); err != nil {
p.badSignature("Fetching %s failed: %v.", sigFile, err) p.badSignature("Fetching %s failed: %v.", sigFile, err)
continue continue
@ -498,6 +512,9 @@ func (p *processor) checkIndex(base string, mask whereType) error {
client := p.httpClient() client := p.httpClient()
index := base + "/index.txt" index := base + "/index.txt"
p.checkTLS(index) p.checkTLS(index)
use(&p.badIndices)
res, err := client.Get(index) res, err := client.Get(index)
if err != nil { if err != nil {
p.badIndex("Fetching %s failed: %v", index, err) p.badIndex("Fetching %s failed: %v", index, err)
@ -534,6 +551,9 @@ func (p *processor) checkChanges(base string, mask whereType) error {
changes := base + "/changes.csv" changes := base + "/changes.csv"
p.checkTLS(changes) p.checkTLS(changes)
res, err := client.Get(changes) res, err := client.Get(changes)
use(&p.badChanges)
if err != nil { if err != nil {
p.badChange("Fetching %s failed: %v", changes, err) p.badChange("Fetching %s failed: %v", changes, err)
return errContinue return errContinue
@ -687,6 +707,8 @@ func (p *processor) checkProviderMetadata(domain string) error {
url := "https://" + domain + "/.well-known/csaf/provider-metadata.json" url := "https://" + domain + "/.well-known/csaf/provider-metadata.json"
use(&p.badProviderMetadatas)
res, err := client.Get(url) res, err := client.Get(url)
if err != nil { if err != nil {
p.badProviderMetadata("Fetching %s: %v.", url, err) p.badProviderMetadata("Fetching %s: %v.", url, err)
@ -730,6 +752,8 @@ func (p *processor) checkSecurity(domain string) error {
client := p.httpClient() client := p.httpClient()
use(&p.badSecurities)
path := "https://" + domain + "/.well-known/security.txt" path := "https://" + domain + "/.well-known/security.txt"
res, err := client.Get(path) res, err := client.Get(path)
if err != nil { if err != nil {
@ -804,6 +828,8 @@ func (p *processor) checkSecurity(domain string) error {
func (p *processor) checkPGPKeys(domain string) error { func (p *processor) checkPGPKeys(domain string) error {
use(&p.badPGPs)
src, err := p.jsonPath("$.pgp_keys", p.pmd) src, err := p.jsonPath("$.pgp_keys", p.pmd)
if err != nil { if err != nil {
p.badPGP("No PGP keys found: %v.", err) p.badPGP("No PGP keys found: %v.", err)

View file

@ -44,6 +44,10 @@ func (bc *baseReporter) requirement(domain *Domain) *Requirement {
func (r *tlsReporter) report(p *processor, domain *Domain) { func (r *tlsReporter) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if p.noneTLS == nil {
req.message("No TLS checks performed.")
return
}
if len(p.noneTLS) == 0 { if len(p.noneTLS) == 0 {
req.message("All tested URLs were https.") req.message("All tested URLs were https.")
return return
@ -82,6 +86,10 @@ func (r *redirectsReporter) report(p *processor, domain *Domain) {
func (r *providerMetadataReport) report(p *processor, domain *Domain) { func (r *providerMetadataReport) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badProviderMetadatas) {
req.message("No provider-metadata.json checked.")
return
}
if len(p.badProviderMetadatas) == 0 { if len(p.badProviderMetadatas) == 0 {
req.message("No problems with provider metadata.") req.message("No problems with provider metadata.")
return return
@ -91,6 +99,10 @@ func (r *providerMetadataReport) report(p *processor, domain *Domain) {
func (r *securityReporter) report(p *processor, domain *Domain) { func (r *securityReporter) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badSecurities) {
req.message("No security.txt checked.")
return
}
if len(p.badSecurities) == 0 { if len(p.badSecurities) == 0 {
req.message("No problems with security.txt found.") req.message("No problems with security.txt found.")
return return
@ -112,6 +124,10 @@ func (r *dnsPathReporter) report(_ *processor, domain *Domain) {
func (r *oneFolderPerYearReport) report(p *processor, domain *Domain) { func (r *oneFolderPerYearReport) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badFolders) {
req.message("No checks if file are in right folders were performed.")
return
}
if len(p.badFolders) == 0 { if len(p.badFolders) == 0 {
req.message("All CSAF files are in the right folders.") req.message("All CSAF files are in the right folders.")
return return
@ -121,6 +137,10 @@ func (r *oneFolderPerYearReport) report(p *processor, domain *Domain) {
func (r *indexReporter) report(p *processor, domain *Domain) { func (r *indexReporter) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badIndices) {
req.message("No index.txt checked.")
return
}
if len(p.badIndices) == 0 { if len(p.badIndices) == 0 {
req.message("No problems with index.txt found.") req.message("No problems with index.txt found.")
return return
@ -130,6 +150,10 @@ func (r *indexReporter) report(p *processor, domain *Domain) {
func (r *changesReporter) report(p *processor, domain *Domain) { func (r *changesReporter) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badChanges) {
req.message("No changes.csv checked.")
return
}
if len(p.badChanges) == 0 { if len(p.badChanges) == 0 {
req.message("No problems with changes.csv found.") req.message("No problems with changes.csv found.")
return return
@ -145,6 +169,10 @@ func (r *directoryListingsReporter) report(_ *processor, domain *Domain) {
func (r *integrityReporter) report(p *processor, domain *Domain) { func (r *integrityReporter) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badIntegrities) {
req.message("No checksums checked.")
return
}
if len(p.badIntegrities) == 0 { if len(p.badIntegrities) == 0 {
req.message("All checksums match.") req.message("All checksums match.")
return return
@ -154,6 +182,10 @@ func (r *integrityReporter) report(p *processor, domain *Domain) {
func (r *signaturesReporter) report(p *processor, domain *Domain) { func (r *signaturesReporter) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badSignatures) {
req.message("No signatures checked.")
return
}
req.Messages = p.badSignatures req.Messages = p.badSignatures
if len(p.badSignatures) == 0 { if len(p.badSignatures) == 0 {
req.message("All signatures verified.") req.message("All signatures verified.")
@ -162,6 +194,10 @@ func (r *signaturesReporter) report(p *processor, domain *Domain) {
func (r *publicPGPKeyReporter) report(p *processor, domain *Domain) { func (r *publicPGPKeyReporter) report(p *processor, domain *Domain) {
req := r.requirement(domain) req := r.requirement(domain)
if !used(p.badPGPs) {
req.message("No PGP keys loaded.")
return
}
req.Messages = p.badPGPs req.Messages = p.badPGPs
if len(p.keys) > 0 { if len(p.keys) > 0 {
req.message(fmt.Sprintf("%d PGP key(s) loaded successfully.", len(p.keys))) req.message(fmt.Sprintf("%d PGP key(s) loaded successfully.", len(p.keys)))