The client API is a normal way for any account to use SD. A person running a
custom GUI program that talks to SD needs API access and may need nothing
else — no ssh, no terminal. An account has it only if SDSYS gave it — a new
account has none, and api (or both) gives it:
create.account user jane api
modify.account jane api
Your application code does not change. SDConnect() and SDConnectLocal()
take the same arguments and return the same things. What changed is
underneath: the login protocol, the encryption of the connection, the port, the
identity a session runs as, and what it is allowed to open.
SDSYS is the one exception: from another computer it has no API access until the administrator opens that door, and then only from the addresses named — see Reaching the port is not getting in below. Every other account has no API access until SDSYS gives it —
modify.accountnameapi(orboth), orapiatcreate.account— and an account that has not been given it is refused at the door.
There is a second, narrower route for a client that only needs files. An
account SDSYS gave files-on (and not api) can log in over the API but is
held to files: opening, closing, reading, writing, deleting, selecting, locking,
indices and file information. A request to call a subroutine, execute a
command, enter another account (logto), read a variable or use a sequential
file is refused with "This login is for files only: request n is not
allowed", and the connection stays open. An account with api has the whole
API whether or not it also has files-on. This is the route SDNet's logins are
meant to use.
The login is SCRAM-SHA-256#
A client that sends a password in clear is refused. It gets "Cleartext login is no longer supported; this server requires SCRAM authentication" and the connection drops.
The API runs a challenge and response rather than sending the user name and password as plain text: the server sets a puzzle only someone who knows the password can answer, and the password itself is never sent in any form.
The server also proves itself to you. It finishes by returning a value only the real server can compute, and the client refuses the connection if it does not match. Another program that grabbed the port before SD started cannot pretend to be SD in order to collect passwords.
A client library that does not speak SCRAM is refused outright. Use the client library that comes with SD (see Client distribution).
An account that has no password set is refused, and the refusal reads as a
wrong password. From the server's point of view there is no credential to
check; modify.password sets one.
The password is never kept anywhere, by design — SD stores only what the challenge and response needs to check an answer.
Programs using the !sdclient class are covered. The class module BASIC
programs use to reach another SD server speaks the same login, so a program
that uses it needs no change.
SDConnectLocal() connections are unaffected. They send no password and
never did.
The port#
The API port is 4247, and nothing can change it. (OpenQM and ScarletDME
use 4243.) sd.conf's APIPORT now only switches the API
on: any number above zero means on, and SD listens on 4247 whatever the number
is. A file that says APIPORT=4243 keeps working and means 4247. A program that
names port 4243 must name 4247 instead; one that names no port needs no change.
The server accepts API connections on any network interface, unless
remote.api local has limited it to 127.0.0.1 (APILOCAL=1 in sd.conf),
in which case only this computer can connect.
If you tunnel, stop. ssh -L 4247:127.0.0.1:4247 user@host still works
but is no longer what the design expects. Point the
client straight at port 4247 on the server.
Reaching the port from another computer is off unless you tick the box during installation. To change it afterwards, from an elevated prompt:
powershell -ExecutionPolicy Bypass -File "C:\Program Files\SD\api-firewall.ps1" -Open
powershell -ExecutionPolicy Bypass -File "C:\Program Files\SD\api-firewall.ps1" -Restrict
To turn the API off altogether, comment out the APIPORT line in
C:\ProgramData\SD\sd.conf and restart SD. With no APIPORT set, SD creates
no socket at all — "no API" is a real state, not just a firewall rule.
Declining the API at install time leaves no listener at all. The installer writes an
sd.confwith noAPIPORTline, so nothing listens and there is no firewall rule to open. The API box is unticked by default.remote.api onputs a listener back.
The connection is encrypted#
Every API connection — the network port and the local one alike — is wrapped in TLS 1.3 before SD sends anything, and the login is bound to that encrypted connection. A machine sitting between a client and the server cannot read the traffic or log in on the client's behalf, even by pretending to be the server.
The client libraries do this automatically. sdclilib, sdclient and the
BASIC !sdclient class all negotiate TLS themselves. A program linked against
an older copy of the library cannot connect at all: the server waits for the
encryption handshake and closes the connection after ten seconds of silence.
Relink it.
The client library remembers each server's certificate. The first time a client library connects to a server it keeps that server's certificate; after that it connects only to a server that presents the same one. This is first use trust: the first connection is taken on trust, and every later one is checked, so a machine in the middle cannot pose as the server and collect a login to guess the password from offline.
| What is kept | the SHA-256 of the server's whole certificate, as 64 lower-case hex digits |
| Where | %USERPROFILE%\.sdcore\known_servers, or the file named by the environment variable SD_KNOWN_SERVERS; one line per server, host:port and the digits. A different port is a different server |
| When it is checked | right after the secure connection is made and before anything is sent — no login byte, no password |
A changed certificate is refused, with "The certificate of host:port has
changed since the first connection (pinned ..., now ...). No password was sent.
If the server was reinstalled, remove the line for host:port from ... and connect
again." Nothing
updates the file by itself and nothing asks you; removing the line is the
remedy, and only if you know why the certificate changed. A file that cannot
be opened or written refuses the connection ("cannot pin the server: cannot
open ...") rather than connecting unchecked, so a program that runs with no user
profile, such as a service, needs SD_KNOWN_SERVERS set to a file it may write.
A server whose certificate was replaced is a different server to a client that knew the old one — for instance SD installed on a fresh data folder. The client refuses it until its line is removed.
What this does not cover. The very first connection is trusted, as with
ssh: a machine in the middle at that moment would be remembered in the
server's place. Programs that reach another SD with the !sdclient class or
SDNet do not go through the client library and are not pinned. Use long API
passwords that are not reused elsewhere.
A low-privilege Windows account, sdrelay, appears in Computer Management.
The small helper program that ends the encryption for each connection
(sdtlsrelay.exe, beside sd.exe) runs as sdrelay, an account with every
privilege stripped, at low integrity, unable to sign in interactively and in no
group. SD's service creates it and removes it. Leave it alone: if it is
deleted by hand, every API connection is refused until the service is
reinstalled.
Reaching the port is not getting in#
A caller must clear two gates, in this order, and SDSYS has a door of its own:
- Complete the SCRAM exchange against a password held for that account — so an account with no password cannot connect at all.
- Be a member of the
sdapigroup (or ofsdfiles, for the files-only route), which an account joins only when you give it API access:create.account user fred apior... bothdoes that;sshornonedoes not.
SDSYS is admitted from another computer only through a door the
administrator opens. It is never joined to sdapi, because only
create.account does that and SDSYS is not created that way, so the ordinary
route is closed to it. Signed in to Windows as SDSYS, the administrator can open
a separate door for chosen addresses with remote.sdsys api on address, and
shut it again with remote.sdsys api off; as delivered it is shut. A session
that comes through it must still complete the SCRAM exchange with SDSYS's own
SD password, the one SD asked SDSYS to set the first time it signed in. The
Administrator Guide's chapter Remote Administration through the API says what
opening the door means for security. See
Accounts.
Failed API logins are written to the audit trail, with the reason and
the address they came from. The line is written before the wait (PWDELAY,
three seconds unless you set it) that SD adds to slow down guessing, so a
program that hangs up during the wait is recorded as well. See
Other hardening.
A session is confined to its own account#
| Allowed | everything inside its own account, and the shipped SDSYS files every account needs — messages, syscom, the dictionaries. Ordinary programs are unaffected |
| Not allowed | opening, renaming, deleting or listing anything else, while the account's os-on switch is off (as delivered) |
A refused OPEN takes the ELSE branch and STATUS() is 3035, which
means not permitted rather than not found. That distinction matters when
you are debugging: 3035 is a containment refusal, not a missing file.
A suspended account is refused here too, and deliberately says nothing
about why. modify.account fred suspended denies the API as well as ssh,
and the message is the one this page already gives for an account that does
not exist and for one you are not granted:
User not allowed in requested account
All three answer identically on purpose, so the API cannot be used to
enumerate which accounts exist or what state they are in. If you are debugging
a client that has suddenly stopped connecting, list accounts from SDSYS
is where the answer is — a suspended account shows it in that listing.
If your data lives outside an account#
Name the directory in the NETDIRS setting in C:\ProgramData\SD\sd.conf,
separating several with a semicolon. Nothing else needs changing. An entry that is not an
absolute path, not an existing directory, a drive root, the root of a network share (\\server\share), or that overlaps the SD system
directory or any account is ignored and named in the error log when SD starts; the Administrator
Guide's Configuration: The API, Printing and the Rest has the rules. config('NETDIRS') does
not read it: read the file.
The account's os-on switch lifts this confinement, for an API session as
for any other: an account that holds it reaches whatever its Windows user may.
THE PASSWORD FILE, THE PROGRAM CATALOG AND THE ACCOUNT REGISTER CANNOT BE
ADDED TO NETDIRS, so that setting never opens them to an API session.
An API session runs as you#
Records an API session creates are owned by the account that logged in, and the session reaches files with your access rather than the service's. If your account may not read something, the API session may not read it either.
If your identity cannot be taken on, the login is refused rather than continued with the service's identity. A session that believes it is you while holding the service's rights is worse than one that never started.
There is an alarm for the condition returning. If a session ever believes it is you while Windows says it is not, SD's error log gets:
API IDENTITY LOST at record write - session believes it is ...
Nothing is written when the two agree, so a healthy session is silent and you should never see this. It refuses and slows nothing; it exists so the condition cannot go unnoticed.
sh and OS.EXECUTE over the API#
They follow the account's switches, the same as anywhere else. The
per-account switches sh-on and os-on are read when a session enters its
account, and by the API server when it enters the account for an API session,
so an account that holds sh-on has the sh verb over the API, one that holds
os-on has OS.EXECUTE, and a new account has neither. That puts a shell
behind the account's API credential, reachable from wherever the API port
is: weigh it before you turn either on for an account that also has the
api route. (SDSYS holds no sh-on or os-on switch: it is the
administrator, and a session that is admitted as SDSYS, through the local door
or the door remote.sdsys api on opens, has both gates open.) An API session runs with the signed-in user's own rights,
never as the service's LocalSystem account. SDCLIENT in sd.conf is the
further control, if you want one: non-zero disables file access outright for an
API session, and 2 additionally refuses any subroutine not compiled as
callable from a client. It defaults to 0 — see the Administrator set's
Configuration chapter. One limit is Windows': a process started the way an
API login starts one cannot launch anything that needs a desktop, which
includes PowerShell (see Differences from W1.0-0).
Client libraries#
| 64-bit | sdclilib.dll (and sdclient.dll) |
| 32-bit | none; a 32-bit application must be rebuilt as 64-bit |
The library must speak SCRAM. A client library that sends the password in clear is refused by the server — check which one your application is actually loading.