mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
Add OpenPGP key to provider metadata when generated at setup.
This commit is contained in:
parent
f2d8cd1e90
commit
9cf4a7cb5c
3 changed files with 20 additions and 10 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/csaf-poc/csaf_distribution/csaf"
|
||||
)
|
||||
|
||||
|
|
@ -70,6 +71,15 @@ func (cfg *config) modelTLPs() []csaf.TLPLabel {
|
|||
return tlps
|
||||
}
|
||||
|
||||
func (cfg *config) loadCryptoKey() (*crypto.Key, error) {
|
||||
f, err := os.Open(cfg.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
return crypto.NewKeyFromArmoredReader(f)
|
||||
}
|
||||
|
||||
func loadConfig() (*config, error) {
|
||||
path := os.Getenv(configEnv)
|
||||
if path == "" {
|
||||
|
|
|
|||
|
|
@ -112,19 +112,10 @@ func loadCSAF(r *http.Request) (string, []byte, error) {
|
|||
return cleanFileName(handler.Filename), buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func (c *controller) loadCryptoKey() (*crypto.Key, error) {
|
||||
f, err := os.Open(c.cfg.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
return crypto.NewKeyFromArmoredReader(f)
|
||||
}
|
||||
|
||||
func (c *controller) handleSignature(r *http.Request, data []byte) (string, string, error) {
|
||||
|
||||
// Either way ... we need the key.
|
||||
key, err := c.loadCryptoKey()
|
||||
key, err := c.cfg.loadCryptoKey()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,5 +95,14 @@ func createProviderMetadata(c *config, wellknownCSAF string) error {
|
|||
}
|
||||
pm := csaf.NewProviderMetadataDomain(c.Domain, c.modelTLPs())
|
||||
pm.Publisher = c.Publisher
|
||||
|
||||
// Set OpenPGP key.
|
||||
key, err := c.loadCryptoKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fingerprint := key.GetFingerprint()
|
||||
pm.SetPGP(fingerprint, c.GetOpenPGPURL(fingerprint))
|
||||
|
||||
return saveToFile(path, pm)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue