Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for API keys #4515

Merged
merged 8 commits into from
Aug 25, 2020
Prev Previous commit
Next Next commit
Use secure random value as key secret
  • Loading branch information
ikapelyukhin committed Aug 20, 2020
commit e93d550da2233ef37b0d2b9c7f26be162a63caf0
10 changes: 9 additions & 1 deletion src/jetstream/repository/apikeys/psql_apikeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package apikeys

import (
"database/sql"
"encoding/base64"
"errors"
"time"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/crypto"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/datastore"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces"
uuid "github.com/satori/go.uuid"
Expand Down Expand Up @@ -52,12 +54,18 @@ func (p *PgsqlAPIKeysRepository) AddAPIKey(userID string, comment string) (*inte
log.Debug(msg)
err = errors.New(msg)
}

if err != nil {
return nil, err
}

randomBytes, err := crypto.GenerateRandomBytes(48)
if err != nil {
return nil, err
}

keyGUID := uuid.NewV4().String()
keySecret := uuid.NewV4().String()
keySecret := base64.URLEncoding.EncodeToString(randomBytes)

var result sql.Result
if result, err = p.db.Exec(insertAPIKey, keyGUID, keySecret, userID, comment); err != nil {
Expand Down