Skip to content

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

3.7 KB
Raw Blame
//-----------------------------------------------------------------------
// <copyright file="Manifest.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.Vault;

using System.Text.Json.Serialization;

/// <summary>
/// A single vault manifest as carried in list-based payloads. A user's logical vault is assembled from one or more
/// manifests: the one owned by their personal group plus any number owned by shared groups they belong to.
/// Which is which follows from <see cref="GetResponse.PersonalManifestId"/>, not from a flag on each entry. Each
/// manifest is independently encrypted and revisioned, and carries its own blob references.
/// </summary>
public class Manifest : IFramePart, IFrameBody
{
    /// <summary>Gets or sets the stable identifier of the logical manifest (constant across its revisions).</summary>
    public required Guid ManifestId { get; set; }

    /// <inheritdoc/>
    public int Offset { get; set; }

    /// <inheritdoc/>
    public int Size { get; set; }

    /// <summary>Gets or sets the manifest ciphertext (AES-GCM), empty on an empty vault.</summary>
    [JsonIgnore]
    public byte[] Data { get; set; } = [];

    /// <summary>Gets or sets the SHA-256 (hex) of the manifest ciphertext for client-side storage-integrity check.</summary>
    public string? CiphertextHash { get; set; }

    /// <summary>Gets or sets the manifest revision number.</summary>
    public required long Revision { get; set; }

    /// <summary>Gets or sets the blob references this manifest revision needs (so the client can detect cache misses).</summary>
    public List<BlobReference> BlobReferences { get; set; } = [];

    /// <summary>
    /// Gets or sets a value indicating whether the caller may administer this manifest's sharing: grant and revoke
    /// access and publish its email delivery key. True when the caller is an owner or admin of the group that owns
    /// the manifest.
    /// </summary>
    public bool CanAdminister { get; set; }

    /// <summary>
    /// Gets or sets how the caller's access to this manifest's VEK is encrypted, as a ManifestKeyType token.
    /// </summary>
    public string? KeyType { get; set; }

    /// <summary>
    /// Gets or sets the manifest VEK encrypted with the caller's public key.
    /// </summary>
    public string? EncryptedVek { get; set; }

    /// <summary>Gets or sets the algorithm of <see cref="EncryptedVek"/>, as a VaultKeyAlgorithm token. Null when <see cref="EncryptedVek"/> is null.</summary>
    public string? Algorithm { get; set; }

    /// <summary>
    /// Gets or sets the caller's account public key <see cref="EncryptedVek"/> was encrypted with.
    /// </summary>
    public string? AccountPublicKey { get; set; }

    /// <summary>Gets or sets the granter's signature over the grant in <see cref="EncryptedVek"/>.</summary>
    public string? GrantSignature { get; set; }

    /// <summary>Gets or sets the id of the user who signed the grant.</summary>
    public string? GrantSignerUserId { get; set; }

    /// <summary>Gets or sets the granter's signing public key that <see cref="GrantSignature"/> verifies under.</summary>
    public string? GrantSignerPublicKey { get; set; }

    /// <summary>Gets or sets the version of the VEK in <see cref="EncryptedVek"/>, which the grant is signed for.</summary>
    public int KeyVersion { get; set; }

    /// <summary>Gets this manifest as its own frame part, for GET /v2/Vault/manifest/{id}.</summary>
    [JsonIgnore]
    public IEnumerable<IFramePart> FrameParts => [this];
}