Skip to main content

Auth Guide

Overview

Auth is the central component of SST. It is a local authentication and authorization service that sits near the entities it serves. Every entity in an SST network must contact Auth before communicating securely with another entity.

Auth is responsible for:

  • authenticating registered entities using public-key or pre-shared distribution-key credentials;
  • checking communication policy before issuing session keys;
  • generating and distributing symmetric session keys to authorized entities;
  • maintaining a SQLite database of registered entities, communication policies, trusted Auths, and cached session keys;
  • communicating over HTTPS with other trusted Auth instances in multi-Auth deployments;
  • optionally supporting backup, migration, delegation, and file-sharing workflows.

The Auth implementation lives under auth/ in the iotauth/iotauth repository.

Module layout

auth/
├── auth-server/ Main Auth server application (IntelliJ/Maven project)
│ └── src/main/
│ ├── java/org/iot/auth/
│ │ ├── AuthServer.java Entry point and lifecycle
│ │ ├── AuthCommandLine.java Interactive CLI handler
│ │ └── server/ Request handlers and connection logic
│ └── resources/logback.xml Logging configuration
├── library/ Shared library: database, crypto, config, messages
│ └── src/main/java/org/iot/auth/
│ ├── config/ AuthServerProperties and configuration constants
│ ├── crypto/ Cryptographic helpers
│ ├── db/ AuthDB, RegisteredEntity, CommunicationPolicy, TrustedAuth, SessionKeyPurpose
│ ├── exception/ Auth-specific exceptions
│ ├── io/ I/O helpers
│ ├── message/ Message types between Auth and entities
│ └── util/ Utility functions
├── example-auth-db-generator/ Generates example Auth SQLite databases from graph configs
├── migration-solver/ Optimization solver for migration plan generation (requires Gurobi)
├── credentials/ Auth keystores and certificates (generated)
├── databases/ SQLite databases (generated)
└── properties/ Auth runtime properties files (generated)

Prerequisites

  • Java 11 or newer (IntelliJ IDEA recommended for development; VSCode with the Java and Maven extensions also works)
  • Maven CLI (mvn)

On macOS:

brew install openjdk maven

On Ubuntu:

sudo apt-get install openjdk-17-jdk maven

Build

From auth/auth-server/:

mvn clean install

This produces a self-contained JAR at:

auth/auth-server/target/auth-server-jar-with-dependencies.jar

Alternatively, use the provided Makefile:

cd auth/auth-server
make

Start Auth

Auth requires a generated properties file. Properties and databases are created by the example generator (see Network Configuration):

cd examples
./generateAll.sh

Then start Auth from auth/auth-server/:

java -jar target/auth-server-jar-with-dependencies.jar -p ../properties/exampleAuth101.properties

Auth is ready when the interactive prompt appears:

Enter command (e.g., show re/cp/ta/sk/maps/dp/di, add/remove re/cp/dp...):

Command-line options

FlagLong formRequiredPurpose
-p--propertiesYesPath to the Auth properties file.
-b--base_pathNoBase directory for resolving relative file paths in the properties file.
-s--passwordNoAuth keystore password (not recommended for production; Auth will prompt interactively if omitted).
-d--debugNoEnable debug-level logging.

Running from IntelliJ IDEA

Open the project at $ROOT/auth in IntelliJ. Configure a Run/Debug configuration with:

  • Main class: org.iot.auth.AuthServer
  • Program arguments: -p ../properties/exampleAuth101.properties
  • Working directory: $ROOT/auth/auth-server

Reference screenshots from auth/README.md show the expected configuration for Auth 101 and Auth 102.

Running from VSCode

Add a launch configuration to .vscode/launch.json:

{
"type": "java",
"name": "AuthServer",
"request": "launch",
"mainClass": "org.iot.auth.AuthServer",
"args": "-p ../properties/exampleAuth101.properties"
}

CLI reference

Once Auth is running, the interactive prompt accepts the following commands.

Inspect state

CommandDescription
show rePrint all registered entities and their configuration.
show cpPrint all communication policies.
show taPrint all trusted Auth records.
show skPrint all cached session keys.
show mapsPrint internal maps for the UDP listener port.
show dpPrint all delegation privileges.
show diPrint all delegation info records.
helpList all available commands.

Manage session keys

CommandDescription
clean skRemove expired session keys from the database.
reset skDelete all cached session keys.

Manage registered entities

CommandDescription
add reInteractively add a new registered entity to the database.
remove reInteractively remove a registered entity.
reset reDelete all entities that were backed up from other Auths.

Manage communication policies

CommandDescription
add cpInteractively add a new communication policy.
remove cpInteractively remove a communication policy.

Manage delegation privileges

