diff --git a/cmd/csaf_provider/config.go b/cmd/csaf_provider/config.go index 13997db..e33594a 100644 --- a/cmd/csaf_provider/config.go +++ b/cmd/csaf_provider/config.go @@ -57,6 +57,7 @@ type config struct { Issuer *string `toml:"issuer"` RemoteValidator *csaf.RemoteValidatorOptions `toml:"remote_validator"` Categories *[]string `toml:"categories"` + ServiceDocument bool `toml:"create_service_document"` } func (pmdc *providerMetadataConfig) apply(pmd *csaf.ProviderMetadata) { diff --git a/cmd/csaf_provider/create.go b/cmd/csaf_provider/create.go index 6529c2f..22c9200 100644 --- a/cmd/csaf_provider/create.go +++ b/cmd/csaf_provider/create.go @@ -34,6 +34,7 @@ func ensureFolders(c *config) error { for _, create := range []func(*config, string) error{ createWellknown, createFeedFolders, + createService, createOpenPGPFolder, createProviderMetadata, } { @@ -61,6 +62,53 @@ func createWellknown(_ *config, wellknown string) error { return nil } +// createService creates the ROLIE service document (if configured). +func createService(c *config, wellknownCSAF string) error { + // no service document needed. + if !c.ServiceDocument { + return nil + } + + categories := csaf.ROLIEServiceWorkspaceCollectionCategories{ + Category: []csaf.ROLIEServiceWorkspaceCollectionCategoriesCategory{{ + Scheme: "urn:ietf:params:rolie:category:information-type", + Term: "csaf", + }}, + } + + var collections []csaf.ROLIEServiceWorkspaceCollection + + for _, t := range c.TLPs { + if t == tlpCSAF { + continue + } + ts := string(t) + title := "CSAF feed (TLP:" + strings.ToUpper(ts) + ")" + feedName := "csaf-feed-tlp-" + ts + ".json" + href := c.CanonicalURLPrefix + + "/.well-known/csaf/" + ts + "/" + feedName + + collection := csaf.ROLIEServiceWorkspaceCollection{ + Title: title, + HRef: href, + Categories: categories, + } + collections = append(collections, collection) + } + + rsd := &csaf.ROLIEServiceDocument{ + Service: csaf.ROLIEService{ + Workspace: []csaf.ROLIEServiceWorkspace{{ + Title: "CSAF feeds", + Collection: collections, + }}, + }, + } + + path := filepath.Join(wellknownCSAF, "service.json") + return util.WriteToFile(path, rsd) +} + // createFeedFolders creates the feed folders according to the tlp values // in the "tlps" config option if they do not already exist. // No creation for the "csaf" option will be done.