Skip to content

[devices] public key operations - #258

Open
capcom6 wants to merge 2 commits into
masterfrom
devices/public-key-support
Open

capcom6 wants to merge 2 commits into
masterfrom
devices/public-key-support

Conversation

@capcom6

@capcom6 capcom6 commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

RetriggerConfidence Score: 5/5

This PR is safe to merge with minimal risk

Summary

This PR adds public key infrastructure for end-to-end encryption. The changes add two nullable columns to the devices table: public_key (text) and key_version (int), exposed through device registration and update endpoints.

Major changes:

  • E2E key storage — devices can now register an RSA public key with version tracking for key rotation
  • Phone number expansion — recipient phone number storage increased from 128 to 512 characters
  • Documentation — new CHANGELOG.md documents the public key feature and updated .env.example with clarified config descriptions
Diagram
sequenceDiagram
    participant Client as Android App
    participant Handler as Mobile Handler
    participant Service as Device Service
    participant Repo as Repository
    participant DB as MySQL

    Note over Client,DB: Device Registration with E2E Key
    Client->>Handler: "POST /mobile/v1/device<br/>{publicKey, keyVersion, ...}"
    Handler->>Handler: Validate (go-playground/validator)
    Handler->>Service: RegisterDevice(publicKey, keyVersion)
    Service->>Repo: Insert(device)
    Repo->>DB: "INSERT INTO devices<br/>(public_key, key_version, ...)"
    DB-->>Repo: OK
    Repo-->>Service: Device
    Service-->>Handler: Device
    Handler-->>Client: "201 {id, token}"

    Note over Client,DB: Key Rotation via Update
    Client->>Handler: "PATCH /mobile/v1/device<br/>{publicKey, keyVersion}"
    Handler->>Handler: Validate new key pair
    Handler->>Service: Update(publicKey, keyVersion)
    Service->>Repo: Update(device)
    Repo->>DB: "UPDATE devices<br/>SET public_key=?, key_version=?"
    DB-->>Repo: OK
    Repo-->>Service: OK
    Service-->>Handler: OK
    Handler-->>Client: 204 No Content
Loading

Reviews (39) · Last reviewed commit: "[docs] create changelog, update dotenv e..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

🤖 Pull request artifacts

Platform File
🐳 Docker GitHub Container Registry
🍎 Darwin arm64 server_Darwin_arm64.tar.gz
🍎 Darwin x86_64 server_Darwin_x86_64.tar.gz
🐧 Linux arm64 server_Linux_arm64.tar.gz
🐧 Linux i386 server_Linux_i386.tar.gz
🐧 Linux x86_64 server_Linux_x86_64.tar.gz
🪟 Windows arm64 server_Windows_arm64.zip
🪟 Windows i386 server_Windows_i386.zip
🪟 Windows x86_64 server_Windows_x86_64.zip

@capcom6
capcom6 force-pushed the devices/public-key-support branch from 1c556ac to f8364a1 Compare July 29, 2026 07:50
@capcom6
capcom6 marked this pull request as ready for review July 29, 2026 07:50
Comment thread internal/sms-gateway/modules/devices/repository.go
Comment thread internal/sms-gateway/openapi/docs.go Outdated
Comment thread internal/sms-gateway/modules/devices/models.go Outdated
@capcom6
capcom6 force-pushed the devices/public-key-support branch from 7b74cd5 to 0bd4583 Compare July 30, 2026 00:29
@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@capcom6
capcom6 force-pushed the devices/public-key-support branch from 0bd4583 to 3d10ade Compare July 31, 2026 02:16
@capcom6
capcom6 force-pushed the devices/public-key-support branch from 4303779 to b167711 Compare August 1, 2026 01:21
Comment thread internal/sms-gateway/modules/devices/service.go Outdated
@capcom6

capcom6 commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@capcom6
capcom6 force-pushed the devices/public-key-support branch 3 times, most recently from 0883119 to 90b1780 Compare August 4, 2026 07:39
@capcom6 capcom6 added the ready label Aug 4, 2026
@capcom6
capcom6 force-pushed the devices/public-key-support branch from 90b1780 to 7b24780 Compare August 5, 2026 01:01
@github-actions github-actions Bot removed the ready label Aug 5, 2026
@capcom6 capcom6 added the ready label Aug 5, 2026
@github-actions github-actions Bot removed the ready label Aug 7, 2026
@capcom6
capcom6 force-pushed the devices/public-key-support branch 2 times, most recently from 5e03d03 to 04f32ec Compare August 10, 2026 02:55
Comment thread internal/sms-gateway/handlers/mobile.go
@capcom6
capcom6 force-pushed the devices/public-key-support branch from 5649879 to 8b37237 Compare August 11, 2026 02:13
Comment thread internal/sms-gateway/modules/devices/domain.go
@capcom6
capcom6 force-pushed the devices/public-key-support branch 3 times, most recently from 066ae5e to 7b16d41 Compare August 13, 2026 08:25
@capcom6 capcom6 added the ready label Aug 14, 2026
@capcom6
capcom6 force-pushed the devices/public-key-support branch from 7b16d41 to f24a89c Compare August 18, 2026 00:43
@github-actions github-actions Bot removed the ready label Aug 18, 2026
Comment thread internal/sms-gateway/modules/devices/repository.go
@capcom6 capcom6 added the ready label Aug 19, 2026
@capcom6
capcom6 force-pushed the devices/public-key-support branch from f24a89c to 7957312 Compare August 20, 2026 00:43
@github-actions github-actions Bot removed the ready label Aug 20, 2026
@capcom6 capcom6 added the ready label Aug 20, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 7 days with no activity.

@github-actions github-actions Bot added the stale label Aug 27, 2026
@capcom6
capcom6 force-pushed the devices/public-key-support branch from a237aea to a1da645 Compare September 2, 2026 00:48
@capcom6 capcom6 added the ready label Sep 3, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 7 days with no activity.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 7 days with no activity.

@github-actions github-actions Bot added the stale label Sep 20, 2026
@capcom6 capcom6 removed the stale label Sep 21, 2026
@capcom6
capcom6 force-pushed the devices/public-key-support branch from 3c3e7fe to 22a4d30 Compare September 25, 2026 01:06
@github-actions github-actions Bot removed the ready label Sep 25, 2026
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Comments Outside Diff

These findings could not be posted inline.

  • P1 E2E consistency not validated on device registration internal/sms-gateway/modules/devices/service.go:42 ▶

    The ErrInconsistentE2E guard exists in Update, but Insert has no equivalent check. RegisterDevice calls devicesSvc.Insert directly, so a registration request that supplies publicKey without keyVersion (or vice versa) bypasses the pairing validation entirely and persists the inconsistent state to the DB - exactly the case Update is designed to prevent.

@capcom6
capcom6 force-pushed the devices/public-key-support branch 2 times, most recently from 893f96b to afb29c4 Compare September 30, 2026 01:54
Comment thread .env.example Outdated
@capcom6
capcom6 force-pushed the devices/public-key-support branch from 32fc859 to e2d3e6d Compare October 2, 2026 00:37
@capcom6
capcom6 force-pushed the devices/public-key-support branch from e2d3e6d to 81b9743 Compare October 7, 2026 07:25

This branch has not been deployed

No deployments
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