Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add family sharing invite manifest name signing (#2469)
Leendert de Borst6984a0c7bfcd
diff --git a/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs b/apps/server/AliasVault.Api/Controllers/V2/GroupsController.csindex 1063329de..361bb2177 100644--- a/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs@@ -288,7 +288,8 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Use}var signerPublicKey = await GrantHelper.GetPrimarySigningKeyAsync(context, me.Id);- if (!Signing.Verify(signerPublicKey, Signing.GrantMessage(manifestId, manifestKeyVersion.Value, me.Id, recipientPublicKey, model.Algorithm, model.Grant.EncryptedVek), model.Grant.Signature))+ var nameIsSigned = model.Grant.EncryptedName is null || Signing.Verify(signerPublicKey, Signing.InvitationNameMessage(manifestId, me.Id, recipientPublicKey, model.Grant.EncryptedName), model.Grant.EncryptedNameSignature);+ if (!nameIsSigned || !Signing.Verify(signerPublicKey, Signing.GrantMessage(manifestId, manifestKeyVersion.Value, me.Id, recipientPublicKey, model.Algorithm, model.Grant.EncryptedVek), model.Grant.Signature)){return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.SIGNATURE_INVALID, 400));}@@ -316,6 +317,7 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, UseVaultManifestId = manifestId,EncryptedVek = model.Grant.EncryptedVek,EncryptedName = model.Grant.EncryptedName,+ EncryptedNameSignature = model.Grant.EncryptedName is null ? null : model.Grant.EncryptedNameSignature,UserGrantKeyId = model.Grant.RecipientPublicKeyId,GrantSignature = model.Grant.Signature,GrantSignerPublicKey = signerPublicKey,@@ -622,6 +624,7 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Use// The encrypted copy has become the grant, so it stops being a second copy of the key lying around.invitation.EncryptedVek = null;invitation.EncryptedName = null;+ invitation.EncryptedNameSignature = null;invitation.UserGrantKeyId = null;invitation.GrantSignature = null;invitation.GrantSignerPublicKey = null;@@ -721,8 +724,11 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Usei.GroupId,ManifestId = i.VaultManifestId!.Value,InviterUsername = i.Inviter.UserName ?? string.Empty,+ i.InviterUserId,i.CreatedAt,i.EncryptedName,+ i.EncryptedNameSignature,+ i.GrantSignerPublicKey,RecipientPublicKey = i.UserGrantKey != null ? i.UserGrantKey.PublicKey : null,}).ToListAsync();@@ -745,8 +751,11 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, UseGroupId = i.GroupId,ManifestId = i.ManifestId,InviterUsername = i.InviterUsername,+ InviterUserId = i.InviterUserId,CreatedAt = i.CreatedAt,EncryptedName = i.EncryptedName,+ EncryptedNameSignature = i.EncryptedNameSignature,+ SignerPublicKey = i.GrantSignerPublicKey,RecipientPublicKey = i.RecipientPublicKey,})];}@@ -761,6 +770,7 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Useinvitation.State = state;invitation.EncryptedVek = null;invitation.EncryptedName = null;+ invitation.EncryptedNameSignature = null;invitation.UserGrantKeyId = null;invitation.GrantSignature = null;invitation.GrantSignerPublicKey = null;diff --git a/apps/server/Databases/AliasServerDb/GroupInvitation.cs b/apps/server/Databases/AliasServerDb/GroupInvitation.csindex f736862fb..044b80c4f 100644--- a/apps/server/Databases/AliasServerDb/GroupInvitation.cs+++ b/apps/server/Databases/AliasServerDb/GroupInvitation.cs@@ -79,6 +79,12 @@ public class GroupInvitation/// </summary>public string? EncryptedName { get; set; }+ /// <summary>+ /// Gets or sets the inviter's signature over <see cref="EncryptedName"/>, verifying under <see cref="GrantSignerPublicKey"/>.+ /// </summary>+ [StringLength(255)]+ public string? EncryptedNameSignature { get; set; }+/// <summary>/// Gets or sets the invitee's account keypair (<see cref="UserGrantKey"/>) the <see cref="EncryptedVek"/> was encrypted to./// </summary>diff --git a/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.Designer.csindex 0b600a540..cf136f2ca 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.Designer.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.Designer.cs@@ -720,6 +720,10 @@ namespace AliasServerDb.Migrationsb.Property<string>("EncryptedName").HasColumnType("text");+ b.Property<string>("EncryptedNameSignature")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");+b.Property<string>("EncryptedVek").HasColumnType("text");diff --git a/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.cs b/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.csindex 997450a52..b5c921a32 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20261005080213_AddAccountSigningKeys.cs@@ -40,6 +40,13 @@ namespace AliasServerDb.Migrationsnullable: false,defaultValue: "");+ migrationBuilder.AddColumn<string>(+ name: "EncryptedNameSignature",+ table: "GroupInvitations",+ type: "character varying(255)",+ maxLength: 255,+ nullable: true);+migrationBuilder.AddColumn<string>(name: "GrantSignature",table: "GroupInvitations",@@ -109,6 +116,10 @@ namespace AliasServerDb.Migrationsname: "PublicKeySignature",table: "UserGrantKeys");+ migrationBuilder.DropColumn(+ name: "EncryptedNameSignature",+ table: "GroupInvitations");+migrationBuilder.DropColumn(name: "GrantSignature",table: "GroupInvitations");diff --git a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.csindex 9f7482453..88ff14e81 100644--- a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs@@ -182,16 +182,16 @@ namespace AliasServerDb.Migrations.HasMaxLength(45).HasColumnType("character varying(45)");- b.Property<string>("PreviousTokenValue")- .HasMaxLength(255)- .HasColumnType("character varying(255)");+ b.Property<string>("PreviousTokenHash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");- b.Property<string>("UserId")+ b.Property<string>("TokenHash").IsRequired()- .HasMaxLength(255)- .HasColumnType("character varying(255)");+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");- b.Property<string>("Value")+ b.Property<string>("UserId").IsRequired().HasMaxLength(255).HasColumnType("character varying(255)");@@ -717,6 +717,10 @@ namespace AliasServerDb.Migrationsb.Property<string>("EncryptedName").HasColumnType("text");+ b.Property<string>("EncryptedNameSignature")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");+b.Property<string>("EncryptedVek").HasColumnType("text");diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ManifestGrant.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ManifestGrant.csindex 70352ceb1..76c972652 100644--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ManifestGrant.cs+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Groups/ManifestGrant.cs@@ -26,6 +26,10 @@ public class ManifestGrant/// <summary>Gets or sets the vault's name encrypted with the same public key, null when the client encrypted none.</summary>public string? EncryptedName { get; set; }+ /// <summary>Gets or sets the caller's signature over <see cref="EncryptedName"/>, required when a name is sent.</summary>+ [StringLength(255)]+ public string? EncryptedNameSignature { get; set; }+/// <summary>Gets or sets the caller's signature over the grant.</summary>[StringLength(255)]public required string Signature { 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.csindex 0637ea5ed..043d559c4 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@@ -24,12 +24,21 @@ public class ReceivedManifestInvitation/// <summary>Gets or sets the username of the member who sent it.</summary>public required string InviterUsername { get; set; }+ /// <summary>Gets or sets the user id of the member who sent it, which <see cref="EncryptedNameSignature"/> names.</summary>+ public required string InviterUserId { get; set; }+/// <summary>Gets or sets when it was sent.</summary>public required DateTime CreatedAt { get; set; }/// <summary>Gets or sets the encrypted name of the vault.</summary>public string? EncryptedName { get; set; }+ /// <summary>Gets or sets the inviter's signature over <see cref="EncryptedName"/>.</summary>+ public string? EncryptedNameSignature { get; set; }++ /// <summary>Gets or sets the inviter's signing public key that <see cref="EncryptedNameSignature"/> verifies under.</summary>+ public string? SignerPublicKey { get; set; }+/// <summary>Gets or sets the public half of the recipient's keypair the offer was encrypted to.</summary>public string? RecipientPublicKey { get; set; }}diff --git a/apps/server/Utilities/AliasVault.Cryptography/Signing.cs b/apps/server/Utilities/AliasVault.Cryptography/Signing.csindex d484b0094..ec1988282 100644--- a/apps/server/Utilities/AliasVault.Cryptography/Signing.cs+++ b/apps/server/Utilities/AliasVault.Cryptography/Signing.cs@@ -32,6 +32,11 @@ public static class Signing/// </summary>public const string DeliveryKeyLabel = "aliasvault/v1/sig/delivery-key";+ /// <summary>+ /// The label of the vault name an invitation carries, signed by the inviter.+ /// </summary>+ public const string InvitationNameLabel = "aliasvault/v1/sig/invitation-name";+/// <summary>/// Builds the bytes a signature covers: the label and each field, each prefixed with its length as a big-endian uint./// </summary>@@ -68,6 +73,19 @@ public static class Signingreturn SignedMessage(GrantLabel, Utf8(manifestId.ToString()), Utf8(keyVersion.ToString(System.Globalization.CultureInfo.InvariantCulture)), Utf8(signerUserId), Utf8(recipientPublicKey), Utf8(algorithm), Utf8(encryptedVek));}+ /// <summary>+ /// Builds the signed message of the vault name an invitation carries.+ /// </summary>+ /// <param name="manifestId">The manifest the invitation is for.</param>+ /// <param name="signerUserId">The inviter.</param>+ /// <param name="recipientPublicKey">The recipient public key (JWK) the name is encrypted for, as stored.</param>+ /// <param name="encryptedName">The encrypted name.</param>+ /// <returns>The message bytes.</returns>+ public static byte[] InvitationNameMessage(Guid manifestId, string signerUserId, string recipientPublicKey, string encryptedName)+ {+ return SignedMessage(InvitationNameLabel, Utf8(manifestId.ToString()), Utf8(signerUserId), Utf8(recipientPublicKey), Utf8(encryptedName));+ }+/// <summary>/// Builds the signed message of a delivery key publish, bound to the manifest revision the write is based on so it/// cannot be replayed in a later write.diff --git a/core/models/src/webapi/Groups.ts b/core/models/src/webapi/Groups.tsindex d85df7e44..6137c6696 100644--- a/core/models/src/webapi/Groups.ts+++ b/core/models/src/webapi/Groups.ts@@ -40,8 +40,11 @@ export type ReceivedManifestInvitation = {groupId: string;manifestId: string;inviterUsername: string;+ inviterUserId: string;createdAt: string;encryptedName: string | null;+ encryptedNameSignature: string | null;+ signerPublicKey: string | null;recipientPublicKey: string | null;}@@ -110,6 +113,7 @@ export type ManifestGrant = {recipientPublicKeyId: string;encryptedVek: string;encryptedName?: string | null;+ encryptedNameSignature?: string | null;signature: string;}diff --git a/core/rust/src/crypto/signing.rs b/core/rust/src/crypto/signing.rsindex 09d02c5c7..28aa563c8 100644--- a/core/rust/src/crypto/signing.rs+++ b/core/rust/src/crypto/signing.rs@@ -21,6 +21,9 @@ pub const GRANT_LABEL: &str = "aliasvault/v1/sig/grant";/// The label of a manifest's mail delivery public key, signed by whoever published it.pub const DELIVERY_KEY_LABEL: &str = "aliasvault/v1/sig/delivery-key";+/// The label of the vault name an invitation carries, signed by the inviter.+pub const INVITATION_NAME_LABEL: &str = "aliasvault/v1/sig/invitation-name";+/// A new signing keypair, both halves base64: the 32-byte public key and the 32-byte private seed.#[derive(Clone, Serialize, Deserialize, Zeroize, ZeroizeOnDrop)]#[serde(rename_all = "camelCase")]@@ -66,6 +69,11 @@ pub fn grant_message(manifest_id: &str, key_version: i64, signer_user_id: &str,signed_message(GRANT_LABEL, &[manifest_id.as_bytes(), key_version.as_bytes(), signer_user_id.as_bytes(), recipient_public_key.as_bytes(), algorithm.as_bytes(), encrypted_vek.as_bytes()])}+/// The signed message of the vault name an invitation carries, encrypted for `recipient_public_key`.+pub fn invitation_name_message(manifest_id: &str, signer_user_id: &str, recipient_public_key: &str, encrypted_name: &str) -> Vec<u8> {+ signed_message(INVITATION_NAME_LABEL, &[manifest_id.to_ascii_lowercase().as_bytes(), signer_user_id.as_bytes(), recipient_public_key.as_bytes(), encrypted_name.as_bytes()])+}+/// The signed message of a delivery key publish, bound to the revision the write is based on so it cannot be replayed.pub fn delivery_key_message(manifest_id: &str, public_key: &str, current_revision: i64) -> Vec<u8> {signed_message(DELIVERY_KEY_LABEL, &[manifest_id.to_ascii_lowercase().as_bytes(), public_key.as_bytes(), current_revision.to_string().as_bytes()])@@ -110,8 +118,8 @@ mod tests {base64_encode(&(0u8..32).collect::<Vec<u8>>())}- /// Known-answer vector for the message encoding. The server builds the same bytes and checks this exact- /// signature (`SigningTests` in the server unit tests); a changed output means stored signatures no longer verify. Never regenerate it.+ /// Known-answer vector for the message encoding, which the server's `Signing.cs` builds byte for byte. A changed output+ /// means stored signatures no longer verify. Never regenerate it.#[test]fn signed_message_known_answer() {let message = signed_message(ACCOUNT_PUBLIC_KEY_LABEL, &[b"{\"kty\":\"RSA\"}"]);@@ -124,15 +132,18 @@ mod tests {const PUBLIC_KEY_VECTOR: &str = "A6EHv/POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg=";const SIGNATURE_VECTOR: &str = "twY5wx2bX5kesFEjJa+ZUYOpw4Hs3hqFUpbWC4KbVRVgragIilho+vCl9Haik3F/a2vLcAoCtJssesL4wAaxDg==";- /// Known-answer vectors for the grant and delivery key messages, which the server builds too (`SigningTests`). The+ /// Known-answer vectors for the grant, delivery key and invitation name messages, which `Signing.cs` builds too. The/// manifest id is lowercased, as the server prints a GUID. Never regenerate them.#[test]fn grant_and_delivery_key_messages_known_answer() {let manifest_id = "0A1B2C3D-0000-0000-0000-000000000001";assert_eq!(crate::common::encoding::hex_encode_lower(&grant_message(manifest_id, 3, "user-1", "{\"kty\":\"RSA\"}", "rsa-oaep-sha256", "dmVr")), GRANT_MESSAGE_VECTOR);assert_eq!(crate::common::encoding::hex_encode_lower(&delivery_key_message(manifest_id, "{\"kty\":\"RSA\"}", 42)), DELIVERY_KEY_MESSAGE_VECTOR);+ assert_eq!(crate::common::encoding::hex_encode_lower(&invitation_name_message(manifest_id, "user-1", "{\"kty\":\"RSA\"}", "bmFtZQ==")), INVITATION_NAME_MESSAGE_VECTOR);}+ const INVITATION_NAME_MESSAGE_VECTOR: &str = "00000021616c6961737661756c742f76312f7369672f696e7669746174696f6e2d6e616d650000002430613162326333642d303030302d303030302d303030302d30303030303030303030303100000006757365722d310000000d7b226b7479223a22525341227d00000008626d46745a513d3d";+const GRANT_MESSAGE_VECTOR: &str = "00000017616c6961737661756c742f76312f7369672f6772616e740000002430613162326333642d303030302d303030302d303030302d303030303030303030303031000000013300000006757365722d310000000d7b226b7479223a22525341227d0000000f7273612d6f6165702d73686132353600000004646d5672";const DELIVERY_KEY_MESSAGE_VECTOR: &str = "0000001e616c6961737661756c742f76312f7369672f64656c69766572792d6b65790000002430613162326333642d303030302d303030302d303030302d3030303030303030303030310000000d7b226b7479223a22525341227d000000023432";diff --git a/core/rust/src/vault_sync/sharing.rs b/core/rust/src/vault_sync/sharing.rsindex 39edd02c2..0cdbba6f8 100644--- a/core/rust/src/vault_sync/sharing.rs+++ b/core/rust/src/vault_sync/sharing.rs@@ -95,6 +95,7 @@ struct ManifestGrant {recipient_public_key_id: String,encrypted_vek: String,encrypted_name: Option<String>,+ encrypted_name_signature: Option<String>,signature: String,}@@ -337,13 +338,16 @@ async fn invite_to_shared_manifest(ctx: &mut Ctx) -> Outcome {// The name travels encrypted in the invitation, so the recipient sees what they are invited to; one too long to fit is left out.let name = db::manifest_display_names(&ctx.host).await?.get(&id_key(&manifest.manifest_id)).cloned().filter(|name| !name.is_empty() && name.len() <= MAX_SHARED_MANIFEST_NAME_BYTES);+ let own_user_id = own_user_id(ctx, &group)?;let encrypted_vek = keys::encrypt_manifest_vek(&manifest_vek, &manifest.manifest_id, &recipient_public_key)?;+ let encrypted_name = name.map(|name| crypto::encrypt_with_public_key(name.as_bytes(), &recipient_public_key)).transpose()?;let grant = ManifestGrant {recipient_user_id: member.user_id.clone(),recipient_public_key_id,- signature: crypto::signing::sign(&signing_key, &crypto::signing::grant_message(&manifest.manifest_id, manifest.key_version, &own_user_id(ctx, &group)?, &recipient_public_key, ALGORITHM_RSA_OAEP_SHA256, &encrypted_vek))?,+ signature: crypto::signing::sign(&signing_key, &crypto::signing::grant_message(&manifest.manifest_id, manifest.key_version, &own_user_id, &recipient_public_key, ALGORITHM_RSA_OAEP_SHA256, &encrypted_vek))?,+ encrypted_name_signature: encrypted_name.as_deref().map(|name| crypto::signing::sign(&signing_key, &crypto::signing::invitation_name_message(&manifest.manifest_id, &own_user_id, &recipient_public_key, name))).transpose()?,encrypted_vek,- encrypted_name: name.map(|name| crypto::encrypt_with_public_key(name.as_bytes(), &recipient_public_key)).transpose()?,+ encrypted_name,};http::post_no_content(