Public Access
Sync and authenticate with SSH keys on the client
Completes the client half of SSH keys: they sync alongside hosts, appear in their own list, and can be selected to authenticate a connection instead of typing a password. The reconciler and the repository were Host-typed throughout, so the choice was to generalise them or to keep a second copy per item type. Generalised, because ItemReconciler's whole premise is that the pull and the push paths must answer the same collision the same way — two copies would drift the first time one of them was fixed. What is genuinely per-type now arrives through IItemKind<TSecret>: the cipher, the merge, the plaintext columns, and the noun to use when telling a person what happened to their item. Generic where the server's IItemKind is not, and for the reason that reverses there — the client needs the concrete type, because it merges field by field. The pull filter is derived from the same registry that builds the reconcilers. That is the specific failure being designed out: an item type that encrypts, merges and lists perfectly and is never once requested from the server, so it works on the machine that made it and exists nowhere else. No client cache migration. The item table's primary key and the outbox's unique index already carry the entity type, and AadResourceTypes already mapped SshKey — so a host and a key may share an id and never see each other's rows, which SshKeySyncTests now arranges deliberately. A key hands the server nothing in plaintext. There is a public_key_fingerprint column and it would be accepted; leaving it null is deliberate. A fingerprint is not secret but it is a stable identifier for a key pair, so filling it would let an operator tell which of their users hold the same key and correlate one across vaults, for a column nothing reads. The design allows itself one plaintext concession — the relay address, which the relay cannot work without — and this is not that. A key is chosen per connection rather than bound to a host, which works the way ssh -i does. Binding one needs a field on HostSecret and therefore a payload schema bump, which makes every host written afterwards read-only on an older build; worth doing deliberately rather than as a side effect of adding keys. Three things this found, all of them by being falsified rather than by review: - Making the reconciler generic silently turned a record comparison into reference equality, because == on a type parameter is not value equality. The effect would have been a conflict recorded on every pass for an unacknowledged create that had in fact landed. Sabotaging the fix left all 73 tests passing — nothing covered that branch — so ConflictMatrixTests now has AnUnacknowledgedCreateThatDidLand_IsDroppedQuietly, which fails without it. - A test asserting that a blank passphrase reaches SSH.NET as null was vacuous: it exercised the editor, not the credential path, and passed with the guard deleted. Resolved by making SshKeySecret.Passphrase normalise an empty string to null, so there is one spelling of one state — which also keeps two clients from producing different payload bytes for an identical key. That exposed a wider gap: SshKeySecret, its codec and its merge had no direct unit tests at all. They have 25 now. - The reason first given for that normalisation was false. It claimed SSH.NET rejects a passphrase supplied for an unprotected key; measured against a real sshd it ignores it and authenticates anyway. Corrected everywhere it was stated and recorded in docs/platform-flags.md. The same test file also closes a real hole: SshPrivateKeyCredential had never been exercised against a server, because the existing key test builds SSH.NET's auth method directly and bypasses the path a vault-held key actually takes. Only one editor may be open at a time. Both sit in the same 340-pixel column as Auto rows and their heights together exceed it at the window's minimum size, so two open editors put the lower one's Save and Cancel past the bottom edge — the same failure this window already shipped once with the setup screens. Expressed as a state rule because that is the only form of it this repository can check: nothing here loads a .axaml. The refusal keeps what was typed, since in the key editor that is a pasted private key the user may have nowhere else. The end-to-end slice now carries a key as well as a host, so both item types go through the real API, the real PostgreSQL and the real crypto in one pass — the three hand-kept mappings between enums that do not line up are the reason that is worth doing rather than trusting the unit suites. 735 tests green, including the container-backed SSH and end-to-end suites. Zero warnings, dotnet format clean.
This commit is contained in:
@@ -33,7 +33,13 @@ public sealed class SyncEngine
|
||||
private readonly VaultKeyring keyring;
|
||||
private readonly TimeProvider clock;
|
||||
private readonly SyncOptions options;
|
||||
private readonly ItemReconciler reconciler;
|
||||
|
||||
/// <remarks>
|
||||
/// One per synchronised item type, built once. The keys are also the pull filter — see
|
||||
/// <see cref="ItemKinds"/> — so a type this engine cannot reconcile is never requested, and a type it
|
||||
/// can reconcile cannot be left out of the request.
|
||||
/// </remarks>
|
||||
private readonly Dictionary<SyncEntityType, IItemReconciler> reconcilers;
|
||||
|
||||
/// <summary>Creates the engine.</summary>
|
||||
public SyncEngine(
|
||||
@@ -63,7 +69,7 @@ public sealed class SyncEngine
|
||||
this.clock = clock;
|
||||
this.options = options ?? SyncOptions.Default;
|
||||
|
||||
reconciler = new ItemReconciler(items, outbox, conflicts, keyring);
|
||||
reconcilers = ItemKinds.Reconcilers(outbox, conflicts, keyring);
|
||||
}
|
||||
|
||||
/// <summary>Runs a full pass over one vault.</summary>
|
||||
@@ -127,7 +133,7 @@ public sealed class SyncEngine
|
||||
{
|
||||
var response = await api.SyncPullAsync(
|
||||
vaultId,
|
||||
new SyncPullRequest(state.Cursor, options.PullPageSize, [SyncEntityType.Host]),
|
||||
new SyncPullRequest(state.Cursor, options.PullPageSize, ItemKinds.SyncedTypes),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
foreach (var change in response.Changes)
|
||||
@@ -187,14 +193,16 @@ public sealed class SyncEngine
|
||||
SyncReportBuilder report,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (change.EntityType != SyncEntityType.Host)
|
||||
if (!reconcilers.TryGetValue(change.EntityType, out var reconciler))
|
||||
{
|
||||
// Reserved in the contract but not yet syncable. Ignoring it keeps a newer server's extra
|
||||
// entity types from breaking an older client's pull.
|
||||
// Reserved in the contract but not yet syncable here. The pull filter already asks for only
|
||||
// the types this build handles, so reaching this means a newer server sent something extra —
|
||||
// and ignoring it keeps that from breaking an older client's pull. Not mirrored either: a row
|
||||
// this build can never read is cache with no reader.
|
||||
return;
|
||||
}
|
||||
|
||||
await reconciler.MirrorAsync(vaultId, change, cancellationToken).ConfigureAwait(false);
|
||||
await ItemMirror.WriteAsync(items, vaultId, change, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var pending = await outbox
|
||||
.FindAsync(vaultId, change.EntityType, change.EntityId, cancellationToken)
|
||||
@@ -394,14 +402,29 @@ public sealed class SyncEngine
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!reconcilers.TryGetValue(operation.EntityType, out var reconciler))
|
||||
{
|
||||
// Only reachable if something queued a type this build does not synchronise, which the
|
||||
// repositories cannot do. Parked rather than dropped, so the change is visible to a user
|
||||
// instead of retried for ever against a path that cannot handle it.
|
||||
await RejectAsync(
|
||||
vaultId,
|
||||
operation,
|
||||
$"This version of DodoSSH cannot reconcile items of type {operation.EntityType}.",
|
||||
report,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result.ServerEntity is null)
|
||||
{
|
||||
// The version check failed but the server has no such row. Re-offer it as a create.
|
||||
return await RetryAsCreateAsync(vaultId, operation, report, cancellationToken)
|
||||
return await RetryAsCreateAsync(vaultId, reconciler, operation, report, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await reconciler.MirrorAsync(vaultId, result.ServerEntity, cancellationToken)
|
||||
await ItemMirror.WriteAsync(items, vaultId, result.ServerEntity, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await reconciler
|
||||
@@ -413,6 +436,7 @@ public sealed class SyncEngine
|
||||
|
||||
private async Task<bool> RetryAsCreateAsync(
|
||||
Guid vaultId,
|
||||
IItemReconciler reconciler,
|
||||
PendingOperation operation,
|
||||
SyncReportBuilder report,
|
||||
CancellationToken cancellationToken)
|
||||
@@ -424,44 +448,20 @@ public sealed class SyncEngine
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!keyring.TryGet(vaultId, out var vaultKey, out var generation)
|
||||
|| operation.Payload is null)
|
||||
// Re-sealing needs the item's own cipher, so the reconciler does it. A reason back means the
|
||||
// change can never be sent, not that it should be retried.
|
||||
var failure = await reconciler
|
||||
.ReofferAsCreateAsync(vaultId, operation, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (failure is null)
|
||||
{
|
||||
await RejectAsync(
|
||||
vaultId, operation, "This item has no usable vault key.", report, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
var local = HostCipher.TryOpen(
|
||||
operation.Payload,
|
||||
vaultKey.Span,
|
||||
operation.EntityId,
|
||||
SyncVersions.NextVersion(operation.ExpectedVersion));
|
||||
await RejectAsync(vaultId, operation, failure, report, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (local is null)
|
||||
{
|
||||
await RejectAsync(
|
||||
vaultId,
|
||||
operation,
|
||||
"The queued change could not be decrypted, so it could not be re-offered.",
|
||||
report,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Re-sealed at version 1, because that is what the server assigns to a create and the AAD binds
|
||||
// the version.
|
||||
await outbox.ReviseAsync(
|
||||
operation.Sequence,
|
||||
SyncOperation.Upsert,
|
||||
expectedVersion: null,
|
||||
HostCipher.Seal(local.Host, vaultKey.Span, operation.EntityId, generation, itemVersion: 1),
|
||||
HostFields.From(local.Host),
|
||||
ancestor: null,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Parks an operation the server will never accept, and says why.</summary>
|
||||
|
||||
Reference in New Issue
Block a user