mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
75ec73ca4a
* feat: dynamic issuer * dynamic domain handling * key rotation durations * feat: dynamic issuer * make webauthn displayname dynamic
37 lines
994 B
Go
37 lines
994 B
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/repository/keypair"
|
|
)
|
|
|
|
func (c *Commands) GenerateSigningKeyPair(ctx context.Context, algorithm string) error {
|
|
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, authz.GetInstance(ctx).InstanceID())
|
|
keyAgg := KeyPairAggregateFromWriteModel(&keyPairWriteModel.WriteModel)
|
|
_, err = c.eventstore.Push(ctx, keypair.NewAddedEvent(
|
|
ctx,
|
|
keyAgg,
|
|
domain.KeyUsageSigning,
|
|
algorithm,
|
|
privateCrypto, publicCrypto,
|
|
privateKeyExp, publicKeyExp))
|
|
return err
|
|
}
|