User Tools

Site Tools


init-abtproxy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

init-abtproxy [2026-04-18 09:08 UTC (7 months ago)] – created aaronjamtinit-abtproxy [2026-11-23 00:38 UTC (5 days ago)] (current) – add information about how abtproxy is used by nx qkb
Line 1: Line 1:
 ====== ABT Proxy ====== ====== ABT Proxy ======
  
-This is a systemd service started automatically on boot. It executes ''%%/init/abtproxy/abtproxy%%'', which in turn executes ''%%proxy_server%%'' (and restarts it on failure). In ''%%/init/abtproxy%%'' there are 4 JSON configuration files (''%%config.json  denylist.json  keys.json  labels.json%%''), a ''%%logs%%'' folder, and a SQLite 3 database ''%%proxyDB.db%%''.+''%%init-abtproxy.service%%'' runs ''%%/init/abtproxy/abtproxy%%'', a bash wrapper 
 +around ''%%proxy_server%%''. If the server dies the wrapper waits five seconds and 
 +starts it again with ''%%reboot_crash%%'' in argv, so it knows that's what 
 +happened. systemd restarts the wrapper itself after three seconds.
  
-===== SQLite Database ===== +''%%proxy_server%%'' is the Bytemark ABT client and the local HTTP server nx uses. 
-The database contains a single table ''%%OfflineTransactions%%'', which contains a single column ''%%TRANSACTION_DATA%%'' (of type ''%%TEXT%%''). There is a single row inside this table, which contains a JSON string like the following (partially redacted, as I'm not sure how much of this information is identifying):+nx never talks to the cloud directly; everything goes through here. 
 + 
 +Files in ''%%/init/abtproxy%%'': 
 + 
 +^ file ^ contents ^ 
 +| ''%%config.json%%'' | operator config: OAuth, endpoints, IDs, timings, messages, log limits, agency flags | 
 +| ''%%keys.json%%'' | cached card keys | 
 +| ''%%labels.json%%'' | 79 fare products | 
 +| ''%%denylist.json%%'' | about 1.3 MB of blocked tokens | 
 +| ''%%proxyDB.db%%'' | offline queue, SQLite | 
 +| ''%%logs/%%'' | request and sync logs, plus ''%%LOGTRACE.log%%'' and ''%%OUTFILE.log%%'' | 
 +| ''%%VERSION.info%%'' | ''%%V1.3.6%%'' | 
 + 
 +The logs are noisy and rotate by count and age. 
 + 
 +===== HTTP ===== 
 + 
 +nx talks to port 80 (config: ''%%HTTP Server Port%%''): ''%%/v1/device/keys%%'', 
 +''%%/v1/device/labels%%'', and ''%%POST /v1/device/transactions%%''. 
 + 
 +Going out, it's Bytemark's UVAPI. OAuth2 client credentials get a bearer token. 
 +After that ''%%validate_now%%'' answers taps, ''%%validation_event_batches%%'' takes the 
 +offline queue, ''%%validation_lists%%'' refreshes the denylist, and 
 +''%%validator_operating_data%%'' refreshes labels. Keys and tokens are separate 
 +endpoints. 
 + 
 +Denylist, labels, and uploads resync every five minutes here; keys have their own 
 +period. 
 + 
 +===== A tap ===== 
 + 
 +Online: nx sends the tap to ''%%proxy_server%%'', which asks ''%%validate_now%%''; the answer 
 +goes on screen. The cloud decides. 
 + 
 +Offline: ''%%ProxyValidation%%'' uses the cached denylist and keys and queues the tap 
 +in ''%%proxyDB.db%%''. ''%%ProxyDecryption%%'' and ''%%ProxyKeysMapper%%'' unwrap the payload 
 +first; ''%%ProxyPassback%%'' handles the anti-passback timeout. 
 + 
 +===== SQLite database ===== 
 + 
 +The SQLite database is actually a stored queue, located in ''%%proxyDB.db%%'': 
 + 
 +<code> 
 +CREATE TABLE OfflineTransactions (TRANSACTION_DATA TEXT NOT NULL); 
 +</code> 
 + 
 +A row is a tap, stored as JSON: 
 + 
 +<code> 
 +{"data": { 
 +  "barcode_data": {"barcode_payload": "", "barcode_timestamp": ""}, 
 +  "device_identifier": "", 
 +  "device_type": "OBV", 
 +  "media_identifier": "", 
 +  "media_scheme": "BYTEMARK", 
 +  "media_type": "ENCRYPTED_PAYLOAD", 
 +  "result": "valid", 
 +  "timestamp": "", 
 +  "transit_data": {"block_id": "", "location": "", "operator_id": "", 
 +                   "route": "", "vehicle_identifier": ""} 
 +}} 
 +</code> 
 + 
 +Rows upload in batches to ''%%validation_event_batches%%'' and are cleared. 
 + 
 +===== Cached JSON ===== 
 + 
 +The cached JSON is plain. ''%%labels.json%%'' is ''%%{"labels":[...]}%%''. Each entry is 
 +a fare product with ''%%id%%'', ''%%type%%'', ''%%value%%'', ''%%group%%'', and 
 +''%%additional_items%%''. ''%%denylist.json%%'' is a Bytemark envelope: ''%%data.list_name%%'', 
 +''%%data.list_version%%'', ''%%data.mediums%%'', ''%%errors%%'', ''%%server_time%%''. 
 +''%%keys.json%%'' is ''%%{"keys":[...]}%%''. 
 + 
 +===== Without the cloud ===== 
 + 
 +Serve the cached keys and labels on port 80 and nx comes up. No OAuth, no 
 +validation. See [[nx]].
  
-  { 
-     "data" : { 
-        "barcode_data" : { 
-           "barcode_payload" : "http://weixin.qq.com/r/[REDACTED]", 
-           "barcode_timestamp" : "" 
-        }, 
-        "device_identifier" : "[REDACTED]", 
-        "device_type" : "OBV", 
-        "media_identifier" : "[REDACTED]", 
-        "media_scheme" : "BYTEMARK", 
-        "media_type" : "ENCRYPTED_PAYLOAD", 
-        "result" : "valid", 
-        "timestamp" : "2024-11-16T20:54:00.708Z", 
-        "transit_data" : { 
-           "block_id" : "[REDACTED]", 
-           "location" : "", 
-           "operator_id" : "", 
-           "route" : "[REDACTED]", 
-           "vehicle_identifier" : "[REDACTED]" 
-        } 
-     } 
-  } 
init-abtproxy.1776503318.txt.gz · Last modified: by aaronjamt