Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add new API models (#2536)

Leendert de Borstfc1d9c15ca0a
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
index 35cba621b..ba59eff74 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
@@ -355,4 +355,39 @@ public enum ApiErrorCode
/// Two-factor authentication is not enabled for this account.
/// </summary>
TWO_FACTOR_NOT_ENABLED,
+
+ /// <summary>
+ /// No account has a signing key whose fingerprint is the given identity code.
+ /// </summary>
+ IDENTITY_CODE_NOT_FOUND,
+
+ /// <summary>
+ /// The account is already a member of the group.
+ /// </summary>
+ ALREADY_GROUP_MEMBER,
+
+ /// <summary>
+ /// The caller already owns the maximum number of shared groups.
+ /// </summary>
+ GROUP_LIMIT_REACHED,
+
+ /// <summary>
+ /// The caller has not certified the member's current signing key with their identity code.
+ /// </summary>
+ MEMBER_NOT_VERIFIED,
+
+ /// <summary>
+ /// The owner of a shared group cannot leave it; they delete it instead.
+ /// </summary>
+ GROUP_OWNER_CANNOT_LEAVE,
+
+ /// <summary>
+ /// The shared group still has other members or shared manifests, so it cannot be deleted yet.
+ /// </summary>
+ GROUP_NOT_EMPTY,
+
+ /// <summary>
+ /// The caller has not certified the inviter's current signing key with their identity code.
+ /// </summary>
+ INVITER_NOT_VERIFIED,
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs
index b8c86fae6..af5c3c2c5 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs
@@ -82,6 +82,26 @@ public enum AuthEventType
/// </summary>
SharedVaultDeletion = 51,
+ /// <summary>
+ /// Represents an admin taking a member's access to a shared manifest away, confirmed with the master password.
+ /// </summary>
+ SharedVaultAccessRevocation = 52,
+
+ /// <summary>
+ /// Represents an admin removing a member from a family, confirmed with the master password.
+ /// </summary>
+ FamilyMemberRemoval = 53,
+
+ /// <summary>
+ /// Represents a member giving up their own access to a shared manifest, confirmed with the master password.
+ /// </summary>
+ SharedVaultLeave = 54,
+
+ /// <summary>
+ /// Represents a member leaving a family, confirmed with the master password.
+ /// </summary>
+ FamilyLeave = 55,
+
/// <summary>
/// Represents a user account deletion event.
/// </summary>
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/AcceptInvitationRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/AcceptInvitationRequest.cs
new file mode 100644
index 000000000..c2128c530
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/AcceptInvitationRequest.cs
@@ -0,0 +1,23 @@
+//-----------------------------------------------------------------------
+// <copyright file="AcceptInvitationRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+using System.ComponentModel.DataAnnotations;
+
+/// <summary>
+/// Accept an invitation (POST /v2/Groups/invitations/{id}/accept).
+/// </summary>
+public class AcceptInvitationRequest
+{
+ /// <summary>
+ /// Gets or sets the invitee's own signature over the offered grant, which turns it into their grant. Required for an
+ /// invitation to a shared manifest, absent for one to join a group.
+ /// </summary>
+ [StringLength(255)]
+ public string? GrantSignature { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/CertifyKeyRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/CertifyKeyRequest.cs
new file mode 100644
index 000000000..f259ea756
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/CertifyKeyRequest.cs
@@ -0,0 +1,23 @@
+//-----------------------------------------------------------------------
+// <copyright file="CertifyKeyRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+/// <summary>
+/// Store the caller's certification of another user's signing key (POST /v2/Groups/certifications).
+/// </summary>
+public class CertifyKeyRequest
+{
+ /// <summary>Gets or sets the user the key belongs to.</summary>
+ public required string SubjectUserId { get; set; }
+
+ /// <summary>Gets or sets the certified signing public key (base64), which must be the subject's current one.</summary>
+ public required string SubjectSigningPublicKey { get; set; }
+
+ /// <summary>Gets or sets the caller's signature over the key certification message.</summary>
+ public required string Signature { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/CreateGroupResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/CreateGroupResponse.cs
new file mode 100644
index 000000000..49248bd88
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/CreateGroupResponse.cs
@@ -0,0 +1,17 @@
+//-----------------------------------------------------------------------
+// <copyright file="CreateGroupResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+/// <summary>
+/// The created group, as served by POST /v2/Groups.
+/// </summary>
+public class CreateGroupResponse
+{
+ /// <summary>Gets or sets the id of the new group.</summary>
+ public required Guid GroupId { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupInfo.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupInfo.cs
index 2058c769f..6c6ea60ce 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupInfo.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupInfo.cs
@@ -31,4 +31,9 @@ public class GroupInfo
/// Gets or sets the group's members.
/// </summary>
public List<GroupMemberInfo> Members { get; set; } = [];
+
+ /// <summary>
+ /// Gets or sets the open invitations to join this group, for admins.
+ /// </summary>
+ public List<SentManifestInvitation> PendingJoinInvitations { get; set; } = [];
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupMemberInfo.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupMemberInfo.cs
index 5a15efe2d..6e990b9fa 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupMemberInfo.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupMemberInfo.cs
@@ -32,4 +32,7 @@ public class GroupMemberInfo
/// <summary>Gets or sets the member's signing public key, which <see cref="AccountPublicKeySignature"/> verifies under.</summary>
public string? SigningPublicKey { get; set; }
+
+ /// <summary>Gets or sets the caller's own certification of <see cref="SigningPublicKey"/>, for admins; the client verifies it.</summary>
+ public string? KeyCertification { get; set; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupOverviewResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupOverviewResponse.cs
index 33c312e25..5b40d12da 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupOverviewResponse.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/GroupOverviewResponse.cs
@@ -12,6 +12,11 @@ namespace AliasVault.Shared.Models.WebApi.V2.Groups;
/// </summary>
public class GroupOverviewResponse
{
+ /// <summary>
+ /// Gets or sets the caller's own user id, which the certifications and grants their client signs name.
+ /// </summary>
+ public required string UserId { get; set; }
+
/// <summary>
/// Gets or sets the shared groups the caller belongs to, with each groups metadata.
/// </summary>
@@ -21,4 +26,9 @@ public class GroupOverviewResponse
/// Gets or sets the offers of access to a shared manifest addressed to the caller, awaiting their accept or decline.
/// </summary>
public List<ReceivedManifestInvitation> ReceivedInvitations { get; set; } = [];
+
+ /// <summary>
+ /// Gets or sets the invitations to join a group addressed to the caller.
+ /// </summary>
+ public List<ReceivedGroupInvitation> ReceivedGroupInvitations { get; set; } = [];
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/IdentityCodeLookupRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/IdentityCodeLookupRequest.cs
new file mode 100644
index 000000000..163533d68
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/IdentityCodeLookupRequest.cs
@@ -0,0 +1,17 @@
+//-----------------------------------------------------------------------
+// <copyright file="IdentityCodeLookupRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+/// <summary>
+/// Look up the account an identity code belongs to (POST /v2/Groups/{groupId}/members/lookup).
+/// </summary>
+public class IdentityCodeLookupRequest
+{
+ /// <summary>Gets or sets the identity code the invitee gave the admin; separators are ignored.</summary>
+ public required string Code { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/IdentityCodeLookupResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/IdentityCodeLookupResponse.cs
new file mode 100644
index 000000000..411747d79
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/IdentityCodeLookupResponse.cs
@@ -0,0 +1,23 @@
+//-----------------------------------------------------------------------
+// <copyright file="IdentityCodeLookupResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+/// <summary>
+/// The account an identity code belongs to. The client checks <see cref="SigningPublicKey"/> against the code itself.
+/// </summary>
+public class IdentityCodeLookupResponse
+{
+ /// <summary>Gets or sets the account's user id.</summary>
+ public required string UserId { get; set; }
+
+ /// <summary>Gets or sets the account's username.</summary>
+ public required string Username { get; set; }
+
+ /// <summary>Gets or sets the account's signing public key (base64), whose fingerprint is the code.</summary>
+ public required string SigningPublicKey { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/InviteToGroupRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/InviteToGroupRequest.cs
new file mode 100644
index 000000000..17566ba09
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/InviteToGroupRequest.cs
@@ -0,0 +1,17 @@
+//-----------------------------------------------------------------------
+// <copyright file="InviteToGroupRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+/// <summary>
+/// Invite an account to join a group (POST /v2/Groups/{groupId}/invitations).
+/// </summary>
+public class InviteToGroupRequest
+{
+ /// <summary>Gets or sets the account to invite, as found by its identity code.</summary>
+ public required string UserId { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/KeyCertificationInfo.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/KeyCertificationInfo.cs
new file mode 100644
index 000000000..db23a9f27
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/KeyCertificationInfo.cs
@@ -0,0 +1,23 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyCertificationInfo.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+/// <summary>
+/// One key certification the caller made, as served by GET /v2/Groups/certifications.
+/// </summary>
+public class KeyCertificationInfo
+{
+ /// <summary>Gets or sets the user whose key was certified.</summary>
+ public required string SubjectUserId { get; set; }
+
+ /// <summary>Gets or sets the certified signing public key (base64).</summary>
+ public required string SubjectSigningPublicKey { get; set; }
+
+ /// <summary>Gets or sets the caller's signature over the certification, for the caller's client to check before signing it again.</summary>
+ public required string Signature { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/DeleteSharedManifestRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/PasswordConfirmationRequest.cs
similarity index 78%
rename from apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/DeleteSharedManifestRequest.cs
rename to apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/PasswordConfirmationRequest.cs
index 165120463..2757c3681 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/DeleteSharedManifestRequest.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/PasswordConfirmationRequest.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="DeleteSharedManifestRequest.cs" company="aliasvault">
+// <copyright file="PasswordConfirmationRequest.cs" company="aliasvault">
// Copyright (c) aliasvault. All rights reserved.
// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
// </copyright>
@@ -8,9 +8,9 @@
namespace AliasVault.Shared.Models.WebApi.V2.Groups;
/// <summary>
-/// Request for POST /v2/Groups/{groupId}/manifests/{manifestId}/delete/confirm.
+/// The SRP proof of the caller's master password, for the sharing actions that are confirmed with it.
/// </summary>
-public class DeleteSharedManifestRequest
+public class PasswordConfirmationRequest
{
/// <summary>Gets or sets the client's public ephemeral of the SRP handshake started by the initiate endpoint.</summary>
public required string ClientPublicEphemeral { get; set; }
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ReceivedGroupInvitation.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ReceivedGroupInvitation.cs
new file mode 100644
index 000000000..9b386fcec
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ReceivedGroupInvitation.cs
@@ -0,0 +1,35 @@
+//-----------------------------------------------------------------------
+// <copyright file="ReceivedGroupInvitation.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Groups;
+
+/// <summary>
+/// An open invitation to join a group, addressed to the caller.
+/// </summary>
+public class ReceivedGroupInvitation
+{
+ /// <summary>Gets or sets the invitation id.</summary>
+ public required Guid Id { get; set; }
+
+ /// <summary>Gets or sets the group it invites to.</summary>
+ public required Guid GroupId { get; set; }
+
+ /// <summary>Gets or sets the admin who sent it.</summary>
+ public required string InviterUserId { get; set; }
+
+ /// <summary>Gets or sets the username of the admin who sent it.</summary>
+ public required string InviterUsername { get; set; }
+
+ /// <summary>Gets or sets when it was sent.</summary>
+ public required DateTime CreatedAt { get; set; }
+
+ /// <summary>Gets or sets the inviter's current signing public key, which the invitee certifies with the inviter's identity code.</summary>
+ public string? InviterSigningPublicKey { get; set; }
+
+ /// <summary>Gets or sets the invitee's own certification of <see cref="InviterSigningPublicKey"/>, when they certified the inviter before.</summary>
+ public string? InviterCertification { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ReceivedManifestInvitation.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ReceivedManifestInvitation.cs
index 99ad162ea..0cb3b464a 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ReceivedManifestInvitation.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ReceivedManifestInvitation.cs
@@ -30,6 +30,15 @@ public class ReceivedManifestInvitation
/// <summary>Gets or sets when it was sent.</summary>
public required DateTime CreatedAt { get; set; }
+ /// <summary>Gets or sets the vault's VEK version the offer was encrypted under.</summary>
+ public int KeyVersion { get; set; }
+
+ /// <summary>Gets or sets the vault's VEK, encrypted for <see cref="RecipientAccountPublicKey"/>; the invitee signs it as their grant when accepting.</summary>
+ public string? EncryptedVek { get; set; }
+
+ /// <summary>Gets or sets the inviter's signature over the offered grant, verifying under <see cref="SignerPublicKey"/>.</summary>
+ public string? GrantSignature { get; set; }
+
/// <summary>Gets or sets the encrypted name of the vault.</summary>
public string? EncryptedName { get; set; }
@@ -44,4 +53,7 @@ public class ReceivedManifestInvitation
/// <summary>Gets or sets the algorithm the offer was encrypted with, as a VaultKeyAlgorithm token.</summary>
public required string Algorithm { get; set; }
+
+ /// <summary>Gets or sets the invitee's own certification of <see cref="SignerPublicKey"/>, when they certified the inviter before.</summary>
+ public string? InviterCertification { get; set; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/CertificationRewrap.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/CertificationRewrap.cs
new file mode 100644
index 000000000..eb11bed96
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/CertificationRewrap.cs
@@ -0,0 +1,32 @@
+//-----------------------------------------------------------------------
+// <copyright file="CertificationRewrap.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using System.ComponentModel.DataAnnotations;
+
+/// <summary>
+/// A key certification the caller made, signed again with the new signing key.
+/// </summary>
+public class CertificationRewrap
+{
+ /// <summary>
+ /// Gets or sets the user whose key was certified.
+ /// </summary>
+ public required string SubjectUserId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the certified signing public key (base64), as stored.
+ /// </summary>
+ public required string SubjectSigningPublicKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the caller's signature over the key certification message, made with the new signing key.
+ /// </summary>
+ [StringLength(255)]
+ public required string Signature { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationRequest.cs
index 08e7f82bc..7936d5d08 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationRequest.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationRequest.cs
@@ -64,6 +64,11 @@ public class KeyRotationRequest : IFrameBody
/// </summary>
public List<GrantRewrap> Grants { get; set; } = [];
+ /// <summary>
+ /// Gets or sets every key certification the caller made, signed again with the new signing key.
+ /// </summary>
+ public List<CertificationRewrap> Certifications { get; set; } = [];
+
/// <inheritdoc />
[JsonIgnore]
public IEnumerable<IFramePart> FrameParts => new IFramePart[] { Manifest }.Concat(Buckets);
diff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/SigningTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/SigningTests.cs
new file mode 100644
index 000000000..354fc5ab9
--- /dev/null
+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/SigningTests.cs
@@ -0,0 +1,42 @@
+//-----------------------------------------------------------------------
+// <copyright file="SigningTests.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.UnitTests.Utilities;
+
+using AliasVault.Cryptography;
+
+/// <summary>
+/// Known-answer tests shared with the Rust core's signing.rs; a changed output means server and clients disagree.
+/// </summary>
+public class SigningTests
+{
+ /// <summary>
+ /// The public key of the private seed 0x00..0x1f, as in signing.rs.
+ /// </summary>
+ private const string PublicKeyVector = "A6EHv/POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg=";
+
+ /// <summary>
+ /// The fingerprint equals the Rust core's FINGERPRINT_VECTOR without its dashes.
+ /// </summary>
+ [Test]
+ public void FingerprintKnownAnswer()
+ {
+ Assert.That(Signing.Fingerprint(PublicKeyVector), Is.EqualTo("09196981526592105908"));
+ Assert.That(Signing.Fingerprint("not base64!"), Is.Null);
+ Assert.That(Signing.NormalizeFingerprint(" 0919-6981 5265-9210 5908 "), Is.EqualTo("09196981526592105908"));
+ }
+
+ /// <summary>
+ /// The key certification message equals the Rust core's KEY_CERTIFICATION_MESSAGE_VECTOR.
+ /// </summary>
+ [Test]
+ public void KeyCertificationMessageKnownAnswer()
+ {
+ var message = Signing.KeyCertificationMessage("user-1", "user-2", PublicKeyVector);
+ Assert.That(Convert.ToHexStringLower(message), Is.EqualTo("00000023616c6961737661756c742f76312f7369672f6b65792d63657274696669636174696f6e00000006757365722d3100000006757365722d320000002c41364548762f504f454c3464634e3059353076416d57666b316a436270513166486479475a424a564d62673d"));
+ }
+}
diff --git a/apps/server/Utilities/AliasVault.Cryptography/Signing.cs b/apps/server/Utilities/AliasVault.Cryptography/Signing.cs
index aa54c4a23..90e1c9f6e 100644
--- a/apps/server/Utilities/AliasVault.Cryptography/Signing.cs
+++ b/apps/server/Utilities/AliasVault.Cryptography/Signing.cs
@@ -42,6 +42,21 @@ public static class Signing
/// </summary>
public const string SigningKeyRotationLabel = "aliasvault/v1/sig/signing-key-rotation";
+ /// <summary>
+ /// The label of a key certification: one user vouching that a signing public key belongs to another user.
+ /// </summary>
+ public const string KeyCertificationLabel = "aliasvault/v1/sig/key-certification";
+
+ /// <summary>
+ /// The label under which a signing public key is hashed into its fingerprint, the user's identity code (the family code in the apps).
+ /// </summary>
+ public const string FingerprintLabel = "aliasvault/v1/signing-key-fingerprint";
+
+ /// <summary>
+ /// The decimal digits in a fingerprint (the value is reduced modulo 10^20).
+ /// </summary>
+ public const int FingerprintDigits = 20;
+
/// <summary>
/// Builds the bytes a signature covers: the label and each field, each prefixed with its length as a big-endian uint.
/// </summary>
@@ -115,6 +130,47 @@ public static class Signing
return SignedMessage(SigningKeyRotationLabel, Utf8(userId), Utf8(newSigningPublicKey));
}
+ /// <summary>
+ /// Builds the signed message of a key certification: the certifier vouches that a signing public key belongs to the subject.
+ /// </summary>
+ /// <param name="certifierUserId">The user vouching for the key.</param>
+ /// <param name="subjectUserId">The user the key belongs to.</param>
+ /// <param name="subjectSigningPublicKey">The certified signing public key (base64).</param>
+ /// <returns>The message bytes.</returns>
+ public static byte[] KeyCertificationMessage(string certifierUserId, string subjectUserId, string subjectSigningPublicKey)
+ {
+ return SignedMessage(KeyCertificationLabel, Utf8(certifierUserId), Utf8(subjectUserId), Utf8(subjectSigningPublicKey));
+ }
+
+ /// <summary>
+ /// The fingerprint of a signing public key as <see cref="FingerprintDigits"/> digits without separators, the same digits the
+ /// Rust core prints in groups of four. Null for a value that is not an Ed25519 public key.
+ /// </summary>
+ /// <param name="publicKeyBase64">The signing public key (base64).</param>
+ /// <returns>The fingerprint digits, or null.</returns>
+ public static string? Fingerprint(string? publicKeyBase64)
+ {
+ var publicKey = TryDecode(publicKeyBase64, Ed25519.PublicKeySize);
+ if (publicKey == null)
+ {
+ return null;
+ }
+
+ var digest = System.Security.Cryptography.SHA256.HashData(SignedMessage(FingerprintLabel, publicKey));
+ var value = BinaryPrimitives.ReadUInt128BigEndian(digest) % UInt128.Parse("100000000000000000000", System.Globalization.CultureInfo.InvariantCulture);
+ return value.ToString("D" + FingerprintDigits, System.Globalization.CultureInfo.InvariantCulture);
+ }
+
+ /// <summary>
+ /// The digits of a code a user typed, ignoring spaces and dashes.
+ /// </summary>
+ /// <param name="code">The typed code.</param>
+ /// <returns>Only its digits.</returns>
+ public static string NormalizeFingerprint(string? code)
+ {
+ return new string((code ?? string.Empty).Where(char.IsAsciiDigit).ToArray());
+ }
+
/// <summary>
/// Whether a base64 signature over a message verifies under a base64 Ed25519 public key.
/// </summary>