CommandDescription
add dpInteractively add a new delegation privilege record.
remove dpInteractively remove a delegation privilege record.

Other operations

CommandDescription
issue cert or icIssue a certificate for an entity.
backupBack up registered entities to a trusted Auth.
quitShut down Auth and exit.

Properties file reference

Generated properties files live under auth/properties/. Each Auth instance has its own properties file.

Identity

PropertyTypeDescription
auth_idintegerUnique Auth ID. Must match the id in the .graph file and entity configs.
host_namestringHostname or IP address for this Auth instance.

Ports

PropertyTypeDescription
entity_tcp_portintegerTCP port that entities use to request session keys.
entity_tcp_port_timeoutlong (ms)TCP connection timeout.
entity_udp_portintegerUDP port for entity requests when UDP distribution is used.
entity_udp_port_timeoutlong (ms)UDP socket timeout.
trusted_auth_portintegerHTTPS port for Auth-to-Auth communication.
trusted_auth_port_idle_timeoutlong (ms)Idle timeout for trusted Auth connections.
contextual_callback_portintegerPort for contextual callback handling.
contextual_callback_port_idle_timeoutlong (ms)Idle timeout for callback connections.
contextual_callback_enabledbooleanEnable or disable contextual callback support.

Credentials

PropertyTypeDescription
entity_key_store_pathpathKeystore used for entity-facing TLS/credential operations.
internet_key_store_pathpathKeystore used for Auth-to-Auth HTTPS.
database_key_store_pathpathKeystore used for database protection.
database_encryption_key_pathpathSymmetric key used for database encryption (when protection method requires it).
trusted_ca_cert_pathspathsSemicolon-separated paths to trusted CA certificates.

Database

PropertyTypeDescription
auth_database_dirpathDirectory containing the Auth SQLite database.
auth_db_protection_methodintegerDatabase protection mode (0 = none, 1 = encryption).

Optional features

PropertyTypeDefaultDescription
backup_enabledbooleanfalseEnable backup of registered entities to trusted Auths.
bluetooth_enabledbooleanfalseEnable Bluetooth entity listening.
qps_throttling_enabledbooleanfalseEnable per-entity queries-per-second rate limiting.
qps_limitfloatMaximum session key requests per second per entity.
qps_calculation_bucket_size_in_secintegerWindow size in seconds for QPS calculation.
cleanup_cycle_in_mslongHow often Auth removes expired session keys and policies.

Database tables

Auth stores all runtime state in a SQLite database. The database is generated by example-auth-db-generator during the generateAll.sh step.

TableContents
RegisteredEntityOne row per registered entity: identity, crypto specs, distribution key material, active status, backup routing, and migration token.
CommunicationPolicyOne row per allowed communication relationship: requesting group, target type and name, session crypto spec, validity periods, expiration, and delegation flag.
TrustedAuthOne row per trusted Auth peer: host, ports, heartbeat settings, and PEM certificates.
CachedSessionKeySymmetric session keys issued to entities, with ownership list, expiration, purpose, and crypto spec.
DelegationPrivilegeDelegation privilege records: privilege type, privileged group, subject, object, validity, and JSON metadata.
DelegationInfoDelegation hierarchy: communication-policy-token ID, parent ID, delegation timestamp, and revocation timestamp.
FileSharingInfoFile-sharing access-control: owner entity, reader entity/group, and reader type.
MetaDataAuth-level StringString key/value metadata. Predefined keys: SessionKeyCount, EncryptedDatabaseKey, CommPolicyCount.

RegisteredEntity columns

ColumnTypeDescription
NameStringUnique entity identifier, e.g. net1.client.
GroupStringLogical group such as Clients, Servers, PtPublishers, or PtSubscribers.
DistProtocolStringProtocol Auth uses for the distribution channel: TCP or UDP.
UsePermanentDistKeybooleanIf true, Auth uses a pre-shared symmetric distribution key instead of public-key credentials.
DistKeyValidityPeriodlongHow long a freshly issued distribution key remains valid (ms).
PublicKeyValueStringPEM-encoded entity public key (used when UsePermanentDistKey is false).
PublicKeyFileStringPath to the entity's public key file (alternative to inline PublicKeyValue).
PublicKeyCryptoSpecStringPublic-key algorithm spec for the distribution channel setup handshake.
DistCryptoSpecStringSymmetric cipher and MAC for the Auth-entity distribution channel.
DistKeyExpirationTimelongAbsolute expiration timestamp of the current distribution key (Unix ms).
DistKeyValuebyte[]Current symmetric distribution key value (stored encrypted).
MaxSessionKeysPerRequestintMaximum session keys Auth will issue in a single request from this entity.
ActivebooleanWhether the entity registration is active.
BackupToAuthIDsStringComma-separated Auth IDs to which this entity record may be backed up.
BackupFromAuthIDintAuth ID that originally owned this record (set when imported via backup).
MigrationTokenStringToken exchanged during entity migration workflows.

