Skip to content

Identify genuine vs simulated G7 sensors from their identity certificate - #86

Merged
ps2 merged 1 commit into
next-devfrom
g7-sensor-authenticity
Oct 11, 2026
Merged

ps2 merged 1 commit into
next-devfrom
g7-sensor-authenticity

Conversation

@ps2

@ps2 ps2 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

A real G7 proves itself during pairing: it streams an X.509 P-256 certificate chain (leaf → DEX01PG2 → DEX00PG1) and signs the key challenge (ECDSA r‖s over SHA256 of our nonce) with its leaf key. We were discarding both. This validates them and records whether the sensor is genuine Dexcom, the LoopKit/g7sim development emulator, or unverified.

  • G7SensorIdentity: SecTrust with the Dexcom sensor intermediate (DEX01PG2) and the emulator's dummy CA pinned as anchors; CryptoKit verifies the challenge signature against the leaf. Dexcom chain → genuine, dummy CA → simulated, otherwise unverified.
  • G7Authenticator captures the leaf, nonce and signature; the verdict flows through both the pairing path and the session-auth path into G7CGMManagerState.sensorAuthenticity and persists across reconnects.
  • Settings shows a critical "Simulated Sensor" warning for the emulator. Tapping it offers to hide it (for development screenshots); the dismissal resets on the next pairing.
  • HealthKit metadata: when simulated, each reading's HKDevice reports manufacturer g7sim (Simulator), model <model> Simulator, and no UDI, so synced data (HealthKit, Nightscout) is never mistaken for a genuine G7.

Validation never blocks a reading: an unrecognized sensor is treated as real.

Testing

  • 6 unit tests (G7SensorIdentityTests) against a captured real DXCMTR chain/signature and the emulator's own Go-generated certificate: genuine, simulated, garbage cert, tampered signature, wrong length, wrong nonce.
  • On device: paired the g7sim emulator; persisted state shows sensorAuthenticity = simulated, the warning appears, and hiding it persists.

A real G7 proves itself during pairing: it streams an X.509 P-256
certificate chain and signs the key challenge (ECDSA r‖s over
SHA256(nonce)) with its leaf key. Loop discarded both. This validates
them and records whether the sensor is a genuine Dexcom, the g7sim
development emulator, or could not be verified.

- G7SensorIdentity: SecTrust-pins the Dexcom sensor intermediate
  (DEX01PG2) and the emulator's dummy CA as trust anchors, and verifies
  the challenge signature against the leaf with CryptoKit. Chains to
  Dexcom → genuine, to the dummy CA → simulated, else unverified.
- G7Authenticator captures the leaf cert, nonce, and signature during
  both pairing and session auth and evaluates authenticity; the verdict
  is threaded through the pairing path and session path into state and
  persisted across reconnects.
- Settings shows a critical "Simulated Sensor" warning for the emulator,
  tappable to hide (resets on the next pairing) for development
  screenshots.
- Every reading's HKDevice reports a "g7sim (Simulator)" manufacturer and
  model and drops Dexcom's UDI when simulated, so data synced to
  HealthKit and onward is never mistaken for a genuine G7.

Validation never blocks a reading: an unrecognized sensor is treated as
real. Six unit tests cover the verdicts against a real DXCMTR capture and
the emulator's own certificate.
@ps2
ps2 merged commit 2a8716c into next-dev Oct 11, 2026
@ps2
ps2 deleted the g7-sensor-authenticity branch October 11, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant