diff --git a/src/AesPasswordEncryptedPubSub.cs b/src/AesPasswordEncryptedPubSub.cs index 228cc30..3d52bbe 100644 --- a/src/AesPasswordEncryptedPubSub.cs +++ b/src/AesPasswordEncryptedPubSub.cs @@ -49,7 +49,11 @@ public async Task PublishAsync(string topic, Stream message, CancellationToken c message.Seek(0, SeekOrigin.Begin); var aes = Aes.Create(); +#if NETSTANDARD2_0 var passBytes = new Rfc2898DeriveBytes(password: _password, salt: Encoding.UTF8.GetBytes(_salt ?? string.Empty), iterations: 2000); +#elif NET5_0_OR_GREATER + var passBytes = new Rfc2898DeriveBytes(password: _password, salt: Encoding.UTF8.GetBytes(_salt ?? string.Empty), iterations: 2000, HashAlgorithmName.SHA1); +#endif aes.Key = passBytes.GetBytes(aes.KeySize / 8); aes.IV = passBytes.GetBytes(aes.BlockSize / 8); @@ -87,7 +91,11 @@ public Task> SubscribedTopicsAsync(CancellationToken cancel internal IPublishedMessage? TryTransformPublishedMessage(IPublishedMessage publishedMessage) { var aes = Aes.Create(); - var passBytes = new Rfc2898DeriveBytes(password: _password, salt: Encoding.UTF8.GetBytes(_salt ?? string.Empty)); +#if NETSTANDARD2_0 + var passBytes = new Rfc2898DeriveBytes(password: _password, salt: Encoding.UTF8.GetBytes(_salt ?? string.Empty), iterations: 2000); +#elif NET5_0_OR_GREATER + var passBytes = new Rfc2898DeriveBytes(password: _password, salt: Encoding.UTF8.GetBytes(_salt ?? string.Empty), iterations: 2000, HashAlgorithmName.SHA1); +#endif aes.Key = passBytes.GetBytes(aes.KeySize / 8); aes.IV = passBytes.GetBytes(aes.BlockSize / 8); @@ -99,8 +107,10 @@ public Task> SubscribedTopicsAsync(CancellationToken cancel using var streamDecryptor = new CryptoStream(inputStream, aes.CreateDecryptor(), CryptoStreamMode.Read); streamDecryptor.CopyTo(outputStream); + outputStream.Seek(0, SeekOrigin.Begin); var outputBytes = outputStream.ToBytes(); + outputStream.Seek(0, SeekOrigin.Begin); return new PublishedMessage(publishedMessage.Sender, publishedMessage.Topics, publishedMessage.SequenceNumber, outputBytes, outputStream, publishedMessage.Size); } catch diff --git a/src/Cache/CachedKeyApi.cs b/src/Cache/CachedKeyApi.cs index 3738220..6b95990 100644 --- a/src/Cache/CachedKeyApi.cs +++ b/src/Cache/CachedKeyApi.cs @@ -13,7 +13,9 @@ public class CachedKeyApi : SettingsBase, IKeyApi, IDelegable, IAsyncIn /// /// The cached record type for created or resolved s. /// - public record KeyInfo(string Name, Cid Id) : IKey; + public record CachedKeyInfo(string Name, string Id); + + private record ApiKeyInfo(string Name, Cid Id) : IKey; /// /// Creates a new instance of . @@ -28,9 +30,9 @@ public CachedKeyApi(IModifiableFolder folder) /// /// The resolved ipns keys. /// - public List Keys + public List Keys { - get => GetSetting(() => new List()); + get => GetSetting(() => new List()); set => SetSetting(value); } @@ -46,12 +48,12 @@ public async Task CreateAsync(string name, string keyType, int size, Cance if (existing is not null) Keys.Remove(existing); - Keys.Add(new KeyInfo(Name: res.Name, Id: res.Id)); + Keys.Add(new CachedKeyInfo(Name: res.Name, Id: res.Id)); return res; } /// - public Task> ListAsync(CancellationToken cancel = default) => Task.FromResult>(Keys); + public Task> ListAsync(CancellationToken cancel = default) => Task.FromResult>(Keys.Select(x=> new ApiKeyInfo(x.Name, x.Id))); /// public Task RemoveAsync(string name, CancellationToken cancel = default) => Inner.RemoveAsync(name, cancel); @@ -72,7 +74,7 @@ public async Task CreateAsync(string name, string keyType, int size, Cance public async Task InitAsync(CancellationToken cancellationToken = default) { var res = await Inner.ListAsync(cancellationToken); - Keys = res.Select(x => new KeyInfo(x.Name, x.Id)).ToList(); + Keys = res.Select(x => new CachedKeyInfo(x.Name, x.Id)).ToList(); await SaveAsync(cancellationToken); diff --git a/src/Cache/KuboCacheSerializerContext.cs b/src/Cache/KuboCacheSerializerContext.cs index 777db2b..30e41a7 100644 --- a/src/Cache/KuboCacheSerializerContext.cs +++ b/src/Cache/KuboCacheSerializerContext.cs @@ -10,7 +10,7 @@ namespace OwlCore.Kubo.Cache; [JsonSerializable(typeof(string))] [JsonSerializable(typeof(int))] [JsonSerializable(typeof(List))] -[JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] public partial class KuboCacheSerializerContext : JsonSerializerContext { } \ No newline at end of file diff --git a/src/OwlCore.Kubo.csproj b/src/OwlCore.Kubo.csproj index aa84345..da44198 100644 --- a/src/OwlCore.Kubo.csproj +++ b/src/OwlCore.Kubo.csproj @@ -14,15 +14,23 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb Arlo Godfrey - 0.16.3 + 0.16.4 OwlCore An essential toolkit for Kubo, IPFS and the distributed web. LICENSE.txt +--- 0.16.4 --- +[Fixes] +Fixed decryption on AesPasswordEncryptedPubSub, addressed usage of deprecated Rfc2898DeriveBytes constructor. +Fixed an issue where cached KeyInfo wasn't being serialized/deserialized. + +[Improvements] +Updated dependencies to latest available stable versions. + --- 0.16.3 --- -[Fises] +[Fixes] Fixed an issue where flushing the CachedNameApi would throw multiple enumeration with a non-empty cache. --- 0.16.2 --- @@ -398,16 +406,16 @@ Added unit tests. - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + \ No newline at end of file