CommunicationPolicy columns

ColumnTypeDescription
IDlongAuto-assigned policy identifier.
RequestingGroupStringEntity group that may invoke this policy (e.g. Clients).
TargetTypeStringPolicy type: Group, PubTopic, SubTopic, or Delegation.
TargetStringTarget group name, topic name, or entity name, depending on TargetType.
MaxNumSessionKeyOwnersintMaximum entities that may simultaneously hold the same session key.
SessionCryptoSpecStringCipher and MAC for session keys issued under this policy.
AbsoluteValiditylongAbsolute validity duration for issued session keys (ms).
RelativeValiditylongRelative validity from first use (ms).
ExpirationlongTimestamp after which this policy itself expires (Unix ms).
IsDelegatedintWhether this policy was established via a delegation grant (0 = false, 1 = true).

TrustedAuth columns

ColumnTypeDescription
IDintTrusted Auth's integer identifier.
HostStringHostname for internet-facing Auth-to-Auth HTTPS.
EntityHostStringHostname that entities use to reach this Auth.
PortintPort for Auth-to-Auth communication.
HeartbeatPeriodintInterval (ms) for heartbeat messages sent to this peer.
FailureThresholdintMissed heartbeats before the peer is considered unavailable.
InternetCertificateValueStringPEM certificate for internet-facing connections (inline).
EntityCertificateValueStringPEM certificate for entity-facing connections (inline).
BackupCertificateValueStringPEM certificate used in backup workflows (inline).
InternetCertificatePathStringFile path alternative to inline InternetCertificateValue.
EntityCertificatePathStringFile path alternative to inline EntityCertificateValue.

CachedSessionKey columns

ColumnTypeDescription
IDlongUnique session key identifier issued by Auth.
OwnersStringSerialized list of entity names currently holding this key.
MaxNumOwnersintMaximum number of concurrent owners allowed.
PurposeStringEncoded purpose (requesting group and target group).
ExpirationTimelongAbsolute expiration timestamp (Unix ms).
RelValiditylongRelative validity duration from first use (ms).
CryptoSpecStringCipher and MAC spec, e.g. AES-128-CBC:SHA256.
KeyValbyte[]Encrypted key material.
ExpectedOwnerGroupsStringGroups from which the key's owners are expected to come.

DelegationPrivilege columns

ColumnTypeDescription
PrivilegeTypeStringPrivilege category, e.g. DELEGATE or READ.
PrivilegedGroupStringEntity group granted this privilege.
SubjectStringThe granting entity or scope subject.
ObjectStringThe resource or target group this privilege applies to.
ValidityStringDuration or expiration for this privilege.
InfoJSONObjectJSON object with additional privilege metadata.

DelegationInfo columns

ColumnTypeDescription
CPTIdlongCommunication-policy-token ID this delegation is associated with.
ParentlongParent delegation record ID (forms a delegation chain).
DelegatedTimelongUnix timestamp (ms) when this delegation was granted.
RevokedTimelongUnix timestamp (ms) when this delegation was revoked (0 if still active).

FileSharingInfo columns

ColumnTypeDescription
OwnerStringEntity that owns the file.
ReaderStringEntity name or group name authorized to read the file.
ReaderTypeStringentity or group, indicating how Reader should be interpreted.

Registered entities

Each entity in the RegisteredEntity table has the attributes described in the database tables section above. Key concepts:

  • Name / Group: Name uniquely identifies the entity; Group determines which communication policies apply.
  • Distribution key: Auth and the entity share a symmetric distribution key used to encrypt session key responses. When UsePermanentDistKey is true, this key is fixed; otherwise Auth issues a fresh key each session.
  • Public-key credentials: When UsePermanentDistKey is false, the entity authenticates with its RSA private key and Auth uses PublicKeyValue (or PublicKeyFile) to verify the signature.
  • Backup / migration: BackupToAuthIDs controls which Auths receive copies of this record. BackupFromAuthID marks records imported from a peer, and MigrationToken is exchanged during live migration handoffs.

Communication policies

A communication policy in the CommunicationPolicy table grants a group of entities permission to obtain session keys for a specific target. Auth checks policy before issuing any session key. See the database tables section for the full column list.

Policy target types

TargetTypeMeaning
GroupRequestingGroup may communicate with all entities in the Target group. Standard client/server use case.
PubTopicRequestingGroup may publish to the Target topic.
SubTopicRequestingGroup may subscribe to the Target topic.
DelegationAccess established via a delegation grant, verified against DelegationInfo records.

