API Reference
StreamSec.Snif.UserStorage
Secure Network Interface Framework - StreamSec.Snif.UserStorage
Persistence for the Snif server-side user list (TsnifClassServer has no
built-in persistence; the app supplies it). TsnifCustomUserStorage is the
abstract contract; TsnifUserFileStorage backs it with an INI file.
It is auth-scheme-agnostic: it stores the opaque per-user TsnifUserListItem
(name, AuthData bytes, roles, failure counters), so it works unchanged for the
legacy verifier-based blob and for the Tunnel Bound KAPA TsnifPwFile (the fInfo
interface is app-specific and NOT persisted - it loads back as nil).
Typical use:
Storage.FileName := '...\users.ini';
Storage.LoadInto(MyClassServer); // populate the server at startup
Storage.Attach(MyClassServer); // write through on server-side changes
...
Storage.SaveUser(Storage.MakeItem('alice', PwFileBytes, ['login','changepassword']));
Attach wires TsnifClassServer.OnUserUpdated so that server-driven changes
(e.g. AkeChangeAuth.Commit -> UpdateCurrentUserListItem) are persisted
automatically. Bulk loads (LoadInto -> UpdateUserList) do NOT fire it, so there
is no save-back loop. File operations are serialised by a lock (the event may
fire from any connection thread).
INI layout (one section per user, prefix 'User:', name percent-escaped):
[User:alice]
AuthData=<uppercase hex>
Roles=login,changepassword
Failures=0
TotalFailures=0
LastFailure=0 ; GeneralizedTime (YYYYMMDDHHMMSS[.fff]Z), 0 = never
OtpHash=<uppercase hex> ; pending one-time code (hash only), empty = none
OtpExpiry=0 ; GeneralizedTime, 0 = no pending code
The two time fields are written as ASN.1 GeneralizedTime text (the stDERUtils
encoder), so the file is readable and hand-editable. Files from before this
format are still read: the loader accepts EITHER a GeneralizedTime OR the
legacy decimal Int64 (the raw TDateTime Double bit pattern) per field.
User names are percent-escaped (%XX) for the INI-significant characters
% [ ] = ; # and control codes, so any name round-trips.
Feature notes: Snif remoting framework (concepts)
Classes, interfaces and records
classTsnifCustomUserStorage
inherits from TComponent
function LoadUsers: TsnifUserList; virtual; abstract;
Core operations - implemented by descendants. Call these directly only for out-of-band administration (provisioning, resets, migration tools); normal server-side updates flow through Attach/OnUserUpdated.
Full description »
procedure SaveUser(const aItem: TsnifUserListItem); virtual; abstract;
Persists one user item (insert or overwrite by name). Apps call this to provision or reset a single account; the framework also calls it internally via HandleServerUserUpdated when a live connection changes a user.
» member page
procedure DeleteUser(const aName: string); virtual; abstract;
Removes a user from the store. Used by admin/deprovisioning code; the server itself never deletes users.
» member page
function UserExists(const aName: string): Boolean; virtual; abstract;
True if the named account is already persisted. Handy before provisioning to avoid clobbering an existing user.
» member page
procedure LoadInto(aServer: TsnifClassServer);
Convenience. Reads the whole store and pushes it into the server (UpdateUserList assigns a fresh per-item lock and resets roles). Call once at server startup. This is a bulk load and deliberately does NOT trigger the write-through set up by Attach, so seeding the server cannot loop back into a save.
» member page
procedure Attach(aServer: TsnifClassServer);
Wires this storage as the server's OnUserUpdated handler so that per-user changes made over a live connection (e.g. a KAPA change-password commit via UpdateCurrentUserListItem) are persisted automatically. Call once after LoadInto to enable write-through; server-only.
» member page
procedure SaveAll(const aList: TsnifUserList); virtual;
Writes every item in the list (default loops SaveUser; descendants may batch into a single file write). Use for a full rewrite of the store, e.g. after a bulk import or migration.
» member page
class function MakeItem(const aName: string; const aAuthData: tBytes; const aRoles: array of string): TsnifUserListItem;
Helper that builds a TsnifUserListItem from a name, opaque auth blob and roles, zeroing the failure counters and leaving fLock nil (the server assigns it on UpdateUserList). Use when provisioning a new account to hand to SaveUser - the AuthData blob is whatever the active scheme produced (legacy verifier or KAPA TsnifPwFile bytes).
» member page
inherits from TsnifCustomUserStorage
constructor Create(AOwner: TComponent); override;
Standard component constructor; also creates the critical section that serialises all file access (OnUserUpdated may fire from any connection thread). Apps normally drop this component or Create it, then set FileName.
» member page
destructor Destroy; override;
Frees the internal lock. Standard teardown; apps rarely call it directly.
» member page
function LoadUsers: TsnifUserList; override;
Reads every 'User:' section from the INI file into a fresh list. Returns an empty list if FileName is unset or the file is missing. The app-specific fInfo interface is not persisted and loads back nil.
» member page
procedure SaveUser(const aItem: TsnifUserListItem); override;
Overwrites (or creates) one user's section in the INI file, then flushes to disk. Called under the lock, so it is safe from the OnUserUpdated event.
» member page
procedure SaveAll(const aList: TsnifUserList); override;
Writes the whole list in a single load-modify-save of the INI file - cheaper than SaveUser per item for a bulk rewrite. Note it adds/updates the given users but does not remove sections absent from the list.
» member page
procedure DeleteUser(const aName: string); override;
Erases the named user's section and flushes. Used by admin/deprovisioning code.
» member page
function UserExists(const aName: string): Boolean; override;
True if the named user's section exists in the INI file. Returns False when FileName is unset or the file is missing.
» member page
property FileName: string read fFileName write fFileName;
Path to the INI file backing the user list. Set this before any load/save; the store is created on first write. LoadUsers/UserExists treat an empty or nonexistent file as "no users", but SaveUser/SaveAll/DeleteUser raise if it is blank.
» member page