Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.Users

ONE ACCOUNT PER MAILBOX, and the account name IS the mailbox address. That is
  the whole data model, and it lines up with the other two things a mailbox has:
  its client certificate (bound to the same address by
  StreamSec.Mail.SMTPServer) and its maildir (StreamSec.Mail.SMTPDelivery).

  WHY THIS EXISTS. SMTP AUTH PLAIN and LOGIN send the password itself, so the
  server has to be able to VERIFY one - which means storing something derived
  from it. TsmCustomSMTPServer.OnAuthenticate deliberately denies by default and
  leaves that to the application; this component is the shipped answer.

  WHAT IS STORED IS NOT THE PASSWORD. Each account holds an Argon2id verifier
  (RFC 9106) over a per-account random salt, with the cost parameters recorded
  ALONGSIDE it. Recording them per account is what makes the store upgradable:
  raise MemoryKiB or Iterations later and existing accounts still verify with
  the parameters they were written with, then get silently re-derived at their
  next successful sign-in (see UpgradeOnVerify). A store whose cost cannot be
  raised without invalidating every password is a store that never gets raised.

  COMPARISON IS CONSTANT TIME (EqualMemConstantTime). The margin is smaller here
  than for a MAC tag - an attacker does not choose the verifier, only the
  password behind it - but the library has one rule about comparing secrets and
  this follows it rather than arguing about the exception.

  THE FILE IS THE STORE. There is no design-time user collection, deliberately:
  a published collection would put password verifiers in a DFM, where they get
  copied into version control and shipped inside an executable. Provision at
  run time, or edit the file.

  IT IS NOT A DIRECTORY. No groups, no aliases, no quotas. An account either
  exists and can authenticate, or it does not.

Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)

Classes, interfaces and records

classeMailUsersError

inherits from Exception

(no public members)

classtMailUser

One account. Held only in memory and in the file - it is not a TCollectionItem and cannot be streamed into a DFM, which is deliberate.

destructor Destroy; override; property Mailbox: string read fMailbox;
The mailbox address this account is for, e.g. 'alice@example.com'.
property Enabled: Boolean read fEnabled write fEnabled; property Failures: Integer read fFailures;
Consecutive failures since the last success, from any source. A record only: what locks is the count per source, in the component's table.
property LastFailure: TDateTime read fLastFailure; property Created: TDateTime read fCreated; property MemoryKiB: Integer read fMemoryKiB;
The parameters THIS account's verifier was derived with - not the component's current ones, which may since have been raised.
property Iterations: Integer read fIterations; property Parallelism: Integer read fParallelism;

classTsmMailUsers — component reference

inherits from TComponent

constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure SetPassword(const aMailbox: string; const aPassword: iSecretKey); overload;
Creates or REPLACES the account for aMailbox. Raises on an empty mailbox or an empty password - an account that cannot be signed in to is not a useful thing to create by accident. » member page
procedure SetPassword(const aMailbox, aPassword: string); overload;
Convenience for a caller holding a plain string, which this cannot wipe. » member page
function DeleteUser(const aMailbox: string): Boolean; function UserExists(const aMailbox: string): Boolean; procedure SetEnabled(const aMailbox: string; aEnabled: Boolean);
Administratively enable or disable without destroying the verifier. » member page
procedure Unlock(const aMailbox: string);
Clears the failure counts and any lockout, for every source. » member page
function Verify(const aMailbox: string; const aPassword: iSecretKey): Boolean; overload;
THE ONE CALL THE SMTP LAYER MAKES.

