SD Core Solo for Windows links libsodium and ships it as cygsodium-26.dll in
usr\bin, beside the server. Two things are built on it: the credential
exchange that authenticates an API login, and BASIC functions and a conversion
that encrypt the data an application chooses to encrypt. A third thing, the kept
copy of your account password, uses Windows' own protection (DPAPI) rather than
libsodium, and is reached through the same interface.
SD folds case, so a command may be typed in either case. Commands are shown here in lower case.
The short version#
For credentials, nothing needs configuring. Passwords are never stored. SD keeps a SCRAM-SHA-256 verifier for each of the three passwords in the credential store, the API login proves knowledge of the password without sending it, and the primitives behind that exchange are the ones listed further down. The one place a password is kept in a recoverable form is the copy Windows protects for you — see The account and its passwords.
For encrypting application data there is a route, and it is the application's. SD gives a program a way to make a key from a passphrase and to encrypt a field with it, and a conversion that shows the field decrypted to a session that holds the key. SD does not keep the key, escrow it or recover it. A passphrase or a salt that is lost is data that is lost; there is no setting that changes that. A site that plans to encrypt fields has to decide where the passphrase lives before it writes the application.
Three layers, and what each one protects#
| Layer | What it is | Protects against | Does not protect against |
|---|---|---|---|
| The disk | encryption of the volume the SD folder is on, by the operating system (BitLocker, or the file system's own encryption). SD is unchanged. It has a page of its own in this set (Encrypting the data SD keeps on disk) | a stolen or discarded disk; a backup copied off the machine | anyone signed in to the running system; an administrator; a mounted volume |
| The program | sdkey() and sdencrypt() in an application |
a copy of the SD files, a backup, a person with file access but not the key | the program itself, its variables, anyone who holds the key |
| The conversion | XE in a dictionary item, with the key held in a ring in the process |
the same, and the field reads decrypted for a session that holds the key | the same, and an administrator or a debugger on that process |
None of them hides the record id, the other fields, which values are empty or how long a value is. The second and third are the application's; the first is the machine's.
What was removed#
The encrypt.field verb |
Removed. It pointed at a program, $CRYPTO, which never existed in the GPL release, so the verb could not have worked in any build derived from it |
encrypt() and decrypt() |
Removed and replaced by sdencrypt() and sddecrypt(). The old names do not compile |
SD_EUID_SET and SD_EUID_RESTORE |
Removed. They were the Linux setuid model, which has no meaning on Windows. Keys 102 and 103 are left unused, so an old program that calls one gets the answer any unknown key gets |
The Python half of SDEXT is not on this list. It is a separate helper
process, sdpy.exe, not a library inside sd-solo.exe — the two cannot
safely share a process (long is a different width on each side of the MSYS2
boundary). SDPYFUNC.H and its twenty-one PY_* functions are documented in
full in the User set's Embedded Python chapter. A session may
start the helper only when the operating system switch is on, as for SH and
OS.EXECUTE — see Operating system access.
The functions an application uses#
All of these are ordinary BASIC functions. Any session may compile a call to them: nothing is gated, because they compute on data the program already holds and give nothing away. The programmer's page for them, with a worked example, is in the User set.
| Function | Result |
|---|---|
sdsalt() |
a fresh random salt, base64 for 16 bytes |
sdkey(passphrase, salt) |
a 44 character base64 key by argon2id |
sdrandkey() |
a random 256 bit key, 44 characters |
sdencrypt(data, key, 202) · sddecrypt(data, key, 202) |
libsodium's authenticated secretbox; 201 selects hexadecimal and wants a 64 character key, which the first three do not make |
The argon2id limits are fixed: 2 passes and 64 MiB. They are part of the
format of every key sdkey() has made. A later release that changed them would
make a different key from the same passphrase and salt, and everything encrypted
under the first would be lost, so they are written into the source as numbers.
The cost is about a tenth of a second and 64 MiB of memory for each call; an
application derives the key once per run.
status() after a failure: 10206 the salt is not base64 for 16 bytes,
10207 the passphrase is empty or over 65,536 bytes, 10204 a key of the
wrong length (a passphrase passed straight in as the key is this), 10201 a
wrong key or a damaged value.
A passphrase is not a key#
sdencrypt('The quick brown fox', 'secretkey', 202) returns nothing and sets
status() to 10204: a passphrase is not a key. The way to turn a passphrase
into a key these functions accept is sdkey(), above; sdext()'s SD_KEYFROMPW is internal-only, so an ordinary program
cannot call it.
The XE conversion and the key ring#
A dictionary item names a key and never holds one: field 3 is XE or
XE;name. The key is looked up in a ring in the memory of the session's own
process, put there by !keyset (a subroutine a program calls) or by the
encrypt.key verb (a person, at a hidden prompt), and taken out by !keyclear.
- Held in memory only. The ring is
sodium_mallocmemory: locked against swap and left out of a core dump where the system allows it, guarded by pages that fault, protected against all access between uses and zeroed when released. It is never written to a file, the audit trail, the error log or$como. - Cleared when the session takes its name (an API login does this once, after
the SCRAM proof is accepted), at sign-off, and by
!keyclear. A session starts with an empty ring, there being nologtohere. Not handed to a phantom: a phantom starts with an empty ring. - 16 keys, each under a name of 1 to 31 letters, digits, dots, dashes or underscores. The newest key of a name encrypts; the older ones stay to read what they made, which is how a key is changed.
- Audited by name only:
encrypt.key setandencrypt.key clearwrite the event and the key name to the audit trail.!keysetfrom a program writes nothing. - The verb asks for no privilege and affects only the process that runs it.
A value is base64 of a version byte, a 4 byte key id, a 24 byte nonce and the
secretbox; it is printable and holds no mark character. If there is no key the
session sees the stored cipher text, never a blank, and an input conversion with
no key gives the null string, never the plaintext. The statuses are 10208
(no key of that name), 10209 (the name's keys did not make the value),
10210 (not an encrypted value) and 10212 (the value has been changed).
What a query does with such a field is the application designer's to know:
sort by sorts the cipher text, with field = "value" cannot match (the literal
is encrypted with a fresh nonce), total adds cipher text, an index holds cipher
text and no plaintext reaches the disk, and copy moves the stored value. The
User page lists each.
encrypt.key set refuses a passphrase of fewer than 12 characters (message 12999),
after it has seen that the two typed copies match. That is its only rule. The rule for SD passwords is not
applied, because this is not an SD password: nothing is stored or compared. sdkey(), the function a program
calls, is unchanged and takes any passphrase that is not empty, so a site that wants a stricter or a looser rule
writes it into the application that asks for the passphrase. A long phrase of words is a better passphrase than
eight characters of every kind.
The SDEXT interface#
sdext() is the internal entry point to the cryptographic primitives.
rtnval = sdext(arg, isargmv, key)
key selects the operation, arg carries the arguments and isargmv says
whether arg holds several values rather than one.
It cannot be called from an application. sdext is in the compiler's
internal function table, so an ordinary account does not merely get refused.
It gets a misleading error: an unknown function is read as a matrix reference,
so the complaint is about a dim statement the program does not contain,
reported at the last line rather than at the call. That behavior is covered by
SD Basic - Restricted Commands in the User set. $internal needs both halves:
the compiler tests for internal mode and for the administrator flag. Internal
mode alone is not enough, because only an internal program may set the
administrator flag. On Solo the door that setup steps use, sd-solo -internal,
admits a session only on a one-shot marker file the installer writes — see
Security.
The keys#
Every binary value is base64, because the interface carries NUL-terminated strings and a raw 32-byte digest would contain a mark character about one time in nine. The argument buffers are zeroed when a call ends.
| Key | Value | Arguments | Result |
|---|---|---|---|
SDEXT_TestIt |
1 | any | Prints each argument and returns a count. A diagnostic |
SD_SALT |
100 | none | A fresh salt, base64 |
SD_KEYFROMPW |
101 | password, salt | A 256-bit key derived from the password. A salt that is not 16 bytes is refused (10206) |
SD_SHA256 |
104 | one | SHA-256 of the argument |
SD_HMACSHA256 |
105 | base64 key, text message | HMAC-SHA256 |
SD_PBKDF2 |
106 | password, salt, iterations, length | Derived key |
SD_RANDBYTES |
107 | count | Random bytes |
SD_XORBYTES |
108 | two equal-length values | Their exclusive-or |
SD_CTEQUAL |
109 | two values | 1 or 0, compared in constant time |
SD_TLS_CBIND |
110 | none | This session's TLS channel binding, as the c= value its SCRAM login must carry; empty when the session is not TLS (a local pipe session) |
SD_FILE_PRIVATE |
111 | path, then FILE or DIR |
1 when the path is closed to everyone but its owner, SYSTEM and Administrators, 0 for anything else, including every failure: a caller that tests for 1 refuses |
SD_USER_HOME |
112 | a path relative to the home, or empty | The absolute path of that directory below the running user's AppData\Local, made private when it is missing; empty on every failure |
SD_DPAPI_PROTECT |
130 | one | Encrypts the argument with Windows' DPAPI, for this Windows user; the result is base64. $internal callers only |
SD_DPAPI_UNPROTECT |
131 | one | The reverse. $internal callers only |
SD_KEYRING |
120 | set name key · clear name · list |
The key ring of the XE conversion: the key id, the number removed, or one field per key. Reached only through !keyset, !keyclear and !keylist |
Numbers 102 and 103 were the POSIX effective-identity calls. They were removed and the numbers are not reused, so a program calling one gets the unknown-key response rather than a different function.
SD_CTEQUAL reports a malformed argument as an error rather than as 0,
because by the time the login path compares these values both sides are the
server's own — a decode failure there is a defect, not a wrong password. A
caller deciding whether to admit a login must still treat the error as a
refusal.
The two DPAPI keys are the kept copy of your account password. (They are
SD_DPAPI_PROTECT and SD_DPAPI_UNPROTECT, keys 130 and 131; 130 to 139 are
the numbers reserved for keys that exist only on Windows.) DPAPI
encrypts for a Windows user, so what the first produces only that user can turn
back. It is Solo's, not the multiuser SD's, and the plaintext each one held is
wiped after use.
What uses it#
Every shipped program that calls sdext() is an internal program, which runs only
from the global catalog and cannot be compiled by an ordinary account. They are
the credential and login ones —
apisrvr, cred_set, cred_verify, login, sd_get_salt, sd_key_from_pw,
sdclient and solo_store_pw (which keeps and reads back the account password
for sd-solo <command>) — the programs for scheduled jobs, phantoms, the remote door and network
logins (solojob, tool_solojobs, phantom, ipc_seal, remotedoor,
setnetlogin, netcred), the two that keep a recovery copy or a debugger
store in a private folder (edit_recovery, pdbg_store), the embedded-Python interface (the
py_* programs, with their own keys, described in the Python chapter), and the
three key ring subroutines keyring_set, keyring_clear and keyring_list. The
last three are cataloged for general use as !keyset, !keyclear and
!keylist, so an application reaches the ring without reaching sdext(). The
others are not cataloged for general use as a way to reach the interface, so they
are not an indirect route to it either. login is the program SD runs at every
sign-in.
Two constants that are not SDEXT keys#
SD_ENCODEHX (201) and SD_ENCODE64 (202) are defined alongside the SDEXT
keys and are easily mistaken for them. They are not keys and sdext() does not
implement them: passing either as a key returns a key error. They are the
third argument to sdencrypt() and sddecrypt().