diff --git a/Notesnook.API/Hubs/SyncHub.cs b/Notesnook.API/Hubs/SyncHub.cs index 55a6ff2..797755c 100644 --- a/Notesnook.API/Hubs/SyncHub.cs +++ b/Notesnook.API/Hubs/SyncHub.cs @@ -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); diff --git a/Notesnook.API/Models/EncryptedData.cs b/Notesnook.API/Models/EncryptedData.cs index 1b1e646..2646ade 100644 --- a/Notesnook.API/Models/EncryptedData.cs +++ b/Notesnook.API/Models/EncryptedData.cs @@ -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; + } } }