Commit Graph

4 Commits

Author SHA1 Message Date
A ashkan@beigi.net
c6423b1bad Harden: concurrency safety (db lock timeout, cache lock, retry, portal)
- get_connection sets PRAGMA busy_timeout so concurrent writers under a
  threaded server wait instead of hitting "database is locked".
- Provision retries credential generation on IMSI/ICCID collision (up to 5x)
  instead of surfacing a duplicate as a 500.
- Guard the module-level profile cache with a threading.Lock.
- Captive portal disables the activate button while a request is in flight to
  avoid double provisioning.

Tests: +2 (collision retry + give-up); 84 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 06:16:25 +00:00
A ashkan@beigi.net
0be02bd1f4 Harden: fix bare-filename db path crash, configurable APN
- Fix FileNotFoundError when database.path has no directory component
  (os.makedirs(os.path.dirname(path)) with path="subscribers.db" raised).
  Add ensure_parent_dir helper; use it in app.py and scripts/init_db.py.
- Open5GS/free5gc adapters now use profile.apn for the core session/DNN name
  instead of a hardcoded "internet"; apn is threaded through get_adapter.

Tests: +4 (ensure_parent_dir, adapter APN); 82 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 06:13:26 +00:00
A ashkan@beigi.net
f367103ceb Harden: capability-token profile URLs, fast core failure, config validation
Security:
- Serve generated profiles at /api/profile/<random-token> instead of
  /api/profile/<sequential-int>. Profiles carry Ki/OPc, so the enumerable id
  scheme allowed anyone on the WiFi to harvest all subscriber keys. Unknown
  tokens return a plain 404 so they can't be probed.

Robustness:
- Open5GS/free5gc adapters use short MongoDB timeouts so an unreachable core
  fails provisioning fast instead of blocking ~30s on the default.
- Profile cache is now a size-capped LRU (OrderedDict) to prevent unbounded
  memory growth.
- load_config rejects empty/non-mapping YAML and validates network.op_key is a
  16-byte hex string.

Tests: +25 (test_app.py API coverage, test_utils.py); 78 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 06:11:14 +00:00
A ashkan@beigi.net
1ade8dfc2c Phase 2: real 3GPP profile encodings + changelog
Upgrade create_esim_profile from a loose JSON mock to a structured
profile-package-v2 that embeds real 3GPP field encodings:
- enc_iccid: EF_ICCID nibble-swapped BCD, 10-byte 0xF-padded (TS 31.102 4.2.1)
- enc_imsi:  EF_IMSI length octet + parity nibble + nibble-swapped BCD (4.2.2)
- build_lpa_activation_code: SGP.22 LPA:1$<smdp>$<matching-id> string

Wire apn and smdp_address through config into the provisioning call; add
smdp_address to config.yaml.example. Add CHANGELOG.md.

Full SGP.22 SAIP/ASN.1 UPP generation via osmocom pySim remains a follow-up
(not on PyPI; needs SM-DP+/LPA for OTA install) and is noted in the changelog.

Tests: +9 (encoders, round-trips, activation code); 53 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 06:03:48 +00:00