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:
parent
10eb90907f
commit
d335ad1b84
4 changed files with 40 additions and 11 deletions
|
|
@ -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 == "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue