Free the terminal from the Hosts screen, and fill the room it left

The WebView sat inside the Hosts grid, so navigating to Files or the keychain
hid every open terminal and the strip that named them. A connection you had
opened was invisible from four of the five screens. The window now has two
surfaces rather than one: a nav rail that says which page you are on, and a
terminal strip that is always there and switches the whole content area to a
shell. Screen keeps meaning "which page" and never becomes a sixth kind of
page, which is why this is two properties instead of one enum with a terminal
member in it.

Every screen lives inside one wrapper panel that collapses when a terminal is
showing. That is not tidiness — the WebView hosts a Win32 child window that
composites above everything Avalonia draws, so a screen left visible over its
rectangle is a screen sliced in half, and this window has shipped that defect
once already. One decision point, IsTerminalShowing, and a nested panel rather
than five compound bindings nobody would remember to extend.

The focus choreography is the part no test in this repo can see. Every reveal
path now focuses in the same turn the WebView appeared, so all three of them
post at DispatcherPriority.Loaded and let the native control re-push its bounds
first. Going the other way had a real bug: the screen-changed branch called a
bare Focus() where it had to release the keyboard from the native child, so
switching from a terminal to Files silently ate the first keystrokes. Rare
before this commit and the primary gesture after it.

The tab strip grew a cross inside each tab, a plus that opens the quick-connect
palette, and middle-click close. Nested buttons are correct here: Avalonia
handles a left press on the cross and deliberately does not handle other
buttons, which is exactly what lets middle-click bubble up from the cross as
well as the tab. The test is PointerUpdateKind rather than
IsMiddleButtonPressed, because the latter reports button state and is also true
for a left press made while the middle button happens to be held. The handler
is on the tab and not the strip, so the background closes nothing by
construction. Plus opens the palette rather than a flyout, since a menu
dropping into the WebView's rectangle may or may not composite above a child
HWND and this repo does not make rendering claims it has not photographed.

Everything a user reads now says keychain. The wire, the database and the
cryptographic spec still say vault, deliberately: renaming those is a migration
and a protocol change for a word. That split is written down rather than left
to be rediscovered as an inconsistency.

Four things that were squeezed into the keychain's category rail, or into
nothing at all, now have screens. Pinned host keys get one, with fingerprints
never truncated and a filter that matches them, because comparing what you have
against what the operator published is the whole workflow; the approved date is
read out of the item's UUIDv7 rather than added as a column, and says so, since
it means first approval and not last use. Keys can be generated in the client,
which needed the openssh-key-v1 container written by hand — there is no BCL or
NSec helper, and the PKCS#8 route is unverified in the SSH library this uses.
The armour carries no passphrase: encrypting it needs bcrypt_pbkdf, which is
Blowfish with a swizzle, in a project whose crypto is otherwise entirely
libsodium, for a protection the key's own remarks argue is redundant inside a
vault. Generation fills the existing editor and stops, so SAVE stays the one
thing that writes. ~/.ssh/config can be imported behind a preview that is
ticked per row and writes nothing until the button; IdentityFile records the
path and imports the key material only on an explicit opt-in, because reading
somebody's private key into a vault is precisely the act this product exists to
make deliberate. Match blocks and ProxyJump are reported rather than obeyed —
one cannot be evaluated statically and the other has nothing behind it to route
with, and a preview that implied otherwise would be worse than one that admits
it.

Files can be dragged in all four directions that are honestly available. Remote
to Explorer does not ship and is not pretended to: the shell wants the bytes
during the drop, which needs a virtual file and a native COM data object,
outside what Avalonia offers. Note for the next person that Avalonia 12
replaced the drag model outright — DataObject and DataFormats are no-op stubs
and IDataObject is not in the reference assembly, so every tutorial written for
11 does not compile here.

Hosts can be grouped, flat and never nested. A parent id merged as a scalar
lets two offline clients each re-parent A under B and B under A, producing a
cycle inside an encrypted payload that no server can police and every reader
would have to detect for ever. Membership lives in that payload rather than in
the one plaintext concession ADR 0001 allows, whose test is that the relay
cannot function without it — nothing on the server reads a group, so what
plaintext would hand over is a clustering of the estate for nothing. The
plaintext column reserved for it is dropped, provably always null, and the
server now refuses a client that sends one; it was never populated, was copied
on apply, and was not cleared on delete, so a group id would have outlived the
host it described.

Snippets insert through xterm rather than through the pump, because xterm is
the only thing that knows whether the remote has bracketed paste on, and that
is what makes a shell treat embedded newlines as text instead of as execute.
The host process moves opaque bytes and never parses output, so it would have
to guess, and guessing wrong runs every line. Running is off by default and the
copy says the text goes into whatever is there — the terminal has no notion of
being at a prompt, and may be in vi or at a password prompt with echo off, so
the Enter the user presses themselves is the entire safety property.

Connections and keychain changes are recorded as synced encrypted items, which
is what makes them auditable by a team later and costs the server knowledge of
connection rate and timing from row counts alone. ADR 0001 already concedes it
cannot hide that class of metadata; the trade is now written into it rather
than left implicit. A connection entry is written once, at close, which is what
makes a synced log tractable: nothing to merge, one outbox row, no chance of
colliding with itself. Live sessions come from memory, not from the log. The
write is void by contract and posts to a bounded channel, because putting an
encrypt-and-write on the teardown path of every session is how closing the
application comes to take four seconds. A ticket opened before a lock still
closes afterwards, since a shell outlives the vault. The activity log hooks the
one generic repository every kind writes through, so it cannot miss a caller —
which is also why the log kinds themselves declare they are not audited, or the
first entry would write an entry about writing an entry. It records the names
of the fields that changed and never their values; a log with an old password
in it would be a plaintext credential store with no vault around it. Retention
is 90 days or 5,000 entries, whichever bites first, pruned on the sync loop
rather than on a second timer.

That log traffic then broke the status line, which is worth recording because
the fix is a shape and not a patch: background sync counted its own log rows as
pushed items, so the quiet rule stopped being quiet and every action's message
was overwritten a second later by a sync report. The report now separates log
rows from user items and the rule reads the latter.

S3 buckets appear as a remote in the file browser, behind the same interface an
SFTP session implements, so the queue and both panes did not have to learn what
they are talking to. Uploads go through a pipe, because the queue wants to
write and the SDK wants to read; memory is then bounded by the part size
instead of buffering a file to disk twice.

Finally, the Windows device key store moved out of the session project, which
was the one thing keeping it from being portable — everything else in it is
platform-neutral, and a Windows CNG dependency in the middle of the vault code
meant a second head could not reference it without dragging Windows along. The
seam that made the move free was already there. docs/android-port.md is the
audit behind that: what ports, what does not, in order of cost, the four
decisions taken, and an inventory of every screen and state the interface has
to carry, written so a design can be made from it directly.