IT DELIBERATELY DOES NOT SAY WHY IT FAILED to the caller's caller: SMTP must answer a single 535 for every failure, because distinguishing "no such user" from "wrong password" turns the AUTH command into an account enumerator. Use VerifyEx when a LOG needs the distinction, and keep it in the log. » member page
function VerifyEx(const aMailbox: string; const aPassword: iSecretKey): tMailUserResult; overload;
Delegates to VerifyEx, forwarding aMailbox, aPassword and an empty string, and returns its result. » member page
function Verify(const aMailbox: string; const aPassword: iSecretKey; const aSource: string): Boolean; overload;
aSource is where the attempt came from, in any form MailUserSourceKey takes. Failures are counted per account AND source, so a wrong password from one address does not lock out another. The calls with no source count as one source of their own, the same as an empty aSource. » member page
function VerifyEx(const aMailbox: string; const aPassword: iSecretKey; const aSource: string): tMailUserResult; overload;
Delegates to VerifyEx, forwarding aMailbox, aPassword and an empty string, and returns its result. » member page
function IsLocked(const aMailbox: string): Boolean; overload;
True while ANY source is locked out of the account. » member page
function IsLocked(const aMailbox, aSource: string): Boolean; overload;
True while this source is locked out of the account. » member page
function FailureEntryCount: Integer;
Entries in the failure table now; never more than MaxFailureEntries. » member page
function IsEnabled(const aMailbox: string): Boolean;
True when the account exists and SetEnabled permits sign-in. This does not test temporary lockout: IsLocked reports that separately. False for an account that does not exist. » member page
procedure LoadFromFile;
Reads FileName. A missing file is an empty store, not an error - a server starting for the first time has no users yet. A CORRUPT file IS an error: silently continuing with fewer accounts than the operator provisioned is how a mail server quietly stops accepting somebody's mail. » member page
procedure SaveToFile; procedure Clear; function MailboxNames: TArray<string>;
A snapshot of the mailbox names. The accounts themselves are not handed out - a verifier that escaped into application code would end up logged. » member page
function Count: Integer; property FileName: string read fFileName write SetFileName;
The file backing the store. Assigning it at run time loads immediately; assigned at design time, the load happens in Loaded. » member page
property AutoSave: Boolean read fAutoSave write fAutoSave default True;
Write the file after every change. On by default: a provisioning call that is not persisted is one the next restart forgets. » member page
property UpgradeOnVerify: Boolean read fUpgradeOnVerify write fUpgradeOnVerify default True;
Re-derive a verifier with the CURRENT cost parameters after a successful sign-in whose stored parameters were weaker. On by default - it is what lets the cost be raised on a live system without a password reset. » member page
property MemoryKiB: Integer read fMemoryKiB write SetMemoryKiB default cMailUserMemoryKiB;
Argon2id cost for NEW and upgraded verifiers. Existing accounts keep the parameters they were written with until they are re-derived. RAISING THESE COSTS CPU AND MEMORY PER AUTHENTICATION ATTEMPT, including failed ones, so they are also a denial-of-service knob. » member page
property Iterations: Integer read fIterations write SetIterations default cMailUserIterations; property Parallelism: Integer read fParallelism write SetParallelism default cMailUserParallelism; property MaxFailures: Integer read fMaxFailures write SetMaxFailures default cMailUserMaxFailures;
Consecutive failures for one account from one source before that source is locked out of it. 0 disables lockout, which leaves password guessing bounded only per connection. » member page
property LockoutSeconds: Integer read fLockoutSeconds write SetLockoutSeconds default cMailUserLockSeconds; property MaxFailureEntries: Integer read fMaxFailureEntries write SetMaxFailureEntries default cMailUserFailureEntries;
The most (account, source) pairs the failure table holds. When it is full the oldest pair not locked out goes first, and the oldest locked out only when every pair is. What goes is that source's count, so a full table gives an address its guesses back sooner and never refuses a sign-in. » member page
property OnUserChanged: tMailUsersChangeEvent read fOnUserChanged write fOnUserChanged;
An account was created, changed, deleted or locked. Fired from whatever thread authenticated, so a handler must be thread-safe and must not block. » member page

Types (enumerations, sets, aliases)

enumtMailUserResult

Why an authentication attempt did not succeed. Returned rather than merely False so a deployment can log the difference - but see the note on Verify: the SMTP layer must not tell the CLIENT which of these it was.

  tMailUserResult = (
    { The password verified. }
    murOk,
    { No such account. }
    murUnknown,
    { The account exists and the password did not verify. }
    murBadPassword,
    { The account is administratively disabled. }
    murDisabled,
    { Too many recent failures from this source; try later. }
    murLockedOut);

proctMailUsersChangeEvent

  tMailUsersChangeEvent = procedure (Sender: TObject;
                                     const aMailbox: string) of object;

Routines