mirror of
https://github.com/warmbly/warmbly.git
synced 2026-08-19 16:01:16 +00:00
b9a5871308
cipher.CipherService.Cipher(ctx, orgID) now resolves, generates, and caches DEKs per organization (Redis key decrypted_key:<orgID>). Platform-level secrets keep the zero-UUID identity, renamed to platformCipherID since it no longer partitions against user keys.
33 lines
660 B
Go
33 lines
660 B
Go
package cipher
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func getDecryptedKeyKey(orgID uuid.UUID) string {
|
|
return "decrypted_key:" + orgID.String()
|
|
}
|
|
|
|
func (s *cipherService) getDecryptedKey(ctx context.Context, orgID uuid.UUID) ([]byte, error) {
|
|
key := getDecryptedKeyKey(orgID)
|
|
|
|
deckey, err := s.cache.Get(ctx, key).Bytes()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return deckey, nil
|
|
}
|
|
|
|
func (s *cipherService) saveDecryptedKey(ctx context.Context, orgID uuid.UUID, decryptedKey []byte) error {
|
|
key := getDecryptedKeyKey(orgID)
|
|
|
|
if err := s.cache.SetNX(ctx, key, decryptedKey, DecryptedKeyTTL).Err(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|