Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ stale. `make test` and `make web-test` run the Go and web suites. See the design
[`docs/architecture/touchstone.md`](docs/architecture/touchstone.md) and
the PRD at [`docs/product/touchstone.md`](docs/product/touchstone.md).

### Discovery and a supplied SBOM/VEX

Every scan checks `/.well-known/security.txt` (then `/security.txt`),
`/.well-known/csaf/provider-metadata.json` and `/.well-known/tea` on the
target's origin. It follows each `CSAF:` field and the provider metadata's
public ROLIE feeds to the five newest CSAF documents, and reads the products
of those that are CSAF VEX as High-confidence components. `/.well-known/tea`
is recorded in `checked` but not queried. Every request is in the report's
`checked` list.

If you already have the vendor's SBOM or VEX (CycloneDX, SPDX 2.3, OpenVEX
or CSAF, as JSON), pass it in. Its components are High confidence with
`SBOM_SUPPLIED` evidence:

```sh
touchstone scan --sbom vendor-sbom.json https://vendor.example
touchstone scan --sbom-url https://vendor.example/sbom.json https://vendor.example
```

The web page has the same two inputs: an upload field and a URL field.

### Web page: `touchstone serve`

`touchstone serve` runs the web page and `POST /v1/scans` on one port.
Expand Down
18 changes: 14 additions & 4 deletions cmd/touchstone/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Command touchstone scans a vendor URL and prints an evidence-graded
// ScanReport as protojson (--format json, the default) or as Markdown
// (--format md), or serves the web page and POST /v1/scans (serve, slice
// S9). The scan fetches the page and its scripts passively, looks
// components up in OSV and NVD, and ranks them with KEV and EPSS.
// S9). The scan fetches the page and its scripts passively, follows the
// vendor's security.txt and CSAF VEX documents, reads an SBOM/VEX the
// reviewer supplies (--sbom, --sbom-url), looks components up in OSV and
// NVD, and ranks them with KEV and EPSS.
package main

import (
Expand All @@ -21,7 +23,7 @@ import (
"google.golang.org/protobuf/encoding/protojson"
)

const usage = "usage: touchstone scan [--allow-private] [--format json|md] <url>\n touchstone serve [--addr host:port]"
const usage = "usage: touchstone scan [--allow-private] [--format json|md] [--sbom file] [--sbom-url url] <url>\n touchstone serve [--addr host:port]"

// newService builds the ScanService for one CLI invocation. The fetch
// options carry CLI-only settings such as --allow-private, which the
Expand Down Expand Up @@ -62,15 +64,23 @@ func run(ctx context.Context, args []string, out io.Writer, newSvc newService) e
fs.SetOutput(io.Discard)
allowPrivate := fs.Bool("allow-private", false, "allow fetching loopback and private addresses (local fixtures only)")
format := fs.String("format", "json", "output format: json (protojson) or md (Markdown)")
sbomFile := fs.String("sbom", "", "an SBOM/VEX file you already have (CycloneDX, SPDX, OpenVEX or CSAF JSON)")
sbomURL := fs.String("sbom-url", "", "the URL of an SBOM/VEX document you already have")
if err := fs.Parse(args[1:]); err != nil || fs.NArg() != 1 {
return errors.New(usage)
}
render, err := renderer(*format)
if err != nil {
return err
}
req := &touchstonev1.ScanRequest{Url: fs.Arg(0), SbomUrl: *sbomURL}
if *sbomFile != "" {
if req.SbomDocument, err = os.ReadFile(*sbomFile); err != nil {
return fmt.Errorf("--sbom: %w", err)
}
}
svc := newSvc(fetch.Options{AllowPrivate: *allowPrivate, Version: service.ToolVersion})
rep, err := svc.Scan(ctx, &touchstonev1.ScanRequest{Url: fs.Arg(0)})
rep, err := svc.Scan(ctx, req)
if err != nil {
return err
}
Expand Down
29 changes: 29 additions & 0 deletions cmd/touchstone/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,40 @@ func TestScanFormatFlag(t *testing.T) {
}
}

// capture is a ScanService that records the request it was given.
type capture struct {
touchstonev1.UnimplementedScanServiceServer
req *touchstonev1.ScanRequest
}

func (c *capture) Scan(ctx context.Context, req *touchstonev1.ScanRequest) (*touchstonev1.ScanReport, error) {
c.req = req
return fixedStub(fetch.Options{}).Scan(ctx, req)
}

func TestScanSuppliedSBOMFlags(t *testing.T) {
file := filepath.Join(t.TempDir(), "sbom.json")
doc := []byte(`{"bomFormat": "CycloneDX", "components": []}`)
if err := os.WriteFile(file, doc, 0o600); err != nil {
t.Fatal(err)
}
c := &capture{}
newSvc := func(fetch.Options) touchstonev1.ScanServiceServer { return c }
args := []string{"scan", "--sbom", file, "--sbom-url", "https://vendor.example/sbom.json", "https://vendor.example"}
if err := run(context.Background(), args, &bytes.Buffer{}, newSvc); err != nil {
t.Fatalf("run(%q): %v", args, err)
}
if !bytes.Equal(c.req.GetSbomDocument(), doc) || c.req.GetSbomUrl() != "https://vendor.example/sbom.json" {
t.Errorf("ScanRequest = %v, want the file's bytes as sbom_document and the sbom_url", c.req)
}
}

func TestScanRejectsBadArgs(t *testing.T) {
for _, args := range [][]string{
nil, {"scan"}, {"serve", "https://example.com"}, {"scan", "ftp://example.com"}, {"scan", "example.com"},
{"scan", "--allow-private"}, {"scan", "--no-such-flag", "https://example.com"}, {"scan", "https://a.example", "https://b.example"},
{"scan", "--format", "xml", "https://example.com"}, {"scan", "--format", "https://example.com"},
{"scan", "--sbom", filepath.Join(t.TempDir(), "missing.json"), "https://example.com"},
} {
if err := run(context.Background(), args, &bytes.Buffer{}, fixedStub); err == nil {
t.Errorf("run(%q) = nil error, want error", args)
Expand Down
Loading
Loading