mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
8dcbbc87ca
* fix: adaot config to commands (and queries) * remove dependency on vv2 in v1 * add queries user to operator * set password for queries on tests * set password for queries on tests * fix config
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
keypair "github.com/caos/zitadel/internal/repository/keypair"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
oidcUser = "OIDC"
|
|
)
|
|
|
|
func (c *Commands) GenerateSigningKeyPair(ctx context.Context, algorithm string) error {
|
|
ctx = setOIDCCtx(ctx)
|
|
privateCrypto, publicCrypto, err := crypto.GenerateEncryptedKeyPair(c.keySize, c.keyAlgorithm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
keyID, err := c.idGenerator.Next()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
privateKeyExp := time.Now().UTC().Add(c.privateKeyLifetime)
|
|
publicKeyExp := time.Now().UTC().Add(c.publicKeyLifetime)
|
|
|
|
keyPairWriteModel := NewKeyPairWriteModel(keyID, domain.IAMID)
|
|
keyAgg := KeyPairAggregateFromWriteModel(&keyPairWriteModel.WriteModel)
|
|
_, err = c.eventstore.PushEvents(ctx, keypair.NewAddedEvent(
|
|
ctx,
|
|
keyAgg,
|
|
domain.KeyUsageSigning,
|
|
algorithm,
|
|
privateCrypto, publicCrypto,
|
|
privateKeyExp, publicKeyExp))
|
|
return err
|
|
}
|
|
|
|
func setOIDCCtx(ctx context.Context) context.Context {
|
|
return authz.SetCtxData(ctx, authz.CtxData{UserID: oidcUser, OrgID: domain.IAMID})
|
|
}
|