dotnet build, dotnet test and dotnet format --verify-no-changes are all clean:
1240 tests at zero warnings, including the end-to-end suite against real
containers. The manual checks that headless Avalonia cannot make — the drag
from Explorer, a generated key against a real host, twelve tabs at the minimum
window width — are listed in docs/manual-checks.md and are still outstanding.
This commit is contained in:
2026-07-31 20:30:05 +02:00
parent 1292084af9
commit d07b336868
163 changed files with 24491 additions and 647 deletions
@@ -0,0 +1,131 @@
using System.Security.Cryptography;
using DodoSSH.Client.Domain;
using DodoSSH.Contracts;
using DodoSSH.Crypto;
namespace DodoSSH.Client.Sync;
/// <summary>
/// Turns a log entry into an item payload and back.
/// </summary>
/// <remarks>
/// <para>
/// Mirrors <see cref="KnownHostKeyCipher"/> exactly, including the rule that a payload is sealed at the
/// version the server <em>will</em> assign rather than the one it replaces — see <see cref="SyncVersions"/>.
/// In practice a log entry is only ever sealed at version 1, because nothing updates one; the general rule
/// is used anyway, so that this cipher does not become the one place where a different one applies.
/// </para>
/// <para>
/// <b>The resource type is the one thing not to copy.</b> <c>SyncEntityType.ActivityLogEntry</c> and
/// <c>CryptoSpec.AadResourceType.ActivityLogEntry</c> deliberately differ, as every pair in this folder does, and the
/// two log kinds sit next to each other in both enums — so a copied cipher with one constant left behind
/// seals a connection record under the resource type for an activity record. That encrypts perfectly,
/// decrypts perfectly on the machine that wrote it, and violates docs/crypto.md everywhere else.
/// </para>
/// </remarks>
public static class ActivityLogCipher
{
private const CryptoSpec.AadResourceType Resource = CryptoSpec.AadResourceType.ActivityLogEntry;
/// <summary>Encrypts an entry.</summary>
/// <param name="entry">The entry. Must be valid for storage.</param>
/// <param name="vaultKey">The vault key, which the data key is wrapped under.</param>
/// <param name="entityId">The item id, which the AAD binds.</param>
/// <param name="keyGeneration">The vault's current key generation.</param>
/// <param name="itemVersion">The version this payload will hold once the server accepts it.</param>
public static EncryptedPayload Seal(
ActivityLogSecret entry,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(entry);
ArgumentOutOfRangeException.ThrowIfLessThan(itemVersion, 1);
var plaintext = ActivityLogSecretCodec.Encode(entry);
var dataKey = ItemKeys.CreateDataKey();
try
{
var dataKeyId = Guid.CreateVersion7();
var wrappedDataKey = ItemKeys.WrapDataKey(
dataKey, vaultKey, Resource, entityId, keyGeneration, (uint)itemVersion);
var envelope = ItemKeys.SealPayload(
dataKey, plaintext, Resource, entityId, dataKeyId, keyGeneration, (uint)itemVersion);
return new EncryptedPayload(
envelope, wrappedDataKey, dataKeyId, keyGeneration, CryptoSpec.CurrentAadVersion);
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
// Wiped like every other payload here. Nothing in a log entry is a credential, and what it does
// hold — which machines this person reaches, and when — is the aggregate the whole item is
// encrypted to keep, so leaving it in a pooled buffer would be an odd place to stop caring.
CryptographicOperations.ZeroMemory(plaintext);
}
}
/// <summary>Decrypts an entry.</summary>
/// <inheritdoc cref="HostCipher.TryOpen" path="/returns" />
public static ActivityLogSecretDocument? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(payload);
if (itemVersion < 1 || payload.WrappedDataKey.Length == 0)
{
return null;
}
var dataKey = ItemKeys.TryUnwrapDataKey(
vaultKey,
payload.WrappedDataKey,
Resource,
entityId,
payload.KeyGeneration,
(uint)itemVersion);
if (dataKey is null)
{
return null;
}
try
{
var plaintext = ItemKeys.TryOpenPayload(
dataKey,
payload.Envelope,
Resource,
entityId,
payload.DataKeyId,
payload.KeyGeneration,
(uint)itemVersion);
if (plaintext is null)
{
return null;
}
try
{
return ActivityLogSecretCodec.TryDecode(plaintext, out var document) ? document : null;
}
finally
{
CryptographicOperations.ZeroMemory(plaintext);
}
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
}
}
}
@@ -0,0 +1,131 @@
using System.Security.Cryptography;
using DodoSSH.Client.Domain;
using DodoSSH.Contracts;
using DodoSSH.Crypto;
namespace DodoSSH.Client.Sync;
/// <summary>
/// Turns a log entry into an item payload and back.
/// </summary>
/// <remarks>
/// <para>
/// Mirrors <see cref="KnownHostKeyCipher"/> exactly, including the rule that a payload is sealed at the
/// version the server <em>will</em> assign rather than the one it replaces — see <see cref="SyncVersions"/>.
/// In practice a log entry is only ever sealed at version 1, because nothing updates one; the general rule
/// is used anyway, so that this cipher does not become the one place where a different one applies.
/// </para>
/// <para>
/// <b>The resource type is the one thing not to copy.</b> <c>SyncEntityType.ConnectionLogEntry</c> and
/// <c>CryptoSpec.AadResourceType.ConnectionLogEntry</c> deliberately differ, as every pair in this folder does, and the
/// two log kinds sit next to each other in both enums — so a copied cipher with one constant left behind
/// seals a connection record under the resource type for an activity record. That encrypts perfectly,
/// decrypts perfectly on the machine that wrote it, and violates docs/crypto.md everywhere else.
/// </para>
/// </remarks>
public static class ConnectionLogCipher
{
private const CryptoSpec.AadResourceType Resource = CryptoSpec.AadResourceType.ConnectionLogEntry;
/// <summary>Encrypts an entry.</summary>
/// <param name="entry">The entry. Must be valid for storage.</param>
/// <param name="vaultKey">The vault key, which the data key is wrapped under.</param>
/// <param name="entityId">The item id, which the AAD binds.</param>
/// <param name="keyGeneration">The vault's current key generation.</param>
/// <param name="itemVersion">The version this payload will hold once the server accepts it.</param>
public static EncryptedPayload Seal(
ConnectionLogSecret entry,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(entry);
ArgumentOutOfRangeException.ThrowIfLessThan(itemVersion, 1);
var plaintext = ConnectionLogSecretCodec.Encode(entry);
var dataKey = ItemKeys.CreateDataKey();
try
{
var dataKeyId = Guid.CreateVersion7();
var wrappedDataKey = ItemKeys.WrapDataKey(
dataKey, vaultKey, Resource, entityId, keyGeneration, (uint)itemVersion);
var envelope = ItemKeys.SealPayload(
dataKey, plaintext, Resource, entityId, dataKeyId, keyGeneration, (uint)itemVersion);
return new EncryptedPayload(
envelope, wrappedDataKey, dataKeyId, keyGeneration, CryptoSpec.CurrentAadVersion);
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
// Wiped like every other payload here. Nothing in a log entry is a credential, and what it does
// hold — which machines this person reaches, and when — is the aggregate the whole item is
// encrypted to keep, so leaving it in a pooled buffer would be an odd place to stop caring.
CryptographicOperations.ZeroMemory(plaintext);
}
}
/// <summary>Decrypts an entry.</summary>
/// <inheritdoc cref="HostCipher.TryOpen" path="/returns" />
public static ConnectionLogSecretDocument? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(payload);
if (itemVersion < 1 || payload.WrappedDataKey.Length == 0)
{
return null;
}
var dataKey = ItemKeys.TryUnwrapDataKey(
vaultKey,
payload.WrappedDataKey,
Resource,
entityId,
payload.KeyGeneration,
(uint)itemVersion);
if (dataKey is null)
{
return null;
}
try
{
var plaintext = ItemKeys.TryOpenPayload(
dataKey,
payload.Envelope,
Resource,
entityId,
payload.DataKeyId,
payload.KeyGeneration,
(uint)itemVersion);
if (plaintext is null)
{
return null;
}
try
{
return ConnectionLogSecretCodec.TryDecode(plaintext, out var document) ? document : null;
}
finally
{
CryptographicOperations.ZeroMemory(plaintext);
}
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
}
}
}
@@ -18,10 +18,14 @@ namespace DodoSSH.Client.Sync;
/// interface reads a listing once per reload rather than holding one open.
/// </para>
/// </remarks>
public sealed class CredentialRepository(ItemStore items, OutboxStore outbox, VaultKeyring keyring)
public sealed class CredentialRepository(
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring,
IActivityLogSink? activity = null)
{
private readonly VaultItemRepository<CredentialSecret> credentials =
new(CredentialKind.Instance, items, outbox, keyring);
new(CredentialKind.Instance, items, outbox, keyring, activity);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<CredentialSecret>> ListAsync(
+130
View File
@@ -0,0 +1,130 @@
using System.Security.Cryptography;
using DodoSSH.Client.Domain;
using DodoSSH.Contracts;
using DodoSSH.Crypto;
namespace DodoSSH.Client.Sync;
/// <summary>
/// Turns a host group into an item payload and back.
/// </summary>
/// <remarks>
/// <para>
/// Mirrors <see cref="KnownHostKeyCipher"/> exactly, including the rule that a payload is sealed at the
/// version the server <em>will</em> assign rather than the one it replaces — see <see cref="SyncVersions"/>.
/// </para>
/// <para>
/// <b>The resource type is the one thing not to copy.</b> <c>SyncEntityType.HostGroup</c> is 4 and
/// <c>CryptoSpec.AadResourceType.HostGroup</c> is 7, because the crypto enum carries None, User, Device and
/// Vault ahead of the item types. Casting one to the other would seal a group under the resource type for a
/// <em>host</em> — which encrypts perfectly, decrypts perfectly on the machine that wrote it, and is a
/// specification violation nothing would notice until an interoperating client refused the item.
/// </para>
/// </remarks>
public static class HostGroupCipher
{
private const CryptoSpec.AadResourceType Resource = CryptoSpec.AadResourceType.HostGroup;
/// <summary>Encrypts a group.</summary>
/// <param name="group">The group. Must be valid for storage.</param>
/// <param name="vaultKey">The vault key, which the data key is wrapped under.</param>
/// <param name="entityId">The item id, which the AAD binds.</param>
/// <param name="keyGeneration">The vault's current key generation.</param>
/// <param name="itemVersion">The version this payload will hold once the server accepts it.</param>
public static EncryptedPayload Seal(
HostGroupSecret group,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(group);
ArgumentOutOfRangeException.ThrowIfLessThan(itemVersion, 1);
var plaintext = HostGroupSecretCodec.Encode(group);
var dataKey = ItemKeys.CreateDataKey();
try
{
var dataKeyId = Guid.CreateVersion7();
var wrappedDataKey = ItemKeys.WrapDataKey(
dataKey, vaultKey, Resource, entityId, keyGeneration, (uint)itemVersion);
var envelope = ItemKeys.SealPayload(
dataKey, plaintext, Resource, entityId, dataKeyId, keyGeneration, (uint)itemVersion);
return new EncryptedPayload(
envelope, wrappedDataKey, dataKeyId, keyGeneration, CryptoSpec.CurrentAadVersion);
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
// Wiped like every other payload in this folder, and here for the smallest reason of all: the
// buffer holds one name somebody chose for a folder. It is wiped anyway, because the rule this
// folder follows is that plaintext does not outlive the call that made it, and an exception for
// the case that seems harmless is how the rule stops being one.
CryptographicOperations.ZeroMemory(plaintext);
}
}
/// <summary>Decrypts a group.</summary>
/// <inheritdoc cref="HostCipher.TryOpen" path="/returns" />
public static HostGroupSecretDocument? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(payload);
if (itemVersion < 1 || payload.WrappedDataKey.Length == 0)
{
return null;
}
var dataKey = ItemKeys.TryUnwrapDataKey(
vaultKey,
payload.WrappedDataKey,
Resource,
entityId,
payload.KeyGeneration,
(uint)itemVersion);
if (dataKey is null)
{
return null;
}
try
{
var plaintext = ItemKeys.TryOpenPayload(
dataKey,
payload.Envelope,
Resource,
entityId,
payload.DataKeyId,
payload.KeyGeneration,
(uint)itemVersion);
if (plaintext is null)
{
return null;
}
try
{
return HostGroupSecretCodec.TryDecode(plaintext, out var document) ? document : null;
}
finally
{
CryptographicOperations.ZeroMemory(plaintext);
}
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
}
}
}
@@ -0,0 +1,54 @@
using DodoSSH.Client.Domain;
using DodoSSH.Client.Storage;
namespace DodoSSH.Client.Sync;
/// <summary>
/// The groups in this vault, decrypted, with unpushed local changes laid over them.
/// </summary>
/// <remarks>
/// <para>
/// The fifth facade over the same generic repository, and like the fourth it needed no new sync logic at all.
/// </para>
/// <para>
/// <b>Deleting a group does not touch the hosts in it.</b> There is deliberately no <c>DeleteAsync</c>
/// overload that unfiles its members: one user action would become N host writes, N outbox rows and N chances
/// to merge against an edit nobody made, and the group's own tombstone can still lose a merge — by which time
/// the membership it was clearing is gone. Hosts left holding a dangling id fall under the ungrouped heading,
/// which is where the interface handles it. See <see cref="HostSecret.GroupId"/>.
/// </para>
/// </remarks>
public sealed class HostGroupRepository(
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring,
IActivityLogSink? activity = null)
{
private readonly VaultItemRepository<HostGroupSecret> groups =
new(HostGroupKind.Instance, items, outbox, keyring, activity);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<HostGroupSecret>> ListAsync(
Guid vaultId,
CancellationToken cancellationToken) =>
groups.ListAsync(vaultId, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
public Task<Guid> CreateAsync(
Guid vaultId,
HostGroupSecret group,
CancellationToken cancellationToken) =>
groups.CreateAsync(vaultId, group, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.UpdateAsync" />
public Task UpdateAsync(
Guid vaultId,
Guid entityId,
HostGroupSecret group,
CancellationToken cancellationToken) =>
groups.UpdateAsync(vaultId, entityId, group, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.DeleteAsync" />
public Task DeleteAsync(Guid vaultId, Guid entityId, CancellationToken cancellationToken) =>
groups.DeleteAsync(vaultId, entityId, cancellationToken);
}
+6 -2
View File
@@ -13,10 +13,14 @@ namespace DodoSSH.Client.Sync;
/// generic is internal to this assembly — exposing it would make the encoding and merge of every item
/// type part of the public surface for the sake of a constructor argument.
/// </remarks>
public sealed class HostRepository(ItemStore items, OutboxStore outbox, VaultKeyring keyring)
public sealed class HostRepository(
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring,
IActivityLogSink? activity = null)
{
private readonly VaultItemRepository<HostSecret> hosts =
new(HostKind.Instance, items, outbox, keyring);
new(HostKind.Instance, items, outbox, keyring, activity);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<HostSecret>> ListAsync(Guid vaultId, CancellationToken cancellationToken) =>
@@ -0,0 +1,64 @@
using DodoSSH.Client.Domain;
using DodoSSH.Contracts;
namespace DodoSSH.Client.Sync;
/// <summary>
/// Somewhere to record that a keychain item was created, changed or deleted.
/// </summary>
/// <remarks>
/// <para>
/// <b>Hooked into <see cref="VaultItemRepository{TSecret}"/> rather than into the view models.</b> That
/// repository is the single generic funnel every kind's create, update and delete goes through, so one
/// write site covers all of them and picks up a new kind for free. Hooking the view models instead would
/// miss <c>VaultKnownHostStore</c>, which writes pins programmatically at connect time and never touches a
/// screen — and those are exactly the writes an audit trail must not be blind to.
/// </para>
/// <para>
/// Three rules govern the call, and they are properties of where it sits rather than of what it does:
/// </para>
/// <list type="number">
/// <item>
/// <b>After the outbox queue, never before.</b> A crash between the two loses an advisory line; the reverse
/// records a change that never happened.
/// </item>
/// <item>
/// <b>Every exception swallowed by the implementation.</b> A failing log write must never fail a save — the
/// entire point of the outbox is that saving works offline and cannot be refused.
/// </item>
/// <item>
/// <b>Not in a transaction with the outbox</b>, or a log failure rolls back a change the user made.
/// </item>
/// </list>
/// <para>
/// Note the deliberate asymmetry with the outbox itself, because it reads as a discrepancy otherwise: the
/// outbox <em>coalesces</em> two edits of one item into a single pending row, and this does not — two edits
/// are two lines. The outbox describes what still has to be sent; this describes what somebody did.
/// </para>
/// </remarks>
public interface IActivityLogSink
{
/// <summary>Records one write.</summary>
/// <param name="vaultId">Which vault it happened in.</param>
/// <param name="kind">Which sort of item, as the wire contract names it.</param>
/// <param name="entityId">The item.</param>
/// <param name="label">What the item was called at the time.</param>
/// <param name="operation">What was done.</param>
/// <param name="changedFields">
/// The names of the fields that differ, and never their values. Empty for a create and a delete, and
/// also when the previous version could not be read — which is why an empty list must not be taken to
/// mean nothing changed.
/// </param>
/// <remarks>
/// Returns <see langword="void"/> by contract, for the reason <c>IConnectionLogSink</c> does: the caller
/// is a save the user is waiting on, and an encrypt-and-write on that path would put the cost of the log
/// into every keystroke that reaches a Save button.
/// </remarks>
void Record(
Guid vaultId,
SyncEntityType kind,
Guid entityId,
string label,
ActivityOperation operation,
IReadOnlyList<string> changedFields);
}
+557
View File
@@ -1,6 +1,7 @@
using DodoSSH.Client.Domain;
using DodoSSH.Client.Storage;
using DodoSSH.Contracts;
using static DodoSSH.Client.Sync.FieldChange;
namespace DodoSSH.Client.Sync;
@@ -85,6 +86,35 @@ internal interface IItemKind<TSecret>
/// <summary>Merges two divergent versions against the version they both started from.</summary>
MergedItem<TSecret> Merge(TSecret ancestor, TSecret local, TSecret remote);
/// <summary>
/// The names of the fields that differ between two versions of an item.
/// </summary>
/// <remarks>
/// <para>
/// For the activity log, which records what changed and never what it changed to. Written per kind
/// rather than derived by reflection, for two reasons: this project's serialisation is source-generated
/// precisely to keep reflection out of it, and the names here are read by a person — so each kind gets
/// to say "Passphrase" rather than whatever a property happens to be called.
/// </para>
/// <para>
/// <b>Never a value.</b> A log that recorded an old password would be a plaintext credential store with
/// a vault drawn around it; see ADR 0006, which imposes the same rule on the server's own detail column.
/// </para>
/// </remarks>
IReadOnlyList<string> Changes(TSecret before, TSecret after);
/// <summary>
/// Whether writing one of these is worth a line in the activity log.
/// </summary>
/// <remarks>
/// False for the log kinds themselves, and that is not a preference: the activity hook sits in the one
/// generic repository every kind goes through, so a log entry that logged itself would produce an entry
/// per entry, for ever. It is stated per kind rather than special-cased at the call site so that a
/// future kind with the same shape — anything written by the machine rather than by a person — cannot
/// re-enter the loop by being forgotten.
/// </remarks>
bool IsAudited => true;
/// <summary>The same item under a new name, for a resurrection.</summary>
TSecret Relabel(TSecret secret, string label);
}
@@ -120,6 +150,23 @@ internal static class ItemKinds
(SyncEntityType.KnownHostKey, static (outbox, conflicts, keyring) =>
new ItemReconciler<KnownHostSecret>(KnownHostKeyKind.Instance, outbox, conflicts, keyring)),
(SyncEntityType.HostGroup, static (outbox, conflicts, keyring) =>
new ItemReconciler<HostGroupSecret>(HostGroupKind.Instance, outbox, conflicts, keyring)),
(SyncEntityType.Snippet, static (outbox, conflicts, keyring) =>
new ItemReconciler<SnippetSecret>(SnippetKind.Instance, outbox, conflicts, keyring)),
(SyncEntityType.ConnectionLogEntry, static (outbox, conflicts, keyring) =>
new ItemReconciler<ConnectionLogSecret>(
ConnectionLogEntryKind.Instance, outbox, conflicts, keyring)),
(SyncEntityType.ActivityLogEntry, static (outbox, conflicts, keyring) =>
new ItemReconciler<ActivityLogSecret>(
ActivityLogEntryKind.Instance, outbox, conflicts, keyring)),
(SyncEntityType.ObjectStore, static (outbox, conflicts, keyring) =>
new ItemReconciler<ObjectStoreSecret>(ObjectStoreKind.Instance, outbox, conflicts, keyring)),
];
/// <summary>The types to ask the server for, in a fixed order.</summary>
@@ -141,6 +188,24 @@ internal static class ItemKinds
entry => entry.Create(outbox, conflicts, keyring));
}
/// <summary>What the per-kind field comparisons share.</summary>
/// <remarks>
/// One line per field at each call site, which is the point: the alternative was reflection, and this
/// project keeps reflection out of its serialisation on purpose. Comparison is <see cref="object.Equals(object)"/>
/// on the values, which is why the collection-shaped fields on a host are types with structural equality —
/// <c>JumpChain</c> and <c>HostOptions</c> — rather than plain lists.
/// </remarks>
internal static class FieldChange
{
internal static void Note<T>(List<string> changed, string name, T before, T after)
{
if (!EqualityComparer<T>.Default.Equals(before, after))
{
changed.Add(name);
}
}
}
/// <summary>Hosts.</summary>
internal sealed class HostKind : IItemKind<HostSecret>
{
@@ -184,6 +249,29 @@ internal sealed class HostKind : IItemKind<HostSecret>
return new MergedItem<HostSecret>(merged.Merged, merged.Conflicts);
}
/// <inheritdoc />
public IReadOnlyList<string> Changes(HostSecret before, HostSecret after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var changed = new List<string>();
Note(changed, "Name", before.Label, after.Label);
Note(changed, "Hostname", before.Hostname, after.Hostname);
Note(changed, "Port", before.Port, after.Port);
Note(changed, "Username", before.Username, after.Username);
Note(changed, "Notes", before.Notes, after.Notes);
Note(changed, "Jump chain", before.JumpHostIds, after.JumpHostIds);
Note(changed, "Options", before.Options, after.Options);
Note(changed, "Relay", before.RelayEnabled, after.RelayEnabled);
Note(changed, "SSH key", before.SshKeyId, after.SshKeyId);
Note(changed, "Credential", before.CredentialId, after.CredentialId);
Note(changed, "Group", before.GroupId, after.GroupId);
return changed;
}
/// <inheritdoc />
public HostSecret Relabel(HostSecret secret, string label)
{
@@ -247,6 +335,27 @@ internal sealed class SshKeyKind : IItemKind<SshKeySecret>
return new MergedItem<SshKeySecret>(merged.Merged, merged.Conflicts);
}
/// <remarks>
/// The private key is compared and never reported by value, which is the whole rule. "Private key"
/// appearing in a log is the fact somebody needs; the key itself is what nobody does.
/// </remarks>
/// <inheritdoc />
public IReadOnlyList<string> Changes(SshKeySecret before, SshKeySecret after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var changed = new List<string>();
Note(changed, "Name", before.Label, after.Label);
Note(changed, "Private key", before.PrivateKeyPem, after.PrivateKeyPem);
Note(changed, "Passphrase", before.Passphrase, after.Passphrase);
Note(changed, "Public key", before.PublicKey, after.PublicKey);
Note(changed, "Notes", before.Notes, after.Notes);
return changed;
}
/// <inheritdoc />
public SshKeySecret Relabel(SshKeySecret secret, string label)
{
@@ -312,6 +421,22 @@ internal sealed class CredentialKind : IItemKind<CredentialSecret>
return new MergedItem<CredentialSecret>(merged.Merged, merged.Conflicts);
}
/// <inheritdoc />
public IReadOnlyList<string> Changes(CredentialSecret before, CredentialSecret after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var changed = new List<string>();
Note(changed, "Name", before.Label, after.Label);
Note(changed, "Password", before.Password, after.Password);
Note(changed, "Username", before.Username, after.Username);
Note(changed, "Notes", before.Notes, after.Notes);
return changed;
}
/// <inheritdoc />
public CredentialSecret Relabel(CredentialSecret secret, string label)
{
@@ -397,6 +522,28 @@ internal sealed class KnownHostKeyKind : IItemKind<KnownHostSecret>
/// the pin is about a different host. The resurrected item still gets its own id and still produces a
/// conflict notice, so the event is visible — the notice simply names the pin the same way twice.
/// </remarks>
/// <remarks>
/// In practice only the fingerprint can change: the store rewrites one or creates a new item, and never
/// re-addresses an existing pin. The other three are compared anyway, because a payload from elsewhere
/// is untrusted input and a silently unreported change to what a pin is <em>about</em> is the one thing
/// an audit trail must not miss.
/// </remarks>
/// <inheritdoc />
public IReadOnlyList<string> Changes(KnownHostSecret before, KnownHostSecret after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var changed = new List<string>();
Note(changed, "Host", before.Host, after.Host);
Note(changed, "Port", before.Port, after.Port);
Note(changed, "Algorithm", before.Algorithm, after.Algorithm);
Note(changed, "Fingerprint", before.Fingerprint, after.Fingerprint);
return changed;
}
/// <inheritdoc />
public KnownHostSecret Relabel(KnownHostSecret secret, string label)
{
@@ -405,3 +552,413 @@ internal sealed class KnownHostKeyKind : IItemKind<KnownHostSecret>
return secret;
}
}
/// <summary>Host groups.</summary>
internal sealed class HostGroupKind : IItemKind<HostGroupSecret>
{
internal static HostGroupKind Instance { get; } = new();
/// <inheritdoc />
public SyncEntityType EntityType => SyncEntityType.HostGroup;
/// <inheritdoc />
public string Noun => "group";
/// <inheritdoc />
public OpenedItem<HostGroupSecret>? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
var document = HostGroupCipher.TryOpen(payload, vaultKey, entityId, itemVersion);
return document is null
? null
: new OpenedItem<HostGroupSecret>(document.Group, document.IsReadOnly);
}
/// <inheritdoc />
public EncryptedPayload Seal(
HostGroupSecret secret,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion) =>
HostGroupCipher.Seal(secret, vaultKey, entityId, keyGeneration, itemVersion);
/// <summary>
/// Nothing, and the field it declines to send is the one named after this type.
/// </summary>
/// <remarks>
/// <c>SyncPlaintextFields.GroupId</c> exists, the server had a column for it, and no client ever wrote
/// one. What it would have handed over is a clustering of the estate — which machines this user files
/// together — for a column nothing in the product reads. The server now refuses the field outright, on
/// hosts as well as here. See ADR 0004.
/// </remarks>
/// <inheritdoc />
public SyncPlaintextFields? Fields(HostGroupSecret secret) => null;
/// <inheritdoc />
public MergedItem<HostGroupSecret> Merge(
HostGroupSecret ancestor,
HostGroupSecret local,
HostGroupSecret remote)
{
var merged = HostGroupSecretMerge.Merge(ancestor, local, remote);
return new MergedItem<HostGroupSecret>(merged.Merged, merged.Conflicts);
}
/// <inheritdoc />
public IReadOnlyList<string> Changes(HostGroupSecret before, HostGroupSecret after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var changed = new List<string>();
Note(changed, "Name", before.Label, after.Label);
return changed;
}
/// <inheritdoc />
public HostGroupSecret Relabel(HostGroupSecret secret, string label)
{
ArgumentNullException.ThrowIfNull(secret);
return secret with { Label = label };
}
}
/// <summary>Snippets.</summary>
internal sealed class SnippetKind : IItemKind<SnippetSecret>
{
internal static SnippetKind Instance { get; } = new();
/// <inheritdoc />
public SyncEntityType EntityType => SyncEntityType.Snippet;
/// <inheritdoc />
public string Noun => "snippet";
/// <inheritdoc />
public OpenedItem<SnippetSecret>? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
var document = SnippetCipher.TryOpen(payload, vaultKey, entityId, itemVersion);
return document is null
? null
: new OpenedItem<SnippetSecret>(document.Snippet, document.IsReadOnly);
}
/// <inheritdoc />
public EncryptedPayload Seal(
SnippetSecret secret,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion) =>
SnippetCipher.Seal(secret, vaultKey, entityId, keyGeneration, itemVersion);
/// <summary>
/// Nothing. A command is a description of the estate as precise as a hostname is.
/// </summary>
/// <inheritdoc />
public SyncPlaintextFields? Fields(SnippetSecret secret) => null;
/// <inheritdoc />
public MergedItem<SnippetSecret> Merge(
SnippetSecret ancestor,
SnippetSecret local,
SnippetSecret remote)
{
var merged = SnippetSecretMerge.Merge(ancestor, local, remote);
return new MergedItem<SnippetSecret>(merged.Merged, merged.Conflicts);
}
/// <inheritdoc />
public IReadOnlyList<string> Changes(SnippetSecret before, SnippetSecret after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var changed = new List<string>();
Note(changed, "Name", before.Label, after.Label);
Note(changed, "Command", before.Command, after.Command);
Note(changed, "Notes", before.Notes, after.Notes);
// Named for what it means rather than after the property, because this is the line somebody
// reviewing a log actually needs to see: a snippet that has been turned into one that runs.
Note(changed, "Runs on insert", before.RunsOnInsert, after.RunsOnInsert);
return changed;
}
/// <inheritdoc />
public SnippetSecret Relabel(SnippetSecret secret, string label)
{
ArgumentNullException.ThrowIfNull(secret);
return secret with { Label = label };
}
}
/// <summary>Connection log entries.</summary>
internal sealed class ConnectionLogEntryKind : IItemKind<ConnectionLogSecret>
{
internal static ConnectionLogEntryKind Instance { get; } = new();
/// <inheritdoc />
public SyncEntityType EntityType => SyncEntityType.ConnectionLogEntry;
/// <summary>What to call one of these to a person.</summary>
/// <remarks>
/// "Log entry" and not "connection". A user told that "this connection could not be decrypted" would go
/// looking at a machine they cannot reach; the item is the <em>record</em> of one, and the noun has to
/// say so.
/// </remarks>
public string Noun => "log entry";
/// <inheritdoc />
public OpenedItem<ConnectionLogSecret>? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
var document = ConnectionLogCipher.TryOpen(payload, vaultKey, entityId, itemVersion);
return document is null
? null
: new OpenedItem<ConnectionLogSecret>(document.Entry, document.IsReadOnly);
}
/// <inheritdoc />
public EncryptedPayload Seal(
ConnectionLogSecret secret,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion) =>
ConnectionLogCipher.Seal(secret, vaultKey, entityId, keyGeneration, itemVersion);
/// <summary>
/// Nothing, and here the temptation is a timestamp rather than an address.
/// </summary>
/// <remarks>
/// A plaintext <c>startedAt</c> would let the server order and prune a log without a client's help, which
/// is genuinely useful and is exactly the wrong trade: a timestamp column on this table is a record of
/// when each user works, assembled for free. The client sorts and prunes its own log. See ADR 0004.
/// </remarks>
/// <inheritdoc />
public SyncPlaintextFields? Fields(ConnectionLogSecret secret) => null;
/// <inheritdoc />
public MergedItem<ConnectionLogSecret> Merge(
ConnectionLogSecret ancestor,
ConnectionLogSecret local,
ConnectionLogSecret remote)
{
var merged = ConnectionLogSecretMerge.Merge(ancestor, local, remote);
return new MergedItem<ConnectionLogSecret>(merged.Merged, merged.Conflicts);
}
/// <summary>Never asked, because a log entry is never audited or updated.</summary>
/// <inheritdoc />
public IReadOnlyList<string> Changes(ConnectionLogSecret before, ConnectionLogSecret after) => [];
/// <summary>
/// False, and this is the guard that stops the log logging itself.
/// </summary>
/// <remarks>
/// The activity hook lives in the one generic repository every kind writes through, so without this a
/// connection entry would produce an activity entry, which would produce another, without end. It is a
/// property of the kind rather than a check at the call site so that the next machine-written kind
/// cannot re-enter the loop by being overlooked.
/// </remarks>
public bool IsAudited => false;
/// <summary>
/// The entry unchanged, because an entry has no name of its own to change.
/// </summary>
/// <remarks>
/// As for a pinned host key: the label is derived from what the entry records, so renaming it would mean
/// claiming the connection was to a different machine. A resurrected entry still gets its own id and
/// still produces a conflict notice, so the event stays visible.
/// </remarks>
/// <inheritdoc />
public ConnectionLogSecret Relabel(ConnectionLogSecret secret, string label)
{
ArgumentNullException.ThrowIfNull(secret);
return secret;
}
}
/// <summary>Activity log entries.</summary>
internal sealed class ActivityLogEntryKind : IItemKind<ActivityLogSecret>
{
internal static ActivityLogEntryKind Instance { get; } = new();
/// <inheritdoc />
public SyncEntityType EntityType => SyncEntityType.ActivityLogEntry;
/// <inheritdoc />
public string Noun => "log entry";
/// <inheritdoc />
public OpenedItem<ActivityLogSecret>? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
var document = ActivityLogCipher.TryOpen(payload, vaultKey, entityId, itemVersion);
return document is null
? null
: new OpenedItem<ActivityLogSecret>(document.Entry, document.IsReadOnly);
}
/// <inheritdoc />
public EncryptedPayload Seal(
ActivityLogSecret secret,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion) =>
ActivityLogCipher.Seal(secret, vaultKey, entityId, keyGeneration, itemVersion);
/// <summary>
/// Nothing. <c>SyncPlaintextFields.Kind</c> would fit and is refused for it.
/// </summary>
/// <inheritdoc />
public SyncPlaintextFields? Fields(ActivityLogSecret secret) => null;
/// <inheritdoc />
public MergedItem<ActivityLogSecret> Merge(
ActivityLogSecret ancestor,
ActivityLogSecret local,
ActivityLogSecret remote)
{
var merged = ActivityLogSecretMerge.Merge(ancestor, local, remote);
return new MergedItem<ActivityLogSecret>(merged.Merged, merged.Conflicts);
}
/// <inheritdoc cref="ConnectionLogEntryKind.Changes" />
public IReadOnlyList<string> Changes(ActivityLogSecret before, ActivityLogSecret after) => [];
/// <inheritdoc cref="ConnectionLogEntryKind.IsAudited" />
public bool IsAudited => false;
/// <inheritdoc cref="ConnectionLogEntryKind.Relabel" />
public ActivityLogSecret Relabel(ActivityLogSecret secret, string label)
{
ArgumentNullException.ThrowIfNull(secret);
return secret;
}
}
/// <summary>Buckets.</summary>
internal sealed class ObjectStoreKind : IItemKind<ObjectStoreSecret>
{
internal static ObjectStoreKind Instance { get; } = new();
/// <inheritdoc />
public SyncEntityType EntityType => SyncEntityType.ObjectStore;
/// <summary>What to call one of these to a person.</summary>
/// <remarks>
/// "Bucket" rather than "object store", because that is the word on the screen and in every service's own
/// documentation. The type is named for the protocol; the noun is named for what people say.
/// </remarks>
public string Noun => "bucket";
/// <inheritdoc />
public OpenedItem<ObjectStoreSecret>? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
var document = ObjectStoreCipher.TryOpen(payload, vaultKey, entityId, itemVersion);
return document is null
? null
: new OpenedItem<ObjectStoreSecret>(document.Store, document.IsReadOnly);
}
/// <inheritdoc />
public EncryptedPayload Seal(
ObjectStoreSecret secret,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion) =>
ObjectStoreCipher.Seal(secret, vaultKey, entityId, keyGeneration, itemVersion);
/// <summary>
/// Nothing, and for this type there was never a candidate.
/// </summary>
/// <remarks>
/// The endpoint is the field somebody might reach for, and it is the one that must not go: for everybody
/// self-hosting it is an address on their own network, which is exactly what the host table only holds in
/// the clear when the relay cannot work without it. Nothing on the server dials a bucket.
/// </remarks>
/// <inheritdoc />
public SyncPlaintextFields? Fields(ObjectStoreSecret secret) => null;
/// <inheritdoc />
public MergedItem<ObjectStoreSecret> Merge(
ObjectStoreSecret ancestor,
ObjectStoreSecret local,
ObjectStoreSecret remote)
{
var merged = ObjectStoreSecretMerge.Merge(ancestor, local, remote);
return new MergedItem<ObjectStoreSecret>(merged.Merged, merged.Conflicts);
}
/// <remarks>
/// The secret access key is compared and never reported by value, which is the rule every credential-like
/// field in this file follows. The access key id is shown: it is an identifier, not a secret.
/// </remarks>
/// <inheritdoc />
public IReadOnlyList<string> Changes(ObjectStoreSecret before, ObjectStoreSecret after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var changed = new List<string>();
Note(changed, "Name", before.Label, after.Label);
Note(changed, "Bucket", before.Bucket, after.Bucket);
Note(changed, "Access key id", before.AccessKeyId, after.AccessKeyId);
Note(changed, "Secret access key", before.SecretAccessKey, after.SecretAccessKey);
Note(changed, "Region", before.Region, after.Region);
Note(changed, "Endpoint", before.Endpoint, after.Endpoint);
Note(changed, "Path-style addressing", before.UsePathStyle, after.UsePathStyle);
Note(changed, "Notes", before.Notes, after.Notes);
return changed;
}
/// <inheritdoc />
public ObjectStoreSecret Relabel(ObjectStoreSecret secret, string label)
{
ArgumentNullException.ThrowIfNull(secret);
return secret with { Label = label };
}
}
@@ -19,10 +19,14 @@ namespace DodoSSH.Client.Sync;
/// the handshake from an in-memory snapshot.
/// </para>
/// </remarks>
public sealed class KnownHostRepository(ItemStore items, OutboxStore outbox, VaultKeyring keyring)
public sealed class KnownHostRepository(
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring,
IActivityLogSink? activity = null)
{
private readonly VaultItemRepository<KnownHostSecret> knownHosts =
new(KnownHostKeyKind.Instance, items, outbox, keyring);
new(KnownHostKeyKind.Instance, items, outbox, keyring, activity);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<KnownHostSecret>> ListAsync(
@@ -0,0 +1,68 @@
using DodoSSH.Client.Domain;
using DodoSSH.Client.Storage;
namespace DodoSSH.Client.Sync;
/// <summary>
/// The connections this vault has recorded, decrypted, with unpushed local entries laid over them.
/// </summary>
/// <remarks>
/// <para>
/// The seventh facade over the same generic repository, and the first whose <c>UpdateAsync</c> is missing on
/// purpose. A connection log entry is written once, at close, and never edited — see
/// <c>VaultConnectionLogEntry</c> for why that is what makes a synced log tractable at all — so an update
/// method here would be an invitation to break the property the whole design rests on.
/// </para>
/// <para>
/// <see cref="DeleteAsync"/> stays, because retention needs it. It is the only thing that deletes an entry.
/// </para>
/// </remarks>
public sealed class ConnectionLogRepository(ItemStore items, OutboxStore outbox, VaultKeyring keyring)
{
private readonly VaultItemRepository<ConnectionLogSecret> entries =
new(ConnectionLogEntryKind.Instance, items, outbox, keyring);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<ConnectionLogSecret>> ListAsync(
Guid vaultId,
CancellationToken cancellationToken) =>
entries.ListAsync(vaultId, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
public Task<Guid> CreateAsync(
Guid vaultId,
ConnectionLogSecret entry,
CancellationToken cancellationToken) =>
entries.CreateAsync(vaultId, entry, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.DeleteAsync" />
public Task DeleteAsync(Guid vaultId, Guid entityId, CancellationToken cancellationToken) =>
entries.DeleteAsync(vaultId, entityId, cancellationToken);
}
/// <summary>
/// The keychain changes this vault has recorded, decrypted, with unpushed local entries laid over them.
/// </summary>
/// <inheritdoc cref="ConnectionLogRepository" path="/remarks" />
public sealed class ActivityLogRepository(ItemStore items, OutboxStore outbox, VaultKeyring keyring)
{
private readonly VaultItemRepository<ActivityLogSecret> entries =
new(ActivityLogEntryKind.Instance, items, outbox, keyring);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<ActivityLogSecret>> ListAsync(
Guid vaultId,
CancellationToken cancellationToken) =>
entries.ListAsync(vaultId, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
public Task<Guid> CreateAsync(
Guid vaultId,
ActivityLogSecret entry,
CancellationToken cancellationToken) =>
entries.CreateAsync(vaultId, entry, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.DeleteAsync" />
public Task DeleteAsync(Guid vaultId, Guid entityId, CancellationToken cancellationToken) =>
entries.DeleteAsync(vaultId, entityId, cancellationToken);
}
@@ -0,0 +1,129 @@
using System.Security.Cryptography;
using DodoSSH.Client.Domain;
using DodoSSH.Contracts;
using DodoSSH.Crypto;
namespace DodoSSH.Client.Sync;
/// <summary>
/// Turns a bucket into an item payload and back.
/// </summary>
/// <remarks>
/// <para>
/// Mirrors <see cref="CredentialCipher"/> exactly, including the rule that a payload is sealed at the version
/// the server <em>will</em> assign rather than the one it replaces — see <see cref="SyncVersions"/>.
/// </para>
/// <para>
/// <b>The resource type is the one thing not to copy.</b> <c>SyncEntityType.ObjectStore</c> is 13 and
/// <c>CryptoSpec.AadResourceType.ObjectStore</c> is 16, because the crypto enum carries None, User, Device
/// and Vault ahead of the item types and then closed a hole at 12 and 13. Casting one to the other would
/// seal a bucket's keys under the resource type for a <em>host-to-credential association</em> — which
/// encrypts perfectly, decrypts perfectly on the machine that wrote it, and violates docs/crypto.md
/// everywhere else.
/// </para>
/// </remarks>
public static class ObjectStoreCipher
{
private const CryptoSpec.AadResourceType Resource = CryptoSpec.AadResourceType.ObjectStore;
/// <summary>Encrypts a bucket.</summary>
/// <param name="store">The bucket. Must be valid for storage.</param>
/// <param name="vaultKey">The vault key, which the data key is wrapped under.</param>
/// <param name="entityId">The item id, which the AAD binds.</param>
/// <param name="keyGeneration">The vault's current key generation.</param>
/// <param name="itemVersion">The version this payload will hold once the server accepts it.</param>
public static EncryptedPayload Seal(
ObjectStoreSecret store,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(store);
ArgumentOutOfRangeException.ThrowIfLessThan(itemVersion, 1);
var plaintext = ObjectStoreSecretCodec.Encode(store);
var dataKey = ItemKeys.CreateDataKey();
try
{
var dataKeyId = Guid.CreateVersion7();
var wrappedDataKey = ItemKeys.WrapDataKey(
dataKey, vaultKey, Resource, entityId, keyGeneration, (uint)itemVersion);
var envelope = ItemKeys.SealPayload(
dataKey, plaintext, Resource, entityId, dataKeyId, keyGeneration, (uint)itemVersion);
return new EncryptedPayload(
envelope, wrappedDataKey, dataKeyId, keyGeneration, CryptoSpec.CurrentAadVersion);
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
// The same reason a credential's buffer is wiped: this one holds a secret access key, which is a
// password by another name and is live on the service it belongs to.
CryptographicOperations.ZeroMemory(plaintext);
}
}
/// <summary>Decrypts a bucket.</summary>
/// <inheritdoc cref="HostCipher.TryOpen" path="/returns" />
public static ObjectStoreSecretDocument? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(payload);
if (itemVersion < 1 || payload.WrappedDataKey.Length == 0)
{
return null;
}
var dataKey = ItemKeys.TryUnwrapDataKey(
vaultKey,
payload.WrappedDataKey,
Resource,
entityId,
payload.KeyGeneration,
(uint)itemVersion);
if (dataKey is null)
{
return null;
}
try
{
var plaintext = ItemKeys.TryOpenPayload(
dataKey,
payload.Envelope,
Resource,
entityId,
payload.DataKeyId,
payload.KeyGeneration,
(uint)itemVersion);
if (plaintext is null)
{
return null;
}
try
{
return ObjectStoreSecretCodec.TryDecode(plaintext, out var document) ? document : null;
}
finally
{
CryptographicOperations.ZeroMemory(plaintext);
}
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
}
}
}
@@ -0,0 +1,47 @@
using DodoSSH.Client.Domain;
using DodoSSH.Client.Storage;
namespace DodoSSH.Client.Sync;
/// <summary>
/// The buckets in this vault, decrypted, with unpushed local changes laid over them.
/// </summary>
/// <remarks>
/// The eighth facade over the same generic repository, and the pattern has not needed a change since the
/// fourth — which is the point of the item-kind seam. Nothing here is on a transfer's data path: a bucket is
/// read when the file screen's picker is built, and the object-store client is constructed from the result.
/// </remarks>
public sealed class ObjectStoreRepository(
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring,
IActivityLogSink? activity = null)
{
private readonly VaultItemRepository<ObjectStoreSecret> stores =
new(ObjectStoreKind.Instance, items, outbox, keyring, activity);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<ObjectStoreSecret>> ListAsync(
Guid vaultId,
CancellationToken cancellationToken) =>
stores.ListAsync(vaultId, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
public Task<Guid> CreateAsync(
Guid vaultId,
ObjectStoreSecret store,
CancellationToken cancellationToken) =>
stores.CreateAsync(vaultId, store, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.UpdateAsync" />
public Task UpdateAsync(
Guid vaultId,
Guid entityId,
ObjectStoreSecret store,
CancellationToken cancellationToken) =>
stores.UpdateAsync(vaultId, entityId, store, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.DeleteAsync" />
public Task DeleteAsync(Guid vaultId, Guid entityId, CancellationToken cancellationToken) =>
stores.DeleteAsync(vaultId, entityId, cancellationToken);
}
+128
View File
@@ -0,0 +1,128 @@
using System.Security.Cryptography;
using DodoSSH.Client.Domain;
using DodoSSH.Contracts;
using DodoSSH.Crypto;
namespace DodoSSH.Client.Sync;
/// <summary>
/// Turns a snippet into an item payload and back.
/// </summary>
/// <remarks>
/// <para>
/// Mirrors <see cref="KnownHostKeyCipher"/> exactly, including the rule that a payload is sealed at the
/// version the server <em>will</em> assign rather than the one it replaces — see <see cref="SyncVersions"/>.
/// </para>
/// <para>
/// <b>The resource type is the one thing not to copy.</b> <c>SyncEntityType.Snippet</c> is 8 and
/// <c>CryptoSpec.AadResourceType.Snippet</c> is 9 — a difference of one, which is the most dangerous kind,
/// because a cast that is wrong by one still produces a defined value and seals the item under the resource
/// type for a <em>tag</em>. That round-trips on the machine that wrote it and violates docs/crypto.md
/// everywhere else.
/// </para>
/// </remarks>
public static class SnippetCipher
{
private const CryptoSpec.AadResourceType Resource = CryptoSpec.AadResourceType.Snippet;
/// <summary>Encrypts a snippet.</summary>
/// <param name="snippet">The snippet. Must be valid for storage.</param>
/// <param name="vaultKey">The vault key, which the data key is wrapped under.</param>
/// <param name="entityId">The item id, which the AAD binds.</param>
/// <param name="keyGeneration">The vault's current key generation.</param>
/// <param name="itemVersion">The version this payload will hold once the server accepts it.</param>
public static EncryptedPayload Seal(
SnippetSecret snippet,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
uint keyGeneration,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(snippet);
ArgumentOutOfRangeException.ThrowIfLessThan(itemVersion, 1);
var plaintext = SnippetSecretCodec.Encode(snippet);
var dataKey = ItemKeys.CreateDataKey();
try
{
var dataKeyId = Guid.CreateVersion7();
var wrappedDataKey = ItemKeys.WrapDataKey(
dataKey, vaultKey, Resource, entityId, keyGeneration, (uint)itemVersion);
var envelope = ItemKeys.SealPayload(
dataKey, plaintext, Resource, entityId, dataKeyId, keyGeneration, (uint)itemVersion);
return new EncryptedPayload(
envelope, wrappedDataKey, dataKeyId, keyGeneration, CryptoSpec.CurrentAadVersion);
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
// A snippet is not a credential, and it is closer to one than it looks: people paste tokens into
// commands, and the command that unlocks a service is worth as much as the password it carries.
CryptographicOperations.ZeroMemory(plaintext);
}
}
/// <summary>Decrypts a snippet.</summary>
/// <inheritdoc cref="HostCipher.TryOpen" path="/returns" />
public static SnippetSecretDocument? TryOpen(
EncryptedPayload payload,
ReadOnlySpan<byte> vaultKey,
Guid entityId,
int itemVersion)
{
ArgumentNullException.ThrowIfNull(payload);
if (itemVersion < 1 || payload.WrappedDataKey.Length == 0)
{
return null;
}
var dataKey = ItemKeys.TryUnwrapDataKey(
vaultKey,
payload.WrappedDataKey,
Resource,
entityId,
payload.KeyGeneration,
(uint)itemVersion);
if (dataKey is null)
{
return null;
}
try
{
var plaintext = ItemKeys.TryOpenPayload(
dataKey,
payload.Envelope,
Resource,
entityId,
payload.DataKeyId,
payload.KeyGeneration,
(uint)itemVersion);
if (plaintext is null)
{
return null;
}
try
{
return SnippetSecretCodec.TryDecode(plaintext, out var document) ? document : null;
}
finally
{
CryptographicOperations.ZeroMemory(plaintext);
}
}
finally
{
CryptographicOperations.ZeroMemory(dataKey);
}
}
}
@@ -0,0 +1,47 @@
using DodoSSH.Client.Domain;
using DodoSSH.Client.Storage;
namespace DodoSSH.Client.Sync;
/// <summary>
/// The snippets in this vault, decrypted, with unpushed local changes laid over them.
/// </summary>
/// <remarks>
/// The sixth facade over the same generic repository. Nothing here is on the terminal's write path: a snippet
/// is read when the screen that lists them opens, and inserting one hands text to the renderer rather than
/// coming back through the vault.
/// </remarks>
public sealed class SnippetRepository(
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring,
IActivityLogSink? activity = null)
{
private readonly VaultItemRepository<SnippetSecret> snippets =
new(SnippetKind.Instance, items, outbox, keyring, activity);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<SnippetSecret>> ListAsync(
Guid vaultId,
CancellationToken cancellationToken) =>
snippets.ListAsync(vaultId, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
public Task<Guid> CreateAsync(
Guid vaultId,
SnippetSecret snippet,
CancellationToken cancellationToken) =>
snippets.CreateAsync(vaultId, snippet, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.UpdateAsync" />
public Task UpdateAsync(
Guid vaultId,
Guid entityId,
SnippetSecret snippet,
CancellationToken cancellationToken) =>
snippets.UpdateAsync(vaultId, entityId, snippet, cancellationToken);
/// <inheritdoc cref="VaultItemRepository{TSecret}.DeleteAsync" />
public Task DeleteAsync(Guid vaultId, Guid entityId, CancellationToken cancellationToken) =>
snippets.DeleteAsync(vaultId, entityId, cancellationToken);
}
+6 -2
View File
@@ -20,10 +20,14 @@ namespace DodoSSH.Client.Sync;
/// where the decryption actually happens, which is here.
/// </para>
/// </remarks>
public sealed class SshKeyRepository(ItemStore items, OutboxStore outbox, VaultKeyring keyring)
public sealed class SshKeyRepository(
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring,
IActivityLogSink? activity = null)
{
private readonly VaultItemRepository<SshKeySecret> keys =
new(SshKeyKind.Instance, items, outbox, keyring);
new(SshKeyKind.Instance, items, outbox, keyring, activity);
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
public Task<ItemListing<SshKeySecret>> ListAsync(
+27
View File
@@ -158,6 +158,14 @@ public sealed class SyncEngine
{
await ApplyAsync(vaultId, change, report, cancellationToken).ConfigureAwait(false);
report.Pulled++;
// Counted apart for the same reason the pushed ones are: a machine reads back the log
// entries it just wrote, so a pass that "pulled five changes" may have carried nothing
// anybody did. See SyncReport.PulledItems.
if (IsLog(change.EntityType))
{
report.PulledLogEntries++;
}
}
var advanced = !string.Equals(state.Cursor, response.NextCursor, StringComparison.Ordinal);
@@ -188,6 +196,15 @@ public sealed class SyncEngine
/// for, so a rejection of <em>that</em> is a server this code cannot reason about and has to surface.
/// It is also what keeps the retry from looping — the restarted request sends no cursor.
/// </remarks>
/// <summary>Whether a change is one the machine wrote about itself rather than one somebody made.</summary>
/// <remarks>
/// Used only for reporting. Log entries sync exactly like every other item — they are pulled, pushed,
/// merged and stored by the same code — and this distinguishes them nowhere except in the two numbers a
/// person reads.
/// </remarks>
private static bool IsLog(SyncEntityType type) =>
type is SyncEntityType.ConnectionLogEntry or SyncEntityType.ActivityLogEntry;
private static bool WasTheCursorRefused(DodoSshApiException exception, string? cursor) =>
!string.IsNullOrEmpty(cursor)
&& string.Equals(exception.Code, ProblemCodes.InvalidCursor, StringComparison.Ordinal);
@@ -393,6 +410,16 @@ public sealed class SyncEngine
// what makes a retry after a timeout exactly-once rather than merely at-least-once.
await AcceptAsync(vaultId, operation, result, cancellationToken).ConfigureAwait(false);
report.Pushed++;
// Counted separately so the interface can stay quiet about a pass that carried nothing but
// log entries. Every user action now queues one, so without this the background pass would
// have something to announce after literally every save — and would overwrite the message
// the save itself had just put on the status line.
if (IsLog(operation.EntityType))
{
report.PushedLogEntries++;
}
return false;
case SyncOperationStatus.Conflict:
+33 -2
View File
@@ -97,11 +97,34 @@ public sealed record SyncReport(
bool RekeyRequired,
long ServerTimeSkewMs,
bool RoundsExhausted,
bool ResyncedFromStart)
bool ResyncedFromStart,
int PushedLogEntries = 0,
int PulledLogEntries = 0)
{
/// <summary>Whether anything happened that a user should be told about.</summary>
public bool NeedsAttention =>
Resurrected > 0 || DeletesAbandoned > 0 || Parked > 0 || Unreadable > 0 || RekeyRequired;
/// <summary>
/// Operations the server accepted that were somebody's own work rather than a log entry.
/// </summary>
/// <remarks>
/// The number a background pass decides whether to speak about. Every user action queues a log entry a
/// moment later, so a pass that reported on <see cref="Pushed"/> alone would have something to announce
/// after every save — and would overwrite the message the save had just written. Defaulted so that the
/// hundreds of existing constructions of this record go on meaning what they meant.
/// </remarks>
public int PushedItems => Pushed - PushedLogEntries;
/// <summary>
/// Changes received that were somebody's own work rather than a log entry.
/// </summary>
/// <remarks>
/// The other half of the same rule, and it needs saying because the case is not obvious: a machine pulls
/// back the log entries it has just pushed, so a pass immediately after a save reports a pull as well as
/// a push, and both are the machine talking about itself.
/// </remarks>
public int PulledItems => Pulled - PulledLogEntries;
}
/// <summary>Accumulates a <see cref="SyncReport"/> while a pass runs.</summary>
@@ -111,6 +134,12 @@ internal sealed class SyncReportBuilder(Guid vaultId)
internal int Pushed { get; set; }
/// <summary>How many of those were log entries rather than the user's own items.</summary>
internal int PushedLogEntries { get; set; }
/// <inheritdoc cref="PushedLogEntries" />
internal int PulledLogEntries { get; set; }
internal int Merged { get; set; }
internal int Resurrected { get; set; }
@@ -145,7 +174,9 @@ internal sealed class SyncReportBuilder(Guid vaultId)
RekeyRequired,
ServerTimeSkewMs,
RoundsExhausted,
ResyncedFromStart);
ResyncedFromStart,
PushedLogEntries,
PulledLogEntries);
}
/// <summary>The record written to the conflict log when a merge had to override something.</summary>
+117 -1
View File
@@ -63,9 +63,20 @@ internal sealed class VaultItemRepository<TSecret>(
IItemKind<TSecret> kind,
ItemStore items,
OutboxStore outbox,
VaultKeyring keyring)
VaultKeyring keyring,
IActivityLogSink? activity = null)
where TSecret : class, IVaultSecret
{
/// <summary>
/// Whether writes through this repository are worth recording.
/// </summary>
/// <remarks>
/// Asked once rather than at each call site, and false for the log kinds themselves — which is the guard
/// that stops the activity log producing an entry for every entry it writes, without end. See
/// <see cref="IItemKind{TSecret}.IsAudited"/>.
/// </remarks>
private bool IsAudited => activity is not null && kind.IsAudited;
/// <summary>Reads every item of this kind the user should see in a vault.</summary>
internal async Task<ItemListing<TSecret>> ListAsync(
Guid vaultId,
@@ -154,6 +165,14 @@ internal sealed class VaultItemRepository<TSecret>(
Ancestor: null),
cancellationToken).ConfigureAwait(false);
// After the queue, deliberately. A crash between the two loses one advisory line; the reverse order
// records an item that was never created.
if (IsAudited)
{
activity!.Record(
vaultId, kind.EntityType, entityId, secret.Label, ActivityOperation.Created, []);
}
return entityId;
}
@@ -188,6 +207,13 @@ internal sealed class VaultItemRepository<TSecret>(
var ancestor = pending?.Ancestor
?? await MirrorAncestorAsync(vaultId, entityId, cancellationToken).ConfigureAwait(false);
// Read before the queue overwrites it, and compared after. The version this decrypts at is the one
// the payload was sealed at, which is why the pending and mirror cases differ: a pending payload
// holds the version the server will assign, and a mirror row holds the one it has.
var before = IsAudited
? Open(vaultKey, entityId, pending, ancestor)
: null;
await outbox.QueueAsync(
new QueuedChange(
vaultId,
@@ -204,6 +230,19 @@ internal sealed class VaultItemRepository<TSecret>(
kind.Fields(secret),
ancestor),
cancellationToken).ConfigureAwait(false);
if (IsAudited)
{
// An empty list when the previous version could not be read, which is why nothing may take empty
// to mean "nothing changed" — it also means "we could not tell".
activity!.Record(
vaultId,
kind.EntityType,
entityId,
secret.Label,
ActivityOperation.Updated,
before is null ? [] : kind.Changes(before, secret));
}
}
/// <summary>
@@ -225,9 +264,20 @@ internal sealed class VaultItemRepository<TSecret>(
.FindAsync(vaultId, kind.EntityType, entityId, cancellationToken)
.ConfigureAwait(false);
// Read before either branch, because both of them destroy it — and a delete's line is the one that
// most needs a name, since the item it refers to is about to stop existing.
var label = IsAudited
? await LabelAsync(vaultId, entityId, pending, cancellationToken).ConfigureAwait(false)
: null;
if (pending is not null && NeverReachedTheServer(pending))
{
await outbox.CompleteAsync(pending.Sequence, cancellationToken).ConfigureAwait(false);
// Recorded even though nothing goes to the server. Somebody created an item and then removed it,
// which is two things they did — and a log that showed only the create would describe a keychain
// that does not exist.
Audit(vaultId, entityId, label);
return;
}
@@ -249,6 +299,72 @@ internal sealed class VaultItemRepository<TSecret>(
Fields: null,
ancestor),
cancellationToken).ConfigureAwait(false);
Audit(vaultId, entityId, label);
}
/// <summary>Records a delete, if this kind is audited at all.</summary>
private void Audit(Guid vaultId, Guid entityId, string? label)
{
if (IsAudited)
{
// The label may be null when the item could not be decrypted, which is a state worth recording
// rather than skipping: an item nobody can read is still one somebody deleted.
activity!.Record(
vaultId,
kind.EntityType,
entityId,
label ?? "(an item that could not be read)",
ActivityOperation.Deleted,
[]);
}
}
/// <summary>What an item is currently called, for a log line written as it goes away.</summary>
private async Task<string?> LabelAsync(
Guid vaultId,
Guid entityId,
PendingOperation? pending,
CancellationToken cancellationToken)
{
if (!keyring.TryGet(vaultId, out var vaultKey, out _))
{
return null;
}
var ancestor = await MirrorAncestorAsync(vaultId, entityId, cancellationToken)
.ConfigureAwait(false);
return Open(vaultKey, entityId, pending, ancestor)?.Label;
}
/// <summary>
/// Decrypts whichever version of an item this machine currently shows.
/// </summary>
/// <remarks>
/// The pending payload first, because that is what the user is looking at — an item edited offline twice
/// should report the second edit against the first, not against what the server last accepted. The
/// version each is opened at differs for the reason the sealing side differs: a queued payload is sealed
/// at the version the server <em>will</em> assign, and a mirror row holds the one it has.
/// </remarks>
private TSecret? Open(
ReadOnlyMemory<byte> vaultKey,
Guid entityId,
PendingOperation? pending,
StoredAncestor? ancestor)
{
if (pending is { Operation: SyncOperation.Upsert, Payload: { } queued })
{
return kind.TryOpen(
queued,
vaultKey.Span,
entityId,
SyncVersions.NextVersion(pending.ExpectedVersion))?.Secret;
}
return ancestor is null
? null
: kind.TryOpen(ancestor.Payload, vaultKey.Span, entityId, ancestor.Version)?.Secret;
}
/// <summary>