mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-01 12:47:24 +00:00

* commander * commander * selber! * move to packages * fix(errors): implement Is interface * test: command * test: commands * add init steps * setup tenant * add default step yaml * possibility to set password * merge v2 into v2-commander * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: search query builder can filter events in memory * fix: filters for add member * fix(setup): add `ExternalSecure` to config * chore: name iam to instance * fix: matching * remove unsued func * base url * base url * test(command): filter funcs * test: commands * fix: rename orgiampolicy to domain policy * start from init * commands * config * fix indexes and add constraints * fixes * fix: merge conflicts * fix: protos * fix: md files * setup * add deprecated org iam policy again * typo * fix search query * fix filter * Apply suggestions from code review * remove custom org from org setup * add todos for verification * change apps creation * simplify package structure * fix error * move preparation helper for tests * fix unique constraints * fix config mapping in setup * fix error handling in encryption_keys.go * fix projection config * fix query from old views to projection * fix setup of mgmt api * set iam project and fix instance projection * imports Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
package start
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
)
|
|
|
|
var (
|
|
defaultKeyIDs = []string{
|
|
"domainVerificationKey",
|
|
"idpConfigKey",
|
|
"oidcKey",
|
|
"otpKey",
|
|
"smsKey",
|
|
"smtpKey",
|
|
"userKey",
|
|
"csrfCookieKey",
|
|
"userAgentCookieKey",
|
|
}
|
|
)
|
|
|
|
type encryptionKeys struct {
|
|
DomainVerification crypto.EncryptionAlgorithm
|
|
IDPConfig crypto.EncryptionAlgorithm
|
|
OIDC crypto.EncryptionAlgorithm
|
|
OTP crypto.EncryptionAlgorithm
|
|
SMS crypto.EncryptionAlgorithm
|
|
SMTP crypto.EncryptionAlgorithm
|
|
User crypto.EncryptionAlgorithm
|
|
CSRFCookieKey []byte
|
|
UserAgentCookieKey []byte
|
|
OIDCKey []byte
|
|
}
|
|
|
|
func ensureEncryptionKeys(keyConfig *encryptionKeyConfig, keyStorage crypto.KeyStorage) (*encryptionKeys, error) {
|
|
keys, err := keyStorage.ReadKeys()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(keys) == 0 {
|
|
if err := createDefaultKeys(keyStorage); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
encryptionKeys := new(encryptionKeys)
|
|
encryptionKeys.DomainVerification, err = crypto.NewAESCrypto(keyConfig.DomainVerification, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.IDPConfig, err = crypto.NewAESCrypto(keyConfig.IDPConfig, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.OIDC, err = crypto.NewAESCrypto(keyConfig.OIDC, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
key, err := crypto.LoadKey(keyConfig.OIDC.EncryptionKeyID, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.OIDCKey = []byte(key)
|
|
encryptionKeys.OTP, err = crypto.NewAESCrypto(keyConfig.OTP, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.SMS, err = crypto.NewAESCrypto(keyConfig.SMS, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.SMTP, err = crypto.NewAESCrypto(keyConfig.SMTP, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.User, err = crypto.NewAESCrypto(keyConfig.User, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
key, err = crypto.LoadKey(keyConfig.CSRFCookieKeyID, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.CSRFCookieKey = []byte(key)
|
|
key, err = crypto.LoadKey(keyConfig.UserAgentCookieKeyID, keyStorage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
encryptionKeys.UserAgentCookieKey = []byte(key)
|
|
return encryptionKeys, nil
|
|
}
|
|
|
|
func createDefaultKeys(keyStorage crypto.KeyStorage) error {
|
|
keys := make([]*crypto.Key, len(defaultKeyIDs))
|
|
for i, keyID := range defaultKeyIDs {
|
|
key, err := crypto.NewKey(keyID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
keys[i] = key
|
|
}
|
|
if err := keyStorage.CreateKeys(keys...); err != nil {
|
|
return caos_errs.ThrowInternal(err, "START-aGBq2", "cannot create default keys")
|
|
}
|
|
return nil
|
|
}
|