fix: prevent double encryption when viewing password and saving
This commit is contained in:
+20
-6
@@ -267,6 +267,10 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
|||||||
}
|
}
|
||||||
if len(item.Passphrase) == 0 {
|
if len(item.Passphrase) == 0 {
|
||||||
item.Passphrase = existingAsset.Passphrase
|
item.Passphrase = existingAsset.Passphrase
|
||||||
|
} else {
|
||||||
|
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case "password":
|
case "password":
|
||||||
item.PrivateKey = "-"
|
item.PrivateKey = "-"
|
||||||
@@ -278,6 +282,22 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
|||||||
if len(item.Password) == 0 {
|
if len(item.Password) == 0 {
|
||||||
item.Password = existingAsset.Password
|
item.Password = existingAsset.Password
|
||||||
item.Encrypted = existingAsset.Encrypted
|
item.Encrypted = existingAsset.Encrypted
|
||||||
|
} else {
|
||||||
|
existingDecrypted := existingAsset
|
||||||
|
if err := s.Decrypt(&existingDecrypted, config.GlobalCfg.EncryptionPassword); err == nil {
|
||||||
|
if item.Password == existingDecrypted.Password {
|
||||||
|
item.Password = existingAsset.Password
|
||||||
|
item.Encrypted = existingAsset.Encrypted
|
||||||
|
} else if !item.Encrypted {
|
||||||
|
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if !item.Encrypted {
|
||||||
|
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,12 +313,6 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
|||||||
item.AccessGatewayId = "-"
|
item.AccessGatewayId = "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.Password != "" && item.Password != "-" && !item.Encrypted {
|
|
||||||
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.Transaction(context.Background(), func(ctx context.Context) error {
|
return s.Transaction(context.Background(), func(ctx context.Context) error {
|
||||||
if err := repository.AssetRepository.UpdateById(ctx, &item, id); err != nil {
|
if err := repository.AssetRepository.UpdateById(ctx, &item, id); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user