Session key request flow

This is the core interaction between an entity and Auth:

  1. Entity connects to Auth's TCP (or UDP) port.
  2. Entity sends a session key request authenticated with its distribution key or private key.
  3. Auth validates the entity's nonce and signature/MAC.
  4. Auth looks up the entity in RegisteredEntity and retrieves or refreshes its distribution key.
  5. Auth evaluates the matching CommunicationPolicy for the requested target group or key ID.
  6. If policy permits and the owner count limit is not exceeded, Auth generates or retrieves session keys from CachedSessionKey.
  7. If the target entity belongs to a different (trusted) Auth, Auth forwards a request to that peer over HTTPS.
  8. Auth encrypts the session keys with the entity's distribution key and sends the response.
  9. Both the client and the server can now use the shared session key to establish an encrypted channel directly, without further Auth involvement.

Multi-Auth deployments

SST supports multiple Auth instances connected by trust relationships. Each Auth maintains a TrustedAuth table. See the database tables section for the full column list.

Auth instances exchange heartbeat messages to monitor peer availability. When an entity belonging to a remote Auth requests a session key for communicating with a local entity, Auth forwards the request to the remote Auth over HTTPS and relays the result.

Trust relationships are defined in the .graph file under authTrusts and are populated into the TrustedAuth table during database generation.

Backup and migration

When backup_enabled is set in the properties file, Auth periodically sends copies of its registered entity records to trusted Auth peers listed in each entity's BackupToAuthIDs field. This allows a backup Auth to serve entities whose primary Auth has failed.

The migration-solver module provides an optimization tool, built on the Gurobi optimizer, for computing optimal migration plans across a multi-Auth topology. It reads scenario JSON files and produces migration assignments that maximize availability. Gurobi requires a separate academic or commercial license; the gurobi.jar file must be obtained independently.

Testing

The Auth library has a unit test suite in auth/library/src/test/java/org/iot/auth/AppTest.java (865 lines, 17 test methods). The tests exercise every database table, the message-type constants, and the crypto helpers.

Running the tests

From auth/library/:

mvn test

Or from the repository root:

cd auth
mvn test

Maven compiles, then runs the JUnit suite. The tests create and destroy a temporary encrypted SQLite database in auth/library/src/test/test_files/databases/ and leave no persistent state.

Test file layout

auth/library/src/test/
├── java/org/iot/auth/AppTest.java JUnit test class
└── test_files/
├── databases/ Temporary test databases (created/deleted by tests)
├── entity_certs/ PEM certificates for test entities
├── trusted_auth_certs/ PEM certificates for the trusted Auth under test (Auth 102)
└── properties/ Auth properties files used by tests

Test methods

All tests use ENCRYPT_CREDENTIALS as the database protection method, which exercises the full encrypted-SQLite code path.

Test methodWhat it covers
testConstant()Validates C.AUTH_NONCE_SIZE equals 8.
testMessageType()Verifies byte values and round-trip conversion for 39+ message-type enum entries.
testAuthHello()Constructs an AuthHello message and checks its serialized form.
testRegEntityInsertionAndSelectAll()Inserts 4 entities (Clients, PtClients, Servers, PtServers) and reads all back.
testCommPolicyInsertionAndSelectAll()Inserts 8 policies covering Group, PubTopic, and SubTopic target types and reads all back.
testTrustedAuthInsertionAndSelectAll()Inserts trusted Auth 102 with PEM certificates and reads it back.
testFileSharingTable()Tests entity-level and group-level reader entries in file_sharing_info.
testCachedSessionKeyInsertionAndSelectAll()Inserts 2 session keys (AES-128-CBC:SHA256) and reads all back.
testCachedSessionKeySelectById()Retrieves a specific cached session key by its ID (42).
testCachedSessionKeySelectByPurpose()Filters cached session keys by encoded purpose string.
testCachedSessionKeyAppendOwner()Appends a new owner to a cached session key and verifies the owner list.
testCachedSessionKeyDeleteAll()Deletes all cached session keys and verifies the table is empty.
testFileSharingInsertionAndSelectByOwner()Retrieves file-sharing records filtered by owner entity name.
testDelegationPrivilegeInsertionAndSelectAll()Inserts DELEGATE and READ privilege records; filters by privileged group.
testDelegationInfoInsertionAndGetChildren()Inserts a 3-level delegation chain (IDs 100→101→102) and retrieves children by parent ID.
testMetaDataInsertionAndUpdate()Inserts SessionKeyCount = "0", updates it to "5", and reads the updated value.

Setup and teardown are handled by createTestAuthDB() and destroyTestAuthDB(), which are called before and after the database-dependent tests.