Public Access
Sync credentials as a vault item type, and bind one to a host
Closes the largest remaining M1 gap in the data layer: a username and password can live in the vault, sync between machines, and be named by a host as how it authenticates. What is not here is the interface for creating one — see the end of this message. The third item type, and the first one that cost almost nothing to add. Server: a VaultCredential row, an EF configuration, a migration, and a CredentialKind. Client: a secret, a codec, a merge, a cipher, a kind, a repository facade and a session property. No new reconciliation logic, no change to the sync engine, no client cache migration. That was the whole point of the item-kind seam, and this is the evidence it holds. The narrowest type of the three on plaintext, and not for symmetry. A host has a deliberate concession — the relay needs an address it can resolve. A key has a fingerprint, public by nature, which this client still declines to send. A password has no part that is safe to expose: not its length, not a hash, not a hint. So CredentialKind refuses every plaintext field there is, hydrates none, and the table has no column to put one in. HostSecret.CredentialId is the password counterpart of SshKeyId, and the two are mutually exclusive. SSH itself would happily try a key and fall back to a password, but a host naming both leaves "how does this authenticate?" without a single answer — the interface, the connect path and the user would each be free to guess differently. TryValidate refuses it. One consequence was not anticipated: "a full host" stops being a coherent idea, which is what broke AFullHost_RoundTrips and is now written into that test. The schema version became a ladder rather than a maximum: credential-bound is 3, key-bound is 2, neither is still 1. Adding credentials therefore does not drag every key-bound host in every vault onto a version that clients understanding keys perfectly well would refuse to edit. A test pins exactly that, because it is the property the whole content-dependent-version rule exists to provide, and the obvious implementation would quietly lose it. Two tests had become false and said so: - Push_AnUnsupportedEntityType_IsInvalidNotAFailedBatch used Credential as its example of a type this server does not implement. It now asks the server's own registry what is still missing, so it cannot go stale again, and skips with a reason if that set ever empties. - ThePullFilterNamesEveryTypeThisBuildSynchronises pinned the exact list, which is what it is for. Also fixes ten nullable warnings — eight in SyncEndpointTests, two in a test file added earlier today. Neither set was introduced here; both were invisible until an unrelated change forced their project to recompile, which means the zero-warning claims made earlier in this work only ever covered what happened to be rebuilt. 777 tests green. Zero warnings, dotnet format clean. Not done, and deliberately: the credential interface. The vault column is 340 pixels wide and already holds two lists and two editors, kept from clipping its own buttons at the window's minimum height only by the one-editor-at-a-time rule added earlier today. A third list and a third editor would recreate that defect rather than avoid it, so the column needs a shape decision first. Credentials sync; they cannot yet be created in the interface.
This commit is contained in:
@@ -68,7 +68,7 @@ internal interface IItemKind
|
||||
internal static class ItemKinds
|
||||
{
|
||||
private static readonly Dictionary<SyncEntityType, IItemKind> Supported =
|
||||
new[] { (IItemKind)new HostKind(), new SshKeyKind() }
|
||||
new[] { (IItemKind)new HostKind(), new SshKeyKind(), new CredentialKind() }
|
||||
.ToDictionary(kind => kind.WireType);
|
||||
|
||||
/// <summary>The kind for a wire type, or null when this server does not synchronise it yet.</summary>
|
||||
@@ -292,3 +292,98 @@ internal sealed class SshKeyKind : IItemKind
|
||||
? new SyncPlaintextFields(PublicKeyFingerprint: fingerprint)
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>Credentials: an envelope and nothing else.</summary>
|
||||
/// <remarks>
|
||||
/// The strictest of the three kinds about plaintext, and the reason is not symmetry. A key at least has a
|
||||
/// fingerprint that is public by nature; a password has no part that is safe to expose, so this kind accepts
|
||||
/// no plaintext fields at all and hydrates none.
|
||||
/// </remarks>
|
||||
internal sealed class CredentialKind : IItemKind
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public SyncEntityType WireType => SyncEntityType.Credential;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ChangeEntityType ChangeType => ChangeEntityType.Credential;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IVaultItem?> FindAsync(
|
||||
DodoDbContext database,
|
||||
Guid id,
|
||||
CancellationToken cancellationToken) =>
|
||||
await database.Credentials.SingleOrDefaultAsync(c => c.Id == id, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<Guid, IVaultItem>> LoadAsync(
|
||||
DodoDbContext database,
|
||||
Guid vaultId,
|
||||
Guid[] ids,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var rows = await database.Credentials
|
||||
.Where(c => c.VaultId == vaultId && ids.Contains(c.Id))
|
||||
.ToListAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return rows.ToDictionary(row => row.Id, row => (IVaultItem)row);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IVaultItem Add(DodoDbContext database, Guid id, Guid vaultId)
|
||||
{
|
||||
var credential = new VaultCredential { Id = id, VaultId = vaultId };
|
||||
|
||||
database.Credentials.Add(credential);
|
||||
|
||||
return credential;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refuses every plaintext field there is.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refused with a reason rather than silently dropped, so a client that believes it is storing something
|
||||
/// finds out now rather than when the field turns out to be missing.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
public bool ValidateFields(SyncPlaintextFields fields, out string error)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(fields);
|
||||
|
||||
error = string.Empty;
|
||||
|
||||
if (fields.RelayEnabled || fields.Hostname is not null || fields.Port is not null)
|
||||
{
|
||||
error = "A credential has no relay target; relay fields may only be set on a host.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fields.PublicKeyFingerprint is not null)
|
||||
{
|
||||
error = "A credential has no public key.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <remarks>Nothing to copy: this type has no plaintext columns to copy anything into.</remarks>
|
||||
/// <inheritdoc />
|
||||
public void ApplyFields(IVaultItem item, SyncPlaintextFields fields)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearFieldsOnDelete(IVaultItem item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Always null, which is a stronger statement than an empty record: this type has no plaintext columns,
|
||||
/// so there is nothing a pull could hydrate even in principle.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
public SyncPlaintextFields? Hydrate(IVaultItem item) => null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace DodoSSH.Client.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// A username and password as the user sees it, decrypted.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The same bargain <see cref="SshKeySecret"/> documents applies here and is worth not repeating in full:
|
||||
/// the password is an ordinary managed string, it cannot be wiped, and a process dump taken while the vault
|
||||
/// is unlocked contains it. What that buys is that it never reaches the disk or the server in a form either
|
||||
/// can read.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="Username"/> is optional and overrides the host's when set, which is the reason this is a
|
||||
/// separate item rather than two more fields on a host: one credential is very often the same account on
|
||||
/// twenty machines, and duplicating it per host means rotating it in twenty places and missing one.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed record CredentialSecret : IVaultSecret
|
||||
{
|
||||
private readonly string? username;
|
||||
|
||||
/// <summary>What the user calls this credential.</summary>
|
||||
public required string Label { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The password.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Required, and an empty one is not valid — see <see cref="TryValidate"/>. A credential with no password
|
||||
/// is not a credential, and storing one would produce an item that looks usable and fails at the
|
||||
/// handshake with an error about authentication rather than about the vault.
|
||||
/// </remarks>
|
||||
public required string Password { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The account this credential is for, when it is not the host's own username.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Empty is normalised to null, as <see cref="SshKeySecret.Passphrase"/> is and for the same kind of
|
||||
/// reason: blank and absent mean one thing here — "use the host's username" — and two spellings of one
|
||||
/// state would give two clients different payload bytes for an identical credential, and make
|
||||
/// <c>Username is not null</c> an unreliable answer to "does this override the host?".
|
||||
/// </remarks>
|
||||
public string? Username
|
||||
{
|
||||
get => username;
|
||||
init => username = string.IsNullOrEmpty(value) ? null : value;
|
||||
}
|
||||
|
||||
/// <summary>Free text.</summary>
|
||||
public string? Notes { get; init; }
|
||||
|
||||
/// <summary>Whether this is storable, and why not if it is not.</summary>
|
||||
public bool TryValidate([NotNullWhen(false)] out string? reason)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Label))
|
||||
{
|
||||
reason = "A credential needs a name.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Password.Length == 0)
|
||||
{
|
||||
// Length rather than IsNullOrWhiteSpace: a password of spaces is a password, and refusing it
|
||||
// would lock someone out of a host over a validation opinion.
|
||||
reason = "A credential needs a password.";
|
||||
return false;
|
||||
}
|
||||
|
||||
reason = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DodoSSH.Client.Domain;
|
||||
|
||||
/// <summary>A decoded credential payload, together with the schema version it was written at.</summary>
|
||||
/// <param name="Credential">The credential.</param>
|
||||
/// <param name="SchemaVersion">The version the writing client used.</param>
|
||||
public sealed record CredentialSecretDocument(CredentialSecret Credential, int SchemaVersion)
|
||||
{
|
||||
/// <inheritdoc cref="HostSecretDocument.IsReadOnly" />
|
||||
public bool IsReadOnly => SchemaVersion > CredentialSecretCodec.CurrentSchemaVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes and decodes the plaintext inside a credential item's encrypted payload.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mirrors <see cref="SshKeySecretCodec"/>, for the same reasons and with the same guarantees: JSON so a
|
||||
/// field can be added without a migration, deterministic property order so an unchanged credential does not
|
||||
/// look like a change to the sync engine, and a separate mutable document type so a decode failure cannot
|
||||
/// produce a half-built credential that looks valid downstream.
|
||||
/// </remarks>
|
||||
public static class CredentialSecretCodec
|
||||
{
|
||||
/// <summary>The schema version this build writes.</summary>
|
||||
public const int CurrentSchemaVersion = 1;
|
||||
|
||||
/// <summary>Serialises a credential to the bytes that get sealed.</summary>
|
||||
/// <exception cref="ArgumentException">The credential is not valid for storage.</exception>
|
||||
public static byte[] Encode(CredentialSecret credential)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(credential);
|
||||
|
||||
if (!credential.TryValidate(out var reason))
|
||||
{
|
||||
throw new ArgumentException(reason, nameof(credential));
|
||||
}
|
||||
|
||||
var document = new CredentialPayloadDocument
|
||||
{
|
||||
SchemaVersion = CurrentSchemaVersion,
|
||||
Label = credential.Label,
|
||||
Password = credential.Password,
|
||||
Username = credential.Username,
|
||||
Notes = credential.Notes,
|
||||
};
|
||||
|
||||
return JsonSerializer.SerializeToUtf8Bytes(
|
||||
document, CredentialPayloadJsonContext.Default.CredentialPayloadDocument);
|
||||
}
|
||||
|
||||
/// <summary>Parses a decrypted payload.</summary>
|
||||
/// <inheritdoc cref="HostSecretCodec.TryDecode" path="/remarks" />
|
||||
public static bool TryDecode(
|
||||
ReadOnlySpan<byte> payload,
|
||||
[NotNullWhen(true)] out CredentialSecretDocument? document)
|
||||
{
|
||||
document = null;
|
||||
|
||||
CredentialPayloadDocument? parsed;
|
||||
try
|
||||
{
|
||||
parsed = JsonSerializer.Deserialize(
|
||||
payload, CredentialPayloadJsonContext.Default.CredentialPayloadDocument);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parsed is null || parsed.SchemaVersion < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var candidate = new CredentialSecret
|
||||
{
|
||||
Label = parsed.Label ?? string.Empty,
|
||||
Password = parsed.Password ?? string.Empty,
|
||||
Username = parsed.Username,
|
||||
Notes = parsed.Notes,
|
||||
};
|
||||
|
||||
if (!candidate.TryValidate(out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
document = new CredentialSecretDocument(candidate, parsed.SchemaVersion);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The serialised shape. Mutable and nullable because it models untrusted input.</summary>
|
||||
/// <inheritdoc cref="HostPayloadDocument" path="/remarks" />
|
||||
internal sealed class CredentialPayloadDocument
|
||||
{
|
||||
public int SchemaVersion { get; set; }
|
||||
|
||||
public string? Label { get; set; }
|
||||
|
||||
public string? Password { get; set; }
|
||||
|
||||
public string? Username { get; set; }
|
||||
|
||||
public string? Notes { get; set; }
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip)]
|
||||
[JsonSerializable(typeof(CredentialPayloadDocument))]
|
||||
internal sealed partial class CredentialPayloadJsonContext : JsonSerializerContext;
|
||||
@@ -0,0 +1,111 @@
|
||||
namespace DodoSSH.Client.Domain;
|
||||
|
||||
/// <summary>The merged credential, and everything that had to be overridden to produce it.</summary>
|
||||
/// <param name="Merged">The credential to store and push.</param>
|
||||
/// <param name="Conflicts">Empty when the two sides were reconcilable field by field.</param>
|
||||
public sealed record CredentialMergeResult(
|
||||
CredentialSecret Merged,
|
||||
IReadOnlyList<HostFieldConflict> Conflicts)
|
||||
{
|
||||
/// <summary>Whether anything had to be overridden.</summary>
|
||||
public bool HasConflicts => Conflicts.Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges two divergent versions of a credential against the version they both started from.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Every field is a scalar, so this is the same shape as <see cref="SshKeySecretMerge"/> and reuses
|
||||
/// <see cref="HostFieldConflict"/> for the same reason: the conflict log, the storage behind it and the
|
||||
/// interface that shows it are shared, and a parallel record with identical members would have to be mapped
|
||||
/// at every boundary.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The password never reaches the conflict log.</b> Reported as having differed and nothing more, exactly
|
||||
/// as <c>SshKeySecretMerge</c> does for key material — and here the case for it is if anything plainer, since
|
||||
/// a discarded password is very often still the live password on some other system. The user loses nothing
|
||||
/// they could act on: nobody reconciles two passwords by reading them side by side.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The username is shown, because it is not a secret and knowing which of two accounts the merge dropped is
|
||||
/// exactly what makes the notice useful.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static class CredentialSecretMerge
|
||||
{
|
||||
/// <summary>Produces the merged credential.</summary>
|
||||
/// <param name="ancestor">The version both sides branched from.</param>
|
||||
/// <param name="local">The pending local version.</param>
|
||||
/// <param name="remote">The server's current version.</param>
|
||||
public static CredentialMergeResult Merge(
|
||||
CredentialSecret ancestor,
|
||||
CredentialSecret local,
|
||||
CredentialSecret remote)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(ancestor);
|
||||
ArgumentNullException.ThrowIfNull(local);
|
||||
ArgumentNullException.ThrowIfNull(remote);
|
||||
|
||||
var conflicts = new List<HostFieldConflict>();
|
||||
|
||||
var merged = new CredentialSecret
|
||||
{
|
||||
// Null-forgiving on the two required fields, as the host and key merges do for the same reason:
|
||||
// the merge returns one of its three inputs, and all three are non-null by construction.
|
||||
Label = Resolve(
|
||||
nameof(CredentialSecret.Label),
|
||||
ancestor.Label,
|
||||
local.Label,
|
||||
remote.Label,
|
||||
conflicts,
|
||||
redact: false)!,
|
||||
Password = Resolve(
|
||||
nameof(CredentialSecret.Password),
|
||||
ancestor.Password,
|
||||
local.Password,
|
||||
remote.Password,
|
||||
conflicts,
|
||||
redact: true)!,
|
||||
Username = Resolve(
|
||||
nameof(CredentialSecret.Username),
|
||||
ancestor.Username,
|
||||
local.Username,
|
||||
remote.Username,
|
||||
conflicts,
|
||||
redact: false),
|
||||
Notes = Resolve(
|
||||
nameof(CredentialSecret.Notes),
|
||||
ancestor.Notes,
|
||||
local.Notes,
|
||||
remote.Notes,
|
||||
conflicts,
|
||||
redact: false),
|
||||
};
|
||||
|
||||
return new CredentialMergeResult(merged, conflicts);
|
||||
}
|
||||
|
||||
private static string? Resolve(
|
||||
string name,
|
||||
string? ancestor,
|
||||
string? local,
|
||||
string? remote,
|
||||
List<HostFieldConflict> conflicts,
|
||||
bool redact)
|
||||
{
|
||||
var merge = ThreeWayMerge.Scalar(ancestor, local, remote, StringComparer.Ordinal);
|
||||
|
||||
if (merge.IsConflicted)
|
||||
{
|
||||
conflicts.Add(new HostFieldConflict(
|
||||
name,
|
||||
MergeSide.Local,
|
||||
redact ? "(kept the server's value)" : merge.Value ?? "(none)",
|
||||
redact ? "(a different value was discarded)" : merge.Discarded ?? "(none)",
|
||||
DiscardedWasRemoval: false));
|
||||
}
|
||||
|
||||
return merge.Value;
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,25 @@ public sealed record HostSecret : IVaultSecret
|
||||
/// </remarks>
|
||||
public Guid? SshKeyId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The vault credential to authenticate with, or null to be asked for a password.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The password counterpart of <see cref="SshKeyId"/>, with the same reasoning about ids rather than
|
||||
/// copies, the same dangling-reference handling, and the same refusal to fall back when the reference
|
||||
/// cannot be resolved. One credential is very often the same account on twenty hosts, which is exactly
|
||||
/// why it is referenced and not embedded — a copy per host is twenty places to rotate and one to forget.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Mutually exclusive with <see cref="SshKeyId"/>.</b> SSH itself would happily try a key and fall
|
||||
/// back to a password, but a host that names both leaves "how does this authenticate?" without a single
|
||||
/// answer — and the interface, the connect path and the user would each be free to guess differently.
|
||||
/// One host, one method; <see cref="TryValidate"/> enforces it.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public Guid? CredentialId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this host may be dialled through the server relay.
|
||||
/// </summary>
|
||||
@@ -143,6 +162,18 @@ public sealed record HostSecret : IVaultSecret
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CredentialId == Guid.Empty)
|
||||
{
|
||||
reason = "A credential reference cannot be an empty id; use no credential instead.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SshKeyId is not null && CredentialId is not null)
|
||||
{
|
||||
reason = "A host authenticates with a key or with a credential, not both.";
|
||||
return false;
|
||||
}
|
||||
|
||||
reason = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,8 +59,11 @@ public static class HostSecretCodec
|
||||
/// <summary>The version that introduced <see cref="HostSecret.SshKeyId"/>.</summary>
|
||||
public const int SshKeyIdSchemaVersion = 2;
|
||||
|
||||
/// <summary>The version that introduced <see cref="HostSecret.CredentialId"/>.</summary>
|
||||
public const int CredentialIdSchemaVersion = 3;
|
||||
|
||||
/// <summary>The highest schema version this build can write.</summary>
|
||||
public const int CurrentSchemaVersion = SshKeyIdSchemaVersion;
|
||||
public const int CurrentSchemaVersion = CredentialIdSchemaVersion;
|
||||
|
||||
/// <summary>Serialises a host to the bytes that get sealed.</summary>
|
||||
/// <exception cref="ArgumentException">The host is not valid for storage.</exception>
|
||||
@@ -91,6 +94,7 @@ public static class HostSecretCodec
|
||||
Options = options,
|
||||
RelayEnabled = host.RelayEnabled,
|
||||
SshKeyId = host.SshKeyId,
|
||||
CredentialId = host.CredentialId,
|
||||
};
|
||||
|
||||
return JsonSerializer.SerializeToUtf8Bytes(
|
||||
@@ -110,14 +114,24 @@ public static class HostSecretCodec
|
||||
/// use the newer field.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The rule generalises, and the next field added should follow it: a host is written at the version
|
||||
/// that introduced the newest field it actually carries. It also means the bytes for a host with no key
|
||||
/// are identical to what this codec produced before <see cref="HostSecret.SshKeyId"/> existed, so
|
||||
/// adding the field did not make every host in every vault look like a change to the sync engine.
|
||||
/// The rule generalises, and every field added since has followed it: a host is written at the version
|
||||
/// that introduced the newest field it actually carries. It also means the bytes for a host that binds
|
||||
/// nothing are identical to what this codec produced before either binding existed, so adding the fields
|
||||
/// did not make every host in every vault look like a change to the sync engine.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The two bindings are mutually exclusive — see <see cref="HostSecret.CredentialId"/> — so this reads as
|
||||
/// a ladder rather than a maximum. If a future field is <em>not</em> exclusive with an older one, this
|
||||
/// becomes the maximum over the versions of the fields present, which is the same rule stated more
|
||||
/// generally.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
private static int SchemaVersionFor(HostSecret host) =>
|
||||
host.SshKeyId is null ? BaseSchemaVersion : SshKeyIdSchemaVersion;
|
||||
private static int SchemaVersionFor(HostSecret host) => host switch
|
||||
{
|
||||
{ CredentialId: not null } => CredentialIdSchemaVersion,
|
||||
{ SshKeyId: not null } => SshKeyIdSchemaVersion,
|
||||
_ => BaseSchemaVersion,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Parses a decrypted payload.
|
||||
@@ -184,6 +198,7 @@ public static class HostSecretCodec
|
||||
Options = options,
|
||||
RelayEnabled = parsed.RelayEnabled,
|
||||
SshKeyId = parsed.SshKeyId,
|
||||
CredentialId = parsed.CredentialId,
|
||||
};
|
||||
|
||||
if (!candidate.TryValidate(out _))
|
||||
@@ -236,6 +251,9 @@ internal sealed class HostPayloadDocument
|
||||
/// makes a host with no key encode exactly as it did before the field existed.
|
||||
/// </remarks>
|
||||
public Guid? SshKeyId { get; set; }
|
||||
|
||||
/// <inheritdoc cref="SshKeyId" />
|
||||
public Guid? CredentialId { get; set; }
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(
|
||||
|
||||
@@ -114,6 +114,14 @@ public static class HostSecretMerge
|
||||
remote.SshKeyId,
|
||||
conflicts,
|
||||
static id => id?.ToString() ?? "no key"),
|
||||
|
||||
CredentialId = Field(
|
||||
nameof(HostSecret.CredentialId),
|
||||
ancestor.CredentialId,
|
||||
local.CredentialId,
|
||||
remote.CredentialId,
|
||||
conflicts,
|
||||
static id => id?.ToString() ?? "no credential"),
|
||||
};
|
||||
|
||||
return new HostMergeResult(merged, conflicts);
|
||||
|
||||
@@ -76,6 +76,7 @@ public sealed class VaultSession : IAsyncDisposable
|
||||
Vault = new VaultStore(caches, clock);
|
||||
Hosts = new HostRepository(Items, Outbox, keyring);
|
||||
SshKeys = new SshKeyRepository(Items, Outbox, keyring);
|
||||
Credentials = new CredentialRepository(Items, Outbox, keyring);
|
||||
}
|
||||
|
||||
/// <summary>Who this session belongs to, and the material that unlocked it.</summary>
|
||||
@@ -97,6 +98,9 @@ public sealed class VaultSession : IAsyncDisposable
|
||||
/// </remarks>
|
||||
public SshKeyRepository SshKeys { get; }
|
||||
|
||||
/// <summary>Usernames and passwords, decrypted, with unpushed local changes laid over them.</summary>
|
||||
public CredentialRepository Credentials { get; }
|
||||
|
||||
/// <summary>Vaults whose grant could not be opened, so their items cannot be read.</summary>
|
||||
public IReadOnlyList<Guid> UnreadableVaults => keyring.Unopened;
|
||||
|
||||
|
||||
@@ -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 credential into an item payload and back.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Mirrors <see cref="HostCipher"/> 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> As with <see cref="SshKeyCipher"/>, the AAD binds
|
||||
/// it and the two enums that name item types do not agree: <c>SyncEntityType.Credential</c> is 2 while
|
||||
/// <c>CryptoSpec.AadResourceType.Credential</c> is 5, because the crypto enum carries None, User, Device and
|
||||
/// Vault ahead of the item types. Casting one to the other would seal a password under the resource type for
|
||||
/// a <em>user</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 CredentialCipher
|
||||
{
|
||||
private const CryptoSpec.AadResourceType Resource = CryptoSpec.AadResourceType.Credential;
|
||||
|
||||
/// <summary>Encrypts a credential.</summary>
|
||||
/// <param name="credential">The credential. 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(
|
||||
CredentialSecret credential,
|
||||
ReadOnlySpan<byte> vaultKey,
|
||||
Guid entityId,
|
||||
uint keyGeneration,
|
||||
int itemVersion)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(credential);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(itemVersion, 1);
|
||||
|
||||
var plaintext = CredentialSecretCodec.Encode(credential);
|
||||
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 encoded password, wiped. As with a key, this is the one buffer holding the secret that can
|
||||
// actually be cleared — the strings the codec read it from cannot be.
|
||||
CryptographicOperations.ZeroMemory(plaintext);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Decrypts a credential.</summary>
|
||||
/// <inheritdoc cref="HostCipher.TryOpen" path="/returns" />
|
||||
public static CredentialSecretDocument? 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 CredentialSecretCodec.TryDecode(plaintext, out var document) ? document : null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CryptographicOperations.ZeroMemory(plaintext);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CryptographicOperations.ZeroMemory(dataKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using DodoSSH.Client.Domain;
|
||||
using DodoSSH.Client.Storage;
|
||||
|
||||
namespace DodoSSH.Client.Sync;
|
||||
|
||||
/// <summary>
|
||||
/// The credentials in a vault, decrypted, with unpushed local changes laid over them.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The third facade over the same generic repository, and by now that is the point: adding an item type to
|
||||
/// this client is a kind, a facade and a view, with no new reconciliation logic and no new sync path.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>A credential listed here has its password in memory.</b> Listing decrypts every credential in the
|
||||
/// vault, so the caller holds them all for as long as it holds the listing — the same bargain
|
||||
/// <see cref="SshKeyRepository"/> makes for key material, and worth restating because it is the reason the
|
||||
/// interface reads a listing once per reload rather than holding one open.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class CredentialRepository(ItemStore items, OutboxStore outbox, VaultKeyring keyring)
|
||||
{
|
||||
private readonly VaultItemRepository<CredentialSecret> credentials =
|
||||
new(CredentialKind.Instance, items, outbox, keyring);
|
||||
|
||||
/// <inheritdoc cref="VaultItemRepository{TSecret}.ListAsync" />
|
||||
public Task<ItemListing<CredentialSecret>> ListAsync(
|
||||
Guid vaultId,
|
||||
CancellationToken cancellationToken) =>
|
||||
credentials.ListAsync(vaultId, cancellationToken);
|
||||
|
||||
/// <inheritdoc cref="VaultItemRepository{TSecret}.CreateAsync" />
|
||||
public Task<Guid> CreateAsync(
|
||||
Guid vaultId,
|
||||
CredentialSecret credential,
|
||||
CancellationToken cancellationToken) =>
|
||||
credentials.CreateAsync(vaultId, credential, cancellationToken);
|
||||
|
||||
/// <inheritdoc cref="VaultItemRepository{TSecret}.UpdateAsync" />
|
||||
public Task UpdateAsync(
|
||||
Guid vaultId,
|
||||
Guid entityId,
|
||||
CredentialSecret credential,
|
||||
CancellationToken cancellationToken) =>
|
||||
credentials.UpdateAsync(vaultId, entityId, credential, cancellationToken);
|
||||
|
||||
/// <inheritdoc cref="VaultItemRepository{TSecret}.DeleteAsync" />
|
||||
public Task DeleteAsync(Guid vaultId, Guid entityId, CancellationToken cancellationToken) =>
|
||||
credentials.DeleteAsync(vaultId, entityId, cancellationToken);
|
||||
}
|
||||
@@ -27,8 +27,8 @@ internal sealed record MergedItem<TSecret>(
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The reconciler holds the six answers a collision can have — merge, adopt, resurrect, abandon, park,
|
||||
/// refuse — and every one of them is identical for a host and for an SSH key. Only the encoding, the
|
||||
/// merge and the plaintext columns differ, and those arrive through here. A second copy of the
|
||||
/// refuse — and every one of them is identical for a host, an SSH key and a credential. Only the encoding,
|
||||
/// the merge and the plaintext columns differ, and those arrive through here. A second copy of the
|
||||
/// reconciler per item type is the alternative, and it is not a real one: the file's whole premise is
|
||||
/// that the pull and push paths must answer the same situation the same way, and two copies would drift
|
||||
/// the moment one of them was fixed.
|
||||
@@ -113,6 +113,9 @@ internal static class ItemKinds
|
||||
|
||||
(SyncEntityType.SshKey, static (outbox, conflicts, keyring) =>
|
||||
new ItemReconciler<SshKeySecret>(SshKeyKind.Instance, outbox, conflicts, keyring)),
|
||||
|
||||
(SyncEntityType.Credential, static (outbox, conflicts, keyring) =>
|
||||
new ItemReconciler<CredentialSecret>(CredentialKind.Instance, outbox, conflicts, keyring)),
|
||||
];
|
||||
|
||||
/// <summary>The types to ask the server for, in a fixed order.</summary>
|
||||
@@ -248,3 +251,68 @@ internal sealed class SshKeyKind : IItemKind<SshKeySecret>
|
||||
return secret with { Label = label };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Credentials.</summary>
|
||||
internal sealed class CredentialKind : IItemKind<CredentialSecret>
|
||||
{
|
||||
internal static CredentialKind Instance { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public SyncEntityType EntityType => SyncEntityType.Credential;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Noun => "credential";
|
||||
|
||||
/// <inheritdoc />
|
||||
public OpenedItem<CredentialSecret>? TryOpen(
|
||||
EncryptedPayload payload,
|
||||
ReadOnlySpan<byte> vaultKey,
|
||||
Guid entityId,
|
||||
int itemVersion)
|
||||
{
|
||||
var document = CredentialCipher.TryOpen(payload, vaultKey, entityId, itemVersion);
|
||||
|
||||
return document is null
|
||||
? null
|
||||
: new OpenedItem<CredentialSecret>(document.Credential, document.IsReadOnly);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EncryptedPayload Seal(
|
||||
CredentialSecret secret,
|
||||
ReadOnlySpan<byte> vaultKey,
|
||||
Guid entityId,
|
||||
uint keyGeneration,
|
||||
int itemVersion) =>
|
||||
CredentialCipher.Seal(secret, vaultKey, entityId, keyGeneration, itemVersion);
|
||||
|
||||
/// <summary>
|
||||
/// Nothing, and for this type there was never a candidate.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A key at least has a fingerprint, which is public by nature and which this client still declines to
|
||||
/// send. A password has no part that is safe to expose — not its length, not a hash, not a hint — so
|
||||
/// there is no decision to make here. The server refuses plaintext fields on this type outright.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
public SyncPlaintextFields? Fields(CredentialSecret secret) => null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public MergedItem<CredentialSecret> Merge(
|
||||
CredentialSecret ancestor,
|
||||
CredentialSecret local,
|
||||
CredentialSecret remote)
|
||||
{
|
||||
var merged = CredentialSecretMerge.Merge(ancestor, local, remote);
|
||||
|
||||
return new MergedItem<CredentialSecret>(merged.Merged, merged.Conflicts);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CredentialSecret Relabel(CredentialSecret secret, string label)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(secret);
|
||||
|
||||
return secret with { Label = label };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,3 +168,68 @@ public sealed class VaultSshKey : IVaultItem
|
||||
/// <summary>Who last modified it.</summary>
|
||||
public Guid UpdatedByUserId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A stored username and password, as ciphertext.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Its own table for the same reason <see cref="VaultSshKey"/> is: the columns a host needs are columns a
|
||||
/// credential must never have. There is no relay trio here, and unlike a key there is not even a fingerprint
|
||||
/// — nothing about a password is safe to hold in the clear, not its length, not a hash, not a hint. So this
|
||||
/// row is an opaque envelope and its bookkeeping, and that is the whole design.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The server cannot enforce anything about the contents, and should not pretend to.</b> Whether a
|
||||
/// credential has a username, whether its password is empty, whether it is still valid — all of that is
|
||||
/// inside the payload and belongs to the client. The one thing this row asserts is that the ciphertext
|
||||
/// belongs to a vault and carries a version, which is what the write path needs to order changes.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class VaultCredential : IVaultItem
|
||||
{
|
||||
/// <summary>Primary key. UUIDv7, generated by the client so credentials can be created offline.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Owning vault.</summary>
|
||||
public Guid VaultId { get; set; }
|
||||
|
||||
/// <summary>Owning vault.</summary>
|
||||
public Vault? Vault { get; set; }
|
||||
|
||||
/// <summary>The encrypted credential: a DSH1 envelope. Opaque to the server.</summary>
|
||||
public byte[] Payload { get; set; } = [];
|
||||
|
||||
/// <summary>The item's data key, wrapped under the vault key. Opaque.</summary>
|
||||
public byte[]? DataKeyWrap { get; set; }
|
||||
|
||||
/// <summary>Reserved for per-item content keys wrapped to individual users; see docs/crypto.md §3.</summary>
|
||||
public Guid? ContentKeyId { get; set; }
|
||||
|
||||
/// <summary>Vault key generation this payload was encrypted under.</summary>
|
||||
public int KeyGeneration { get; set; }
|
||||
|
||||
/// <summary>AAD rule version, enabling a lazy re-encrypt-on-write migration later.</summary>
|
||||
public short PayloadAadVersion { get; set; }
|
||||
|
||||
/// <summary>Client-visible, monotonic item version, used for <c>expectedVersion</c> checks.</summary>
|
||||
public int Version { get; set; }
|
||||
|
||||
/// <summary>Latest change-log sequence touching this row, so a delta pull can join directly.</summary>
|
||||
public long ChangeSequence { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Last modification timestamp.</summary>
|
||||
public DateTimeOffset UpdatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Soft-delete marker; a tombstone, so an offline client learns the credential went away.</summary>
|
||||
public DateTimeOffset? DeletedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Who created it.</summary>
|
||||
public Guid CreatedByUserId { get; set; }
|
||||
|
||||
/// <summary>Who last modified it.</summary>
|
||||
public Guid UpdatedByUserId { get; set; }
|
||||
}
|
||||
|
||||
@@ -86,6 +86,42 @@ public sealed class SshKeyConfiguration : IEntityTypeConfiguration<VaultSshKey>
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps <see cref="VaultCredential"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The narrowest of the three item tables, and deliberately so: no relay CHECK, and unlike
|
||||
/// <see cref="SshKeyConfiguration"/> not even a fingerprint column. There is nothing about a password that
|
||||
/// is safe to hold in the clear, so there is nothing here but the envelope and its bookkeeping.
|
||||
/// </remarks>
|
||||
public sealed class CredentialConfiguration : IEntityTypeConfiguration<VaultCredential>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Configure(EntityTypeBuilder<VaultCredential> builder)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(builder);
|
||||
|
||||
builder.ToTable("credential");
|
||||
builder.HasKey(c => c.Id);
|
||||
|
||||
// Client-generated UUIDv7: credentials must be creatable offline, with their ids.
|
||||
builder.Property(c => c.Id).ValueGeneratedNever();
|
||||
builder.UseXminConcurrencyToken();
|
||||
|
||||
builder.Property(c => c.Payload).IsRequired();
|
||||
|
||||
builder.HasIndex(c => new { c.VaultId, c.ChangeSequence });
|
||||
|
||||
builder.HasIndex(c => c.VaultId)
|
||||
.HasFilter("deleted_at_utc IS NULL")
|
||||
.HasDatabaseName("ix_credential_vault_live");
|
||||
|
||||
builder.ToTable(t => t.HasCheckConstraint(
|
||||
"ck_credential_version",
|
||||
"version >= 1"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Maps <see cref="VaultChange"/>.</summary>
|
||||
public sealed class SyncChangeConfiguration : IEntityTypeConfiguration<VaultChange>
|
||||
{
|
||||
|
||||
@@ -57,6 +57,9 @@ public class DodoDbContext(DbContextOptions<DodoDbContext> options) : DbContext(
|
||||
/// <summary>SSH key pairs, held as ciphertext.</summary>
|
||||
public DbSet<VaultSshKey> SshKeys => Set<VaultSshKey>();
|
||||
|
||||
/// <summary>Usernames and passwords, held as ciphertext.</summary>
|
||||
public DbSet<VaultCredential> Credentials => Set<VaultCredential>();
|
||||
|
||||
/// <summary>The per-vault change log that delta sync reads.</summary>
|
||||
public DbSet<VaultChange> VaultChanges => Set<VaultChange>();
|
||||
|
||||
|
||||
+1162
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DodoSSH.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddCredentialItem : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "credential",
|
||||
schema: "dodo",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
vault_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
payload = table.Column<byte[]>(type: "bytea", nullable: false),
|
||||
data_key_wrap = table.Column<byte[]>(type: "bytea", nullable: true),
|
||||
content_key_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
key_generation = table.Column<int>(type: "integer", nullable: false),
|
||||
payload_aad_version = table.Column<short>(type: "smallint", nullable: false),
|
||||
version = table.Column<int>(type: "integer", nullable: false),
|
||||
change_sequence = table.Column<long>(type: "bigint", nullable: false),
|
||||
created_at_utc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
updated_at_utc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
deleted_at_utc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
created_by_user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
updated_by_user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_credential", x => x.id);
|
||||
table.CheckConstraint("ck_credential_version", "version >= 1");
|
||||
table.ForeignKey(
|
||||
name: "fk_credential_vaults_vault_id",
|
||||
column: x => x.vault_id,
|
||||
principalSchema: "dodo",
|
||||
principalTable: "vault",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_credential_vault_id_change_sequence",
|
||||
schema: "dodo",
|
||||
table: "credential",
|
||||
columns: new[] { "vault_id", "change_sequence" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_credential_vault_live",
|
||||
schema: "dodo",
|
||||
table: "credential",
|
||||
column: "vault_id",
|
||||
filter: "deleted_at_utc IS NULL");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "credential",
|
||||
schema: "dodo");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -737,6 +737,87 @@ namespace DodoSSH.Infrastructure.Migrations
|
||||
b.ToTable("sync_change", "dodo");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DodoSSH.Domain.VaultCredential", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<long>("ChangeSequence")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("change_sequence");
|
||||
|
||||
b.Property<Guid?>("ContentKeyId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("content_key_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAtUtc")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at_utc");
|
||||
|
||||
b.Property<Guid>("CreatedByUserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("created_by_user_id");
|
||||
|
||||
b.Property<byte[]>("DataKeyWrap")
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("data_key_wrap");
|
||||
|
||||
b.Property<DateTimeOffset?>("DeletedAtUtc")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("deleted_at_utc");
|
||||
|
||||
b.Property<int>("KeyGeneration")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("key_generation");
|
||||
|
||||
b.Property<byte[]>("Payload")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("payload");
|
||||
|
||||
b.Property<short>("PayloadAadVersion")
|
||||
.HasColumnType("smallint")
|
||||
.HasColumnName("payload_aad_version");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAtUtc")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at_utc");
|
||||
|
||||
b.Property<Guid>("UpdatedByUserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("updated_by_user_id");
|
||||
|
||||
b.Property<Guid>("VaultId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("vault_id");
|
||||
|
||||
b.Property<int>("Version")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.Property<uint>("xmin")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("xid")
|
||||
.HasColumnName("xmin");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_credential");
|
||||
|
||||
b.HasIndex("VaultId")
|
||||
.HasDatabaseName("ix_credential_vault_live")
|
||||
.HasFilter("deleted_at_utc IS NULL");
|
||||
|
||||
b.HasIndex("VaultId", "ChangeSequence")
|
||||
.HasDatabaseName("ix_credential_vault_id_change_sequence");
|
||||
|
||||
b.ToTable("credential", "dodo", t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_credential_version", "version >= 1");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DodoSSH.Domain.VaultKeyGrant", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -1008,6 +1089,18 @@ namespace DodoSSH.Infrastructure.Migrations
|
||||
b.Navigation("Team");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DodoSSH.Domain.VaultCredential", b =>
|
||||
{
|
||||
b.HasOne("DodoSSH.Domain.Vault", "Vault")
|
||||
.WithMany()
|
||||
.HasForeignKey("VaultId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_credential_vaults_vault_id");
|
||||
|
||||
b.Navigation("Vault");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DodoSSH.Domain.VaultKeyGrant", b =>
|
||||
{
|
||||
b.HasOne("DodoSSH.Domain.UserAccount", "RecipientUser")
|
||||
|
||||
Reference in New Issue
Block a user