mirror of
https://github.com/zitadel/zitadel
synced 2024-11-23 11:12:21 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
37 lines
1006 B
Go
37 lines
1006 B
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/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
|
|
}
|