Table of Contents

Class TotpMasterKek

Namespace
FishMMO.Auth.Implementation
Assembly
FishMMO-AuthShared.dll

The deployment-shared 32-byte master KEK that wraps every account's TOTP secret at rest (see EncryptTotpSecret(byte[], string, byte[], int)).

public static class TotpMasterKek
Inheritance
TotpMasterKek
Inherited Members

Remarks

Why this exists. The TOTP master KEK used to be derived from the LoginServer's HMAC token-signing key via LocalDeriveKmsProvider.DeriveKey("fishmmo-totp-master-key-v1"). That signing key is generated fresh with CryptoHelper.GenerateKey on every process start and then upserted over the stored row, and it is never read back. The consequences were:

  • Every account's TOTP secret became undecryptable the moment the LoginServer restarted — and 2FA enrolment is mandatory at account creation, so this locked players out of their own authenticators.
  • A second LoginServer derived a different key, so an account enrolled on one could not complete 2FA on another.
  • Signing-key rotation orphaned every existing secret.
  • Nothing outside the enrolling LoginServer process — the Control Panel included — could ever verify a code.

The KEK is therefore a deployment secret, provisioned once and shared, exactly as signing_key_kek already is. It is stored in the deployment_secrets table under DatabaseKey as Base64 of 32 random bytes, and it must never be rotated without re-wrapping every stored envelope, because rotation invalidates them all.

This type deliberately performs no I/O and has no database dependency, so the Unity server and the ASP.NET Control Panel can each fetch the row through their own service layer and share one validation and one set of rules.

Fields

DatabaseKey

Row key in the deployment_secrets table.

public const string DatabaseKey = "totp_master_kek"

Field Value

string

KeyLength

Required length in bytes. AES-256, matching EncryptTotpSecret's contract.

public const int KeyLength = 32

Field Value

int

Methods

Generate()

Generates a fresh KEK as a Base64 string, for provisioning tools.

public static string Generate()

Returns

string

Remarks

Generating a second one for a deployment that already has accounts enrolled makes every stored TOTP secret undecryptable. Provisioning must be create-if-absent, never overwrite.

TryDecode(string?, out byte[]?, out string?)

Validates and decodes a Base64 KEK fetched from deployment_secrets.

public static bool TryDecode(string? base64Value, out byte[]? key, out string? error)

Parameters

base64Value string

The stored value, or null/empty when the row is absent.

key byte[]

The decoded 32-byte key on success; otherwise null.

error string

A human-readable reason on failure; otherwise null.

Returns

bool

true when a valid key was decoded.