mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 19:22:45 +00:00
sync: fix vault key getting reset on sync
This commit is contained in:
@@ -305,7 +305,14 @@ namespace Notesnook.API.Hubs
|
||||
GlobalSync.StartPush(userId, Context.ConnectionId);
|
||||
|
||||
|
||||
if (userSettings.VaultKey != null && syncMetadata.VaultKey != null && !userSettings.VaultKey.Equals(syncMetadata.VaultKey) || (userSettings.VaultKey == null && syncMetadata.VaultKey != null))
|
||||
if (
|
||||
(userSettings.VaultKey != null &&
|
||||
syncMetadata.VaultKey != null &&
|
||||
!userSettings.VaultKey.Equals(syncMetadata.VaultKey) &&
|
||||
!syncMetadata.VaultKey.IsEmpty()) ||
|
||||
(userSettings.VaultKey == null &&
|
||||
syncMetadata.VaultKey != null &&
|
||||
!syncMetadata.VaultKey.IsEmpty()))
|
||||
{
|
||||
userSettings.VaultKey = syncMetadata.VaultKey;
|
||||
await Repositories.UsersSettings.UpsertAsync(userSettings, (u) => u.UserId == userId);
|
||||
|
||||
@@ -25,8 +25,10 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace Notesnook.API.Models
|
||||
{
|
||||
[MessagePack.MessagePackObject]
|
||||
public class EncryptedData : IEncrypted
|
||||
{
|
||||
[MessagePack.Key("iv")]
|
||||
[JsonPropertyName("iv")]
|
||||
[BsonElement("iv")]
|
||||
[DataMember(Name = "iv")]
|
||||
@@ -35,6 +37,7 @@ namespace Notesnook.API.Models
|
||||
get; set;
|
||||
}
|
||||
|
||||
[MessagePack.Key("cipher")]
|
||||
[JsonPropertyName("cipher")]
|
||||
[BsonElement("cipher")]
|
||||
[DataMember(Name = "cipher")]
|
||||
@@ -43,11 +46,13 @@ namespace Notesnook.API.Models
|
||||
get; set;
|
||||
}
|
||||
|
||||
[MessagePack.Key("length")]
|
||||
[JsonPropertyName("length")]
|
||||
[BsonElement("length")]
|
||||
[DataMember(Name = "length")]
|
||||
public long Length { get; set; }
|
||||
|
||||
[MessagePack.Key("salt")]
|
||||
[JsonPropertyName("salt")]
|
||||
[BsonElement("salt")]
|
||||
[DataMember(Name = "salt")]
|
||||
@@ -61,5 +66,10 @@ namespace Notesnook.API.Models
|
||||
}
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return this.Cipher == null && this.IV == null && this.Length == 0 && this.Salt == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user