Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upstream changes #33

Closed
wants to merge 10 commits into from
11 changes: 11 additions & 0 deletions LICENSES/BSD-3-Clause.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) <year> <owner>.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 changes: 9 additions & 5 deletions cmd/csaf_aggregator/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,21 @@ func (w *worker) locateProviderMetadata(domain string) error {

lpmd := loader.Load(domain)

if w.processor.cfg.Verbose {
if !lpmd.Valid() {
for i := range lpmd.Messages {
w.log.Info(
w.log.Error(
"Loading provider-metadata.json",
"domain", domain,
"message", lpmd.Messages[i].Message)
}
}

if !lpmd.Valid() {
return fmt.Errorf("no valid provider-metadata.json found for '%s'", domain)
} else if w.processor.cfg.Verbose {
for i := range lpmd.Messages {
w.log.Debug(
"Loading provider-metadata.json",
"domain", domain,
"message", lpmd.Messages[i].Message)
}
}

w.metadataProvider = lpmd.Document
Expand Down
28 changes: 17 additions & 11 deletions cmd/csaf_downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
type Downloader struct {
cfg *Config
keys *crypto.KeyRing
eval *util.PathEval
validator csaf.RemoteValidator
Forwarder *Forwarder
mkdirMu sync.Mutex
Expand Down Expand Up @@ -75,7 +74,6 @@ func NewDownloader(cfg *Config) (*Downloader, error) {

return &Downloader{
cfg: cfg,
eval: util.NewPathEval(),
validator: validator,
Csafs: make(chan []byte),
}, nil
Expand Down Expand Up @@ -205,34 +203,40 @@ func (d *Downloader) download(ctx context.Context, domain string) error {

lpmd := loader.Load(domain)

if d.cfg.verbose() {
if !lpmd.Valid() {
for i := range lpmd.Messages {
slog.Debug("Loading provider-metadata.json",
slog.Error("Loading provider-metadata.json",
"domain", domain,
"message", lpmd.Messages[i].Message)
}
}

if !lpmd.Valid() {
return errs.ErrCsafProviderIssue{Message: fmt.Sprintf("no valid provider-metadata.json found for '%s'", domain)}
} else if d.cfg.verbose() {
for i := range lpmd.Messages {
slog.Debug("Loading provider-metadata.json",
"domain", domain,
"message", lpmd.Messages[i].Message)
}
}

base, err := url.Parse(lpmd.URL)
if err != nil {
return errs.ErrCsafProviderIssue{Message: fmt.Sprintf("invalid URL '%s': %v", lpmd.URL, err)}
}

expr := util.NewPathEval()

if err := d.loadOpenPGPKeys(
client,
lpmd.Document,
base,
expr,
); err != nil {
return errs.ErrCsafProviderIssue{Message: err.Error()}
}

afp := csaf.NewAdvisoryFileProcessor(
client,
d.eval,
expr,
lpmd.Document,
base)

Expand Down Expand Up @@ -304,9 +308,10 @@ func (d *Downloader) loadOpenPGPKeys(
client util.Client,
doc any,
base *url.URL,
expr *util.PathEval,
) error {

src, err := d.eval.Eval("$.public_openpgp_keys", doc)
src, err := expr.Eval("$.public_openpgp_keys", doc)
if err != nil {
// no keys.
return nil
Expand Down Expand Up @@ -428,6 +433,7 @@ func (d *Downloader) downloadWorker(
dateExtract = util.TimeMatcher(&initialReleaseDate, time.RFC3339)
lower = strings.ToLower(string(label))
stats = stats{}
expr = util.NewPathEval()
)

// Add collected stats back to total.
Expand Down Expand Up @@ -616,7 +622,7 @@ nextAdvisory:

// Validate if filename is conforming.
filenameCheck := func() error {
if err := util.IDMatchesFilename(d.eval, doc, filename); err != nil {
if err := util.IDMatchesFilename(expr, doc, filename); err != nil {
stats.filenameFailed++
errorCh <- csafErrs.ErrInvalidCsaf{Message: fmt.Sprintf("invalid CSAF document %s at URL %s: %v", filename, file.URL(), err)}
return fmt.Errorf("filename not conforming %s: %s", file.URL(), err)
Expand Down Expand Up @@ -685,7 +691,7 @@ nextAdvisory:
continue
}

if err := d.eval.Extract(
if err := expr.Extract(
`$.document.tracking.initial_release_date`, dateExtract, false, doc,
); err != nil {
slog.Warn("Cannot extract initial_release_date from advisory",
Expand Down
9 changes: 2 additions & 7 deletions csaf/cvss20enums.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// This file is Free Software under the Apache-2.0 License
// without warranty, see README.md and LICENSES/Apache-2.0.txt for details.
//
// SPDX-License-Identifier: Apache-2.0
//
// SPDX-FileCopyrightText: 2023 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2023 Intevation GmbH <https://intevation.de>
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2017 FIRST.ORG, INC.
//
// THIS FILE IS MACHINE GENERATED. EDIT WITH CARE!

Expand Down
9 changes: 2 additions & 7 deletions csaf/cvss3enums.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// This file is Free Software under the Apache-2.0 License
// without warranty, see README.md and LICENSES/Apache-2.0.txt for details.
//
// SPDX-License-Identifier: Apache-2.0
//
// SPDX-FileCopyrightText: 2023 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2023 Intevation GmbH <https://intevation.de>
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2017 FIRST.ORG, INC.
//
// THIS FILE IS MACHINE GENERATED. EDIT WITH CARE!

Expand Down
28 changes: 21 additions & 7 deletions csaf/generate_cvss_enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ import (
"bytes"
"encoding/json"
"flag"
"fmt"
"go/format"
"log"
"os"
"regexp"
"sort"
"strings"
"text/template"
)

const tmplText = `// This file is Free Software under the MIT License
// without warranty, see README.md and LICENSES/MIT.txt for details.
//
// SPDX-License-Identifier: MIT
//
// SPDX-FileCopyrightText: 2023 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2023 Intevation GmbH <https://intevation.de>
// We from Intevation consider the source code parts in the following
// template file as too insignificant to be a piece of work that gains
// "copyrights" protection in the European Union. So the license(s)
// of the output files are fully determined by the input file.
const tmplText = `// {{ $.License }}
//
// THIS FILE IS MACHINE GENERATED. EDIT WITH CARE!

Expand Down Expand Up @@ -69,6 +69,7 @@ type definition struct {
}

type schema struct {
License []string `json:"license"`
Definitions map[string]*definition `json:"definitions"`
}

Expand Down Expand Up @@ -137,9 +138,22 @@ func main() {
}
sort.Strings(defs)

license := "determine license(s) from input file and replace this line"

pattern := regexp.MustCompile(`Copyright \(c\) (\d+), FIRST.ORG, INC.`)
for _, line := range s.License {
if m := pattern.FindStringSubmatch(line); m != nil {
license = fmt.Sprintf(
"SPDX-License-Identifier: BSD-3-Clause\n"+
"// SPDX-FileCopyrightText: %s FIRST.ORG, INC.", m[1])
break
}
}

var source bytes.Buffer

check(tmpl.Execute(&source, map[string]any{
"License": license,
"Prefix": *prefix,
"Definitions": s.Definitions,
"Keys": defs,
Expand Down
2 changes: 2 additions & 0 deletions csaf/schema/cvss-v2.0.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-License-Identifier: BSD-3-Clause
SPDX-FileCopyrightText: 2017 FIRST.ORG, INC.
2 changes: 2 additions & 0 deletions csaf/schema/cvss-v3.0.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-License-Identifier: BSD-3-Clause
SPDX-FileCopyrightText: 2017 FIRST.ORG, INC.
2 changes: 2 additions & 0 deletions csaf/schema/cvss-v3.1.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-License-Identifier: BSD-3-Clause
SPDX-FileCopyrightText: 2021 FIRST.ORG, INC.
2 changes: 1 addition & 1 deletion docs/examples/aggregator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ insecure = true
# rate = 1.8
# insecure = true
write_indices = true
# If aggregator.category == "aggreator", set for an entry that should
# If aggregator.category == "aggregator", set for an entry that should
# be listed in addition:
category = "lister"
# ignore_pattern = [".*white.*", ".*red.*"]
38 changes: 38 additions & 0 deletions util/csv_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file is Free Software under the Apache-2.0 License
// without warranty, see README.md and LICENSES/Apache-2.0.txt for details.
//
// SPDX-License-Identifier: Apache-2.0
//
// SPDX-FileCopyrightText: 2022 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2022 Intevation GmbH <https://intevation.de>

package util

import (
"bytes"
"testing"
)

func TestCSV(t *testing.T) {
buf := new(bytes.Buffer)
csvWriter := NewFullyQuotedCSWWriter(buf)
for _, x := range [][]string{{"a", "b", "c"}, {"d", "e", "f"}} {
if err := csvWriter.Write(x); err != nil {
t.Error(err)
}
}

csvWriter.Flush()
if err := csvWriter.Error(); err != nil {
t.Error(err)
}
for _, want := range []string{`"a","b","c"`, `"d","e","f"`} {
got, err := buf.ReadString('\n')
if err != nil {
t.Error(err)
}
if got[:len(got)-1] != want {
t.Errorf("FullyQuotedCSWWriter: Expected %q but got %q.", want, got)
}
}
}
Loading
Loading