Skip to content

Commit

Permalink
Fix issue with moving to hex random
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Jun 10, 2024
1 parent e8ce775 commit 950f8f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 11 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,20 @@ func GetIPFromRequest(r *http.Request) net.IP {
}

func GenerateRandomHex(n uint32) (string, error) {
b := make([]byte, n)
_, err := rand.Read(b)
b, err := GenerateRandom(n)
if err != nil {
return "", err
}

return hex.EncodeToString(b), nil
}

func GenerateRandom(n uint32) ([]byte, error) {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
return b, err
}

return b, nil
}
9 changes: 7 additions & 2 deletions internal/webserver/authenticators/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ func (o *Oidc) LogoutPath() string {

func (o *Oidc) Init() error {

key, err := utils.GenerateRandomHex(32)
key, err := utils.GenerateRandom(32)
if err != nil {
return errors.New("failed to get random key: " + err.Error())
}

hashkey, err := utils.GenerateRandom(32)
if err != nil {
return errors.New("failed to get random hash key: " + err.Error())
}

o.details, err = data.GetOidc()
if err != nil {
return err
}

cookieHandler := httphelper.NewCookieHandler([]byte(key), []byte(key), httphelper.WithUnsecure())
cookieHandler := httphelper.NewCookieHandler([]byte(hashkey), []byte(key), httphelper.WithUnsecure())

options := []rp.Option{
rp.WithCookieHandler(cookieHandler),
Expand Down

0 comments on commit 950f8f8

Please sign in to comment.