Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Store encrypted manifests as bytea without base64 overhead (#2159)
Leendert de Borstd549576d5534
diff --git a/apps/server/AliasVault.Api/Controllers/V2/SharingController.cs b/apps/server/AliasVault.Api/Controllers/V2/SharingController.csindex 52fe15a65..96f07301c 100644--- a/apps/server/AliasVault.Api/Controllers/V2/SharingController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/SharingController.cs@@ -99,6 +99,12 @@ public class SharingController(IAliasServerDbContextFactory dbContextFactory, Usreturn BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.MANIFEST_ID_INVALID, 400));}+ // Ciphertext travels base64-encoded but is stored as raw bytes.+ if (!CiphertextHelper.TryDecode(model.ManifestBlob, out var manifestBlob))+ {+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_ERROR, 400));+ }+var ownerGroupId = await GroupHelper.ResolveShareTargetGroupIdAsync(context, me.Id, model.GroupId);if (ownerGroupId is null){@@ -118,10 +124,10 @@ public class SharingController(IAliasServerDbContextFactory dbContextFactory, UsOwnerGroupId = ownerGroupId.Value,Name = model.Name,StorageFormat = ManifestFormat,- ManifestBlob = model.ManifestBlob,+ ManifestBlob = manifestBlob,ManifestCiphertextHash = model.ManifestCiphertextHash,RevisionNumber = 1,- FileSize = FileHelper.Base64StringToKilobytes(model.ManifestBlob),+ FileSize = FileHelper.BytesToKilobytes(manifestBlob.Length),Client = clientHeader,CreatedAt = timeProvider.UtcNow,UpdatedAt = timeProvider.UtcNow,diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultController.csindex 1fa88ba1b..0bea2c69e 100644--- a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs@@ -121,7 +121,7 @@ public class VaultController({ManifestId = x.ManifestId,Category = x.Category,- Blob = x.EncryptedData,+ Blob = Convert.ToBase64String(x.EncryptedData),CiphertextHash = x.CiphertextHash,Revision = x.RevisionNumber,})@@ -152,7 +152,7 @@ public class VaultController({ManifestId = m.ManifestId,Name = m.Name,- Blob = m.ManifestBlob,+ Blob = m.ManifestBlob != null ? Convert.ToBase64String(m.ManifestBlob) : null,CiphertextHash = m.ManifestCiphertextHash,Revision = m.RevisionNumber,BlobReferences = refsByManifest.TryGetValue(m.ManifestId, out var refs) ? refs : [],@@ -211,7 +211,7 @@ public class VaultController({ManifestId = latest.ManifestId,Name = latest.Name,- Blob = latest.ManifestBlob,+ Blob = latest.ManifestBlob != null ? Convert.ToBase64String(latest.ManifestBlob) : null,CiphertextHash = latest.ManifestCiphertextHash,Revision = latest.RevisionNumber,BlobReferences = blobRefs,@@ -268,6 +268,29 @@ public class VaultController(return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_NOT_UP_TO_DATE, 400));}+ // Decode base64-encoded ciphertexts into raw bytes.+ var manifestBlobs = new Dictionary<Guid, byte[]>();+ foreach (var mw in model.Manifests)+ {+ if (!CiphertextHelper.TryDecode(mw.ManifestBlob, out var manifestBlob))+ {+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_ERROR, 400));+ }++ manifestBlobs[mw.ManifestId] = manifestBlob;+ }++ var bucketBlobs = new Dictionary<(Guid ManifestId, VaultDataBucketCategory Category), byte[]>();+ foreach (var bucket in model.Buckets.Where(b => !string.IsNullOrEmpty(b.Blob)))+ {+ if (!CiphertextHelper.TryDecode(bucket.Blob, out var bucketBlob))+ {+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_ERROR, 400));+ }++ bucketBlobs[(bucket.ManifestId, bucket.Category)] = bucketBlob;+ }+var resolved = new List<(ManifestWrite Write, VaultManifest Row)>();foreach (var mw in model.Manifests){@@ -408,13 +431,13 @@ public class VaultController(row.VaultBlob = null;row.StorageFormat = ManifestFormat;- row.ManifestBlob = mw.ManifestBlob;+ row.ManifestBlob = manifestBlobs[mw.ManifestId];row.ManifestCiphertextHash = mw.ManifestCiphertextHash;// Manifest revisions carry no data-model version, so we null it instead.row.Version = null;row.RevisionNumber = mw.CurrentRevision + 1;- row.FileSize = FileHelper.Base64StringToKilobytes(mw.ManifestBlob);+ row.FileSize = FileHelper.BytesToKilobytes(row.ManifestBlob.Length);row.CredentialsCount = mw.CredentialsCount;row.Client = clientHeader;row.UpdatedAt = timeProvider.UtcNow;@@ -507,12 +530,12 @@ public class VaultController(var newBucketRevisions = new List<BucketRevision>();foreach (var bucket in model.Buckets){- if (string.IsNullOrEmpty(bucket.Blob))+ if (!bucketBlobs.TryGetValue((bucket.ManifestId, bucket.Category), out var bucketBlob)){continue;}- var rev = await UpsertBucketAsync(context, bucket.ManifestId, bucket.Category, bucket.Blob, bucket.CiphertextHash, bucket.CurrentRevision, bucketRows.GetValueOrDefault((bucket.ManifestId, bucket.Category)));+ var rev = await UpsertBucketAsync(context, bucket.ManifestId, bucket.Category, bucketBlob, bucket.CiphertextHash, bucket.CurrentRevision, bucketRows.GetValueOrDefault((bucket.ManifestId, bucket.Category)));newBucketRevisions.Add(new BucketRevision { ManifestId = bucket.ManifestId, Category = bucket.Category, Revision = rev });}@@ -777,12 +800,12 @@ public class VaultController(/// <param name="context">Database context.</param>/// <param name="manifestId">The manifest that owns the bucket.</param>/// <param name="kind">The bucket category.</param>- /// <param name="encryptedData">The new encrypted payload.</param>+ /// <param name="encryptedData">The new encrypted payload as raw ciphertext bytes.</param>/// <param name="ciphertextHash">Storage-layer integrity hash of the payload.</param>/// <param name="currentRevision">The revision the client believes is current, used to seed a first write.</param>/// <param name="existing">The current row, already loaded by the revision gate, or null when none exists yet.</param>/// <returns>The new revision number.</returns>- private async Task<long> UpsertBucketAsync(AliasServerDbContext context, Guid manifestId, VaultDataBucketCategory kind, string encryptedData, string? ciphertextHash, long? currentRevision, VaultDataBucket? existing)+ private async Task<long> UpsertBucketAsync(AliasServerDbContext context, Guid manifestId, VaultDataBucketCategory kind, byte[] encryptedData, string? ciphertextHash, long? currentRevision, VaultDataBucket? existing){var now = timeProvider.UtcNow;@@ -858,18 +881,8 @@ public class VaultController(byte[]? data = null;if (!existing.TryGetValue(dto.Hash, out var row) || overwrite){- try- {- data = Convert.FromBase64String(dto.EncryptedDataBase64);- }- catch (FormatException)- {- return false;- }-- if (data.Length < 16)+ if (!CiphertextHelper.TryDecode(dto.EncryptedDataBase64, out data)){- // Anything smaller than IV+tag overhead can't be valid AES-GCM ciphertext, reject the upload.return false;}}diff --git a/apps/server/AliasVault.Api/Helpers/CiphertextHelper.cs b/apps/server/AliasVault.Api/Helpers/CiphertextHelper.csnew file mode 100644index 000000000..8d2d3020e--- /dev/null+++ b/apps/server/AliasVault.Api/Helpers/CiphertextHelper.cs@@ -0,0 +1,40 @@+//-----------------------------------------------------------------------+// <copyright file="CiphertextHelper.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.Api.Helpers;++/// <summary>+/// Helpers for the encrypted payloads.+/// </summary>+public static class CiphertextHelper+{+ /// <summary>+ /// Smallest byte length a payload can have and still be AES-GCM ciphertext (IV + auth tag overhead).+ /// </summary>+ private const int MinCiphertextLength = 16;++ /// <summary>+ /// Decodes a base64-encoded ciphertext into the raw ciphertext bytes.+ /// </summary>+ /// <param name="base64">The base64-encoded ciphertext as it arrived on the request.</param>+ /// <param name="bytes">The decoded ciphertext, empty when the ciphertext is malformed.</param>+ /// <returns>True when the ciphertext decodes to something that can be AES-GCM ciphertext; false when the caller should reject the request.</returns>+ public static bool TryDecode(string base64, out byte[] bytes)+ {+ try+ {+ bytes = Convert.FromBase64String(base64);+ }+ catch (FormatException)+ {+ bytes = [];+ return false;+ }++ return bytes.Length >= MinCiphertextLength;+ }+}diff --git a/apps/server/AliasVault.Api/Helpers/FileHelper.cs b/apps/server/AliasVault.Api/Helpers/FileHelper.csindex ab8961e9e..cbc7abfb8 100644--- a/apps/server/AliasVault.Api/Helpers/FileHelper.cs+++ b/apps/server/AliasVault.Api/Helpers/FileHelper.cs@@ -31,4 +31,11 @@ public static class FileHelper// Return the size in kilobytes as int (rounded up)return (int)Math.Ceiling(kilobytes);}++ /// <summary>+ /// Calculate the size of a raw byte payload in kilobytes.+ /// </summary>+ /// <param name="byteCount">Length of the payload in bytes.</param>+ /// <returns>Length in kilobytes.</returns>+ public static int BytesToKilobytes(int byteCount) => (int)Math.Ceiling(byteCount / 1024.0);}diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.csindex 7e110f2c1..80371d750 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.Designer.cs@@ -982,9 +982,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<long>("RevisionNumber").HasColumnType("bigint");@@ -1016,9 +1016,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<DateTime>("UpdatedAt").HasColumnType("timestamp with time zone");@@ -1056,8 +1056,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("FileSize").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)@@ -1225,8 +1225,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("FileSize").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.csindex 91e788f41..757e462ba 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810093922_ManifestStorageAndGroupOwnership.cs@@ -27,6 +27,7 @@ namespace AliasServerDb.MigrationsScopeDeliveryKeysToManifests(migrationBuilder);ScopeRateLimitsToGroups(migrationBuilder);AddManifestV1Tables(migrationBuilder);+ SkipToastCompressionOnCiphertextColumns(migrationBuilder);}/// <inheritdoc />@@ -154,7 +155,7 @@ namespace AliasServerDb.MigrationsmigrationBuilder.AddColumn<Guid>(name: "OwnerGroupId", table: "VaultManifests", type: "uuid", nullable: true);migrationBuilder.AddColumn<string>(name: "Name", table: "VaultManifests", type: "character varying(255)", maxLength: 255, nullable: true);migrationBuilder.AddColumn<string>(name: "StorageFormat", table: "VaultManifests", type: "character varying(20)", maxLength: 20, nullable: true);- migrationBuilder.AddColumn<string>(name: "ManifestBlob", table: "VaultManifests", type: "text", nullable: true);+ migrationBuilder.AddColumn<byte[]>(name: "ManifestBlob", table: "VaultManifests", type: "bytea", nullable: true);migrationBuilder.AddColumn<string>(name: "ManifestCiphertextHash", table: "VaultManifests", type: "character varying(64)", maxLength: 64, nullable: true);// A manifest-v1 revision carries no vault blob and no SRP credentials, so the columns that only the legacy@@ -182,7 +183,7 @@ namespace AliasServerDb.MigrationsManifestId = table.Column<Guid>(type: "uuid", nullable: false),VaultBlob = table.Column<string>(type: "text", nullable: true),StorageFormat = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),- ManifestBlob = table.Column<string>(type: "text", nullable: true),+ ManifestBlob = table.Column<byte[]>(type: "bytea", nullable: true),ManifestCiphertextHash = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),Version = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),FileSize = table.Column<int>(type: "integer", nullable: false),@@ -543,7 +544,7 @@ namespace AliasServerDb.Migrations{ManifestId = table.Column<Guid>(type: "uuid", nullable: false),Category = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),- EncryptedData = table.Column<string>(type: "text", nullable: false),+ EncryptedData = table.Column<byte[]>(type: "bytea", nullable: false),RevisionNumber = table.Column<long>(type: "bigint", nullable: false),CiphertextHash = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),@@ -567,7 +568,7 @@ namespace AliasServerDb.MigrationsRevisionNumber = table.Column<long>(type: "bigint", nullable: false),ManifestId = table.Column<Guid>(type: "uuid", nullable: false),Category = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),- EncryptedData = table.Column<string>(type: "text", nullable: false),+ EncryptedData = table.Column<byte[]>(type: "bytea", nullable: false),CiphertextHash = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)@@ -591,6 +592,23 @@ namespace AliasServerDb.MigrationsmigrationBuilder.CreateIndex(name: "IX_VaultBlobObjects_OwnerUserId_Category", table: "VaultBlobObjects", columns: new[] { "OwnerUserId", "Category" });}+ /// <summary>+ /// Every manifest-v1 payload column holds AES ciphertext of an already-gzipped payload, which is+ /// incompressible, so TOAST would burn a compression attempt per write and always discard the result.+ /// EXTERNAL keeps the out-of-line storage but skips that attempt, matching the Emails.MessageSourceBytes column.+ /// </summary>+ /// <param name="migrationBuilder">Migration builder.</param>+ private static void SkipToastCompressionOnCiphertextColumns(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("""+ ALTER TABLE "VaultManifests" ALTER COLUMN "ManifestBlob" SET STORAGE EXTERNAL;+ ALTER TABLE "VaultManifestsHistory" ALTER COLUMN "ManifestBlob" SET STORAGE EXTERNAL;+ ALTER TABLE "VaultDataBuckets" ALTER COLUMN "EncryptedData" SET STORAGE EXTERNAL;+ ALTER TABLE "VaultDataBucketsHistory" ALTER COLUMN "EncryptedData" SET STORAGE EXTERNAL;+ ALTER TABLE "VaultBlobObjects" ALTER COLUMN "EncryptedData" SET STORAGE EXTERNAL;+ """);+ }+/// <summary>/// Drops the manifest-v1 only tables again./// </summary>diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810113019_AddKeyVersionColumns.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810113019_AddKeyVersionColumns.Designer.csindex fc6a80b32..d25ee040c 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20260810113019_AddKeyVersionColumns.Designer.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810113019_AddKeyVersionColumns.Designer.cs@@ -996,9 +996,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1033,9 +1033,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1079,8 +1079,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)@@ -1257,8 +1257,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810154523_AddEmailMultiWrap.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810154523_AddEmailMultiWrap.Designer.csindex caf9021f2..2fe3ac44e 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20260810154523_AddEmailMultiWrap.Designer.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810154523_AddEmailMultiWrap.Designer.cs@@ -1013,9 +1013,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1050,9 +1050,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1096,8 +1096,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)@@ -1274,8 +1274,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.Designer.csindex f8cb17eeb..50e044cfb 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.Designer.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.Designer.cs@@ -1018,9 +1018,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1055,9 +1055,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1101,8 +1101,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)@@ -1279,8 +1279,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.cs b/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.csindex 5087d3a40..643001f2d 100644--- a/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/20260810200139_EmailStorageFormatV2.cs@@ -31,13 +31,18 @@ namespace AliasServerDb.Migrationstype: "bytea",nullable: true);- // The column holds AES ciphertext which is incompressible, so skip TOAST compression.- migrationBuilder.Sql(@"ALTER TABLE ""Emails"" ALTER COLUMN ""MessageSourceBytes"" SET STORAGE EXTERNAL;");+ // Both columns hold AES ciphertext which is incompressible, so skip TOAST compression.+ migrationBuilder.Sql("""+ ALTER TABLE "Emails" ALTER COLUMN "MessageSourceBytes" SET STORAGE EXTERNAL;+ ALTER TABLE "EmailAttachments" ALTER COLUMN "Bytes" SET STORAGE EXTERNAL;+ """);}/// <inheritdoc />protected override void Down(MigrationBuilder migrationBuilder){+ migrationBuilder.Sql(@"ALTER TABLE ""EmailAttachments"" ALTER COLUMN ""Bytes"" SET STORAGE EXTENDED;");+migrationBuilder.DropColumn(name: "AttachmentCount",table: "Emails");diff --git a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.csindex 78e132a91..c82309fc3 100644--- a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs@@ -1015,9 +1015,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1052,9 +1052,9 @@ namespace AliasServerDb.Migrationsb.Property<DateTime>("CreatedAt").HasColumnType("timestamp with time zone");- b.Property<string>("EncryptedData")+ b.Property<byte[]>("EncryptedData").IsRequired()- .HasColumnType("text");+ .HasColumnType("bytea");b.Property<int>("KeyVersion").HasColumnType("integer");@@ -1098,8 +1098,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)@@ -1276,8 +1276,8 @@ namespace AliasServerDb.Migrationsb.Property<int>("KeyVersion").HasColumnType("integer");- b.Property<string>("ManifestBlob")- .HasColumnType("text");+ b.Property<byte[]>("ManifestBlob")+ .HasColumnType("bytea");b.Property<string>("ManifestCiphertextHash").HasMaxLength(64)diff --git a/apps/server/Databases/AliasServerDb/VaultDataBucketBase.cs b/apps/server/Databases/AliasServerDb/VaultDataBucketBase.csindex c6ee74480..6fde84da7 100644--- a/apps/server/Databases/AliasServerDb/VaultDataBucketBase.cs+++ b/apps/server/Databases/AliasServerDb/VaultDataBucketBase.cs@@ -16,9 +16,9 @@ using System.ComponentModel.DataAnnotations;public abstract class VaultDataBucketBase : IVaultRevision{/// <summary>- /// Gets or sets the encrypted bucket payload (AES-GCM ciphertext, base64-encoded).+ /// Gets or sets the encrypted bucket payload (raw AES-GCM ciphertext bytes)./// </summary>- public required string EncryptedData { get; set; }+ public required byte[] EncryptedData { get; set; }/// <summary>/// Gets or sets the version of the owning manifest's VEK that <see cref="EncryptedData"/> is encrypted with.diff --git a/apps/server/Databases/AliasServerDb/VaultManifestBase.cs b/apps/server/Databases/AliasServerDb/VaultManifestBase.csindex e0a4cbcb8..7b2e686bb 100644--- a/apps/server/Databases/AliasServerDb/VaultManifestBase.cs+++ b/apps/server/Databases/AliasServerDb/VaultManifestBase.cs@@ -32,9 +32,9 @@ public abstract class VaultManifestBase : IVaultRevisionpublic required string StorageFormat { get; set; }/// <summary>- /// Gets or sets the encrypted manifest blob (AES-GCM ciphertext, base64-encoded).+ /// Gets or sets the encrypted manifest blob (raw AES-GCM ciphertext bytes)./// </summary>- public string? ManifestBlob { get; set; }+ public byte[]? ManifestBlob { get; set; }/// <summary>/// Gets or sets the SHA-256 (hex) of the encrypted manifest ciphertext. Stored for storage-layer integritydiff --git a/apps/server/Tests/AliasVault.UnitTests/Vault/RetentionManager/BucketRetentionTests.cs b/apps/server/Tests/AliasVault.UnitTests/Vault/RetentionManager/BucketRetentionTests.csindex dc47bfffa..6b938e16c 100644--- a/apps/server/Tests/AliasVault.UnitTests/Vault/RetentionManager/BucketRetentionTests.cs+++ b/apps/server/Tests/AliasVault.UnitTests/Vault/RetentionManager/BucketRetentionTests.cs@@ -138,7 +138,7 @@ public class BucketRetentionTests{ManifestId = Guid.Parse("11111111-1111-1111-1111-111111111111"),Category = VaultDataBucketCategory.Settings,- EncryptedData = string.Empty,+ EncryptedData = [],RevisionNumber = 10,UpdatedAt = new DateTime(2023, 6, 1, 12, 0, 0),};@@ -155,7 +155,7 @@ public class BucketRetentionTests{ManifestId = Guid.Parse("11111111-1111-1111-1111-111111111111"),Category = VaultDataBucketCategory.Settings,- EncryptedData = string.Empty,+ EncryptedData = [],RevisionNumber = revisionNumber,UpdatedAt = updatedAt,};