Skip to content

Commit

Permalink
Merge pull request #9 from Arlodotexe/release/0.16.4
Browse files Browse the repository at this point in the history
Release 0.16.4
  • Loading branch information
Arlodotexe authored Jul 17, 2024
2 parents df105b9 + a84a6d0 commit 040a606
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
12 changes: 11 additions & 1 deletion src/AesPasswordEncryptedPubSub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -87,7 +91,11 @@ public Task<IEnumerable<string>> 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);
Expand All @@ -99,8 +107,10 @@ public Task<IEnumerable<string>> 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
Expand Down
14 changes: 8 additions & 6 deletions src/Cache/CachedKeyApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class CachedKeyApi : SettingsBase, IKeyApi, IDelegable<IKeyApi>, IAsyncIn
/// <summary>
/// The cached record type for created or resolved <see cref="IKey"/>s.
/// </summary>
public record KeyInfo(string Name, Cid Id) : IKey;
public record CachedKeyInfo(string Name, string Id);

private record ApiKeyInfo(string Name, Cid Id) : IKey;

/// <summary>
/// Creates a new instance of <see cref="CachedKeyApi"/>.
Expand All @@ -28,9 +30,9 @@ public CachedKeyApi(IModifiableFolder folder)
/// <summary>
/// The resolved ipns keys.
/// </summary>
public List<KeyInfo> Keys
public List<CachedKeyInfo> Keys
{
get => GetSetting(() => new List<KeyInfo>());
get => GetSetting(() => new List<CachedKeyInfo>());
set => SetSetting(value);
}

Expand All @@ -46,12 +48,12 @@ public async Task<IKey> 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;
}

/// <inheritdoc />
public Task<IEnumerable<IKey>> ListAsync(CancellationToken cancel = default) => Task.FromResult<IEnumerable<IKey>>(Keys);
public Task<IEnumerable<IKey>> ListAsync(CancellationToken cancel = default) => Task.FromResult<IEnumerable<IKey>>(Keys.Select(x=> new ApiKeyInfo(x.Name, x.Id)));

/// <inheritdoc />
public Task<IKey?> RemoveAsync(string name, CancellationToken cancel = default) => Inner.RemoveAsync(name, cancel);
Expand All @@ -72,7 +74,7 @@ public async Task<IKey> 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);

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/KuboCacheSerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OwlCore.Kubo.Cache;
[JsonSerializable(typeof(string))]
[JsonSerializable(typeof(int))]
[JsonSerializable(typeof(List<string>))]
[JsonSerializable(typeof(List<string>))]
[JsonSerializable(typeof(List<CachedKeyApi.CachedKeyInfo>))]
public partial class KuboCacheSerializerContext : JsonSerializerContext
{
}
18 changes: 13 additions & 5 deletions src/OwlCore.Kubo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>

<Author>Arlo Godfrey</Author>
<Version>0.16.3</Version>
<Version>0.16.4</Version>
<Product>OwlCore</Product>
<Description>
An essential toolkit for Kubo, IPFS and the distributed web.
</Description>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageReleaseNotes>
--- 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 ---
Expand Down Expand Up @@ -398,16 +406,16 @@ Added unit tests.
<PackageReference Include="OwlCore" Version="0.5.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="OwlCore.ComponentModel" Version="0.8.0" />
<PackageReference Include="OwlCore.ComponentModel" Version="0.8.1" />
<PackageReference Include="OwlCore.ComponentModel.Settings" Version="0.0.0" />
<PackageReference Include="OwlCore.Extensions" Version="0.8.0" />
<PackageReference Include="OwlCore.Storage" Version="0.11.0" />
<PackageReference Include="OwlCore.Storage" Version="0.11.3" />
<PackageReference Include="OwlCore.Storage.SharpCompress" Version="0.1.0" />
<PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>
</Project>

0 comments on commit 040a606

Please sign in to comment.