1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 05:40:11 +01:00

Added server config and middleware to use password to protect endpoints.

This commit is contained in:
Sascha L. Teichmann 2021-12-06 17:24:45 +01:00
parent 10eb90907f
commit d335ad1b84
4 changed files with 40 additions and 11 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/csaf-poc/csaf_distribution/csaf"
"golang.org/x/crypto/bcrypt"
)
const (
@ -19,6 +20,7 @@ const (
)
type config struct {
Password *string `toml:"password"`
Key string `toml:"key"`
Folder string `toml:"folder"`
Web string `toml:"web"`
@ -83,6 +85,11 @@ func (cfg *config) loadCryptoKey() (*crypto.Key, error) {
return crypto.NewKeyFromArmoredReader(f)
}
func (cfg *config) checkPassword(hash string) bool {
return cfg.Password == nil ||
bcrypt.CompareHashAndPassword([]byte(hash), []byte(*cfg.Password)) == nil
}
func loadConfig() (*config, error) {
path := os.Getenv(configEnv)
if path == "" {