Files
Matthew Meszaros b9a5871308 feat: key the cipher service by organization ID
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.
2026-06-10 17:16:26 +02:00

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
}