fix: bearer token encryption (#1524)

* fix: bearer token encryption

* remove some todos
This commit is contained in:
Livio Amstutz
2021-04-06 08:31:18 +02:00
committed by GitHub
parent 18aec74222
commit 27fcf4739d
9 changed files with 26 additions and 21 deletions

View File

@@ -26,7 +26,7 @@ import (
)
type TokenVerifierRepo struct {
TokenVerificationKey [32]byte
TokenVerificationKey crypto.EncryptionAlgorithm
IAMID string
Eventstore v1.Eventstore
View *view.View
@@ -68,8 +68,7 @@ func (repo *TokenVerifierRepo) TokenByID(ctx context.Context, tokenID, userID st
func (repo *TokenVerifierRepo) VerifyAccessToken(ctx context.Context, tokenString, clientID string) (userID string, agentID string, prefLang, resourceOwner string, err error) {
ctx, span := tracing.NewSpan(ctx)
defer func() { span.EndWithError(err) }()
//TODO: use real key
tokenIDSubject, err := crypto.DecryptAESString(tokenString, string(repo.TokenVerificationKey[:32]))
tokenIDSubject, err := repo.TokenVerificationKey.DecryptString([]byte(tokenString), repo.TokenVerificationKey.EncryptionKeyID())
if err != nil {
return "", "", "", "", caos_errs.ThrowUnauthenticated(nil, "APP-8EF0zZ", "invalid token")
}

View File

@@ -3,6 +3,7 @@ package eventsourcing
import (
"context"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/eventstore/v1"
"github.com/caos/zitadel/internal/query"
@@ -49,6 +50,11 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults, qu
spool := spooler.StartSpooler(conf.Spooler, es, view, sqlClient, systemDefaults)
keyAlgorithm, err := crypto.NewAESCrypto(systemDefaults.KeyConfig.EncryptionConfig)
if err != nil {
return nil, err
}
return &EsRepository{
spool,
eventstore.UserGrantRepo{
@@ -62,10 +68,10 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults, qu
IAMV2Query: queries,
},
eventstore.TokenVerifierRepo{
//TODO: Add Token Verification Key
Eventstore: es,
IAMID: systemDefaults.IamID,
View: view,
TokenVerificationKey: keyAlgorithm,
Eventstore: es,
IAMID: systemDefaults.IamID,
View: view,
},
}, nil
}