mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
add config flag to use enumerate-only
This commit is contained in:
parent
457d519990
commit
005e661479
4 changed files with 21 additions and 23 deletions
|
|
@ -58,6 +58,8 @@ type config struct {
|
||||||
IgnorePattern []string `long:"ignore_pattern" short:"i" description:"Do not download files if their URLs match any of the given PATTERNs" value-name:"PATTERN" toml:"ignore_pattern"`
|
IgnorePattern []string `long:"ignore_pattern" short:"i" description:"Do not download files if their URLs match any of the given PATTERNs" value-name:"PATTERN" toml:"ignore_pattern"`
|
||||||
ExtraHeader http.Header `long:"header" short:"H" description:"One or more extra HTTP header fields" toml:"header"`
|
ExtraHeader http.Header `long:"header" short:"H" description:"One or more extra HTTP header fields" toml:"header"`
|
||||||
|
|
||||||
|
EnumeratePMDOnly bool `long:"enumerate_pmd_only" description:"If this flag is set to true, the donwloader will only enumerate valid provider metadata files, but not download documents" toml:"enumerate_pmd_only"`
|
||||||
|
|
||||||
RemoteValidator string `long:"validator" description:"URL to validate documents remotely" value-name:"URL" toml:"validator"`
|
RemoteValidator string `long:"validator" description:"URL to validate documents remotely" value-name:"URL" toml:"validator"`
|
||||||
RemoteValidatorCache string `long:"validator_cache" description:"FILE to cache remote validations" value-name:"FILE" toml:"validator_cache"`
|
RemoteValidatorCache string `long:"validator_cache" description:"FILE to cache remote validations" value-name:"FILE" toml:"validator_cache"`
|
||||||
RemoteValidatorPresets []string `long:"validator_preset" description:"One or more PRESETS to validate remotely" value-name:"PRESETS" toml:"validator_preset"`
|
RemoteValidatorPresets []string `long:"validator_preset" description:"One or more PRESETS to validate remotely" value-name:"PRESETS" toml:"validator_preset"`
|
||||||
|
|
|
||||||
|
|
@ -169,9 +169,10 @@ func (d *downloader) enumerate(domain string) error {
|
||||||
client := d.httpClient()
|
client := d.httpClient()
|
||||||
|
|
||||||
loader := csaf.NewProviderMetadataLoader(client)
|
loader := csaf.NewProviderMetadataLoader(client)
|
||||||
|
|
||||||
lpmd := loader.Enumerate(domain)
|
lpmd := loader.Enumerate(domain)
|
||||||
|
|
||||||
|
docs := []any{}
|
||||||
|
|
||||||
for _, pmd := range lpmd {
|
for _, pmd := range lpmd {
|
||||||
if d.cfg.verbose() {
|
if d.cfg.verbose() {
|
||||||
for i := range pmd.Messages {
|
for i := range pmd.Messages {
|
||||||
|
|
@ -181,22 +182,16 @@ func (d *downloader) enumerate(domain string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !pmd.Valid() {
|
docs = append(docs, pmd.Document)
|
||||||
return fmt.Errorf("invalid provider-metadata.json found for '%s'", domain)
|
|
||||||
}
|
|
||||||
_, err := url.Parse(pmd.URL)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid URL found '%s': %v", pmd.URL, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print the results
|
// print the results
|
||||||
fmt.Println("Found provider-metadata file under URL", pmd.URL)
|
doc, err := json.MarshalIndent(docs, "", " ")
|
||||||
doc, err := json.MarshalIndent(pmd.Document, "", " ")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Couldn't marshal PMD document json")
|
slog.Error("Couldn't marshal PMD document json")
|
||||||
}
|
}
|
||||||
fmt.Println(string(doc))
|
fmt.Println(string(doc))
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,12 @@ func run(cfg *config, domains []string) error {
|
||||||
d.forwarder = f
|
d.forwarder = f
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, enumerate existing PMDs, then load
|
if cfg.EnumeratePMDOnly {
|
||||||
err = d.runEnumerate(domains)
|
// Enumerate only
|
||||||
if err != nil {
|
return d.runEnumerate(domains)
|
||||||
return err
|
} else {
|
||||||
}
|
|
||||||
return d.run(ctx, domains)
|
return d.run(ctx, domains)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -125,13 +126,13 @@ func (pmdl *ProviderMetadataLoader) Enumerate(domain string) []*LoadedProviderMe
|
||||||
|
|
||||||
// Validate the candidate and add to the result array
|
// Validate the candidate and add to the result array
|
||||||
if wellknownResult.Valid() {
|
if wellknownResult.Valid() {
|
||||||
fmt.Println("Found well known result")
|
slog.Debug("Found well known provider-metadata.json")
|
||||||
resPMDs = append(resPMDs, wellknownResult)
|
resPMDs = append(resPMDs, wellknownResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next load the PMDs from security.txt
|
// Next load the PMDs from security.txt
|
||||||
secResults := pmdl.loadFromSecurity(domain)
|
secResults := pmdl.loadFromSecurity(domain)
|
||||||
fmt.Println("Found security.txt results", len(secResults))
|
slog.Info("Found provider metadata results in security.txt", "num", len(secResults))
|
||||||
|
|
||||||
for _, result := range secResults {
|
for _, result := range secResults {
|
||||||
if result.Valid() {
|
if result.Valid() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue