[devices] public key operations - #258
Conversation
🤖 Pull request artifacts
|
1c556ac to
f8364a1
Compare
7b74cd5 to
0bd4583
Compare
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
0bd4583 to
3d10ade
Compare
4303779 to
b167711
Compare
|
@greptile review |
0883119 to
90b1780
Compare
90b1780 to
7b24780
Compare
5e03d03 to
04f32ec
Compare
5649879 to
8b37237
Compare
| // PublicKey is a base64-encoded RSA public key (nil if no E2E). | ||
| // Setting a new key together with KeyVersion overwrites the previous key; | ||
| // clearing an existing key is intentionally unsupported. On insert, nil | ||
| // means the device is created without E2E; on update, a both-nil pair is | ||
| // a no-op that leaves the existing key unchanged. An empty string is | ||
| // rejected with ErrInconsistentE2E. | ||
| PublicKey *string | ||
| // KeyVersion is the key version used for rotation tracking (nil if no | ||
| // E2E). It must always be set together with PublicKey: providing exactly | ||
| // one of the two is rejected with ErrInconsistentE2E. | ||
| KeyVersion *int |
There was a problem hiding this comment.
ErrInconsistentE2E referenced in comments but never defined or enforced
Both doc-comments say inputs are "rejected with ErrInconsistentE2E", but that sentinel is not declared anywhere in the devices package (it is absent from errors.go), and no validation code in service.go or repository.go actually rejects an empty PublicKey string or a mismatched PublicKey/KeyVersion pair. The comments therefore describe a contract the implementation does not honour: empty strings and half-populated pairs are silently persisted, leaving devices in an invalid E2E state. The comments should either reflect what the code currently does, or the missing error sentinel and validation logic should be added.
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/sms-gateway/modules/devices/domain.go
Line: 25-35
Comment:
**`ErrInconsistentE2E` referenced in comments but never defined or enforced**
Both doc-comments say inputs are "rejected with `ErrInconsistentE2E`", but that sentinel is not declared anywhere in the `devices` package (it is absent from `errors.go`), and no validation code in `service.go` or `repository.go` actually rejects an empty `PublicKey` string or a mismatched `PublicKey`/`KeyVersion` pair. The comments therefore describe a contract the implementation does not honour: empty strings and half-populated pairs are silently persisted, leaving devices in an invalid E2E state. The comments should either reflect what the code currently does, or the missing error sentinel and validation logic should be added.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Greptile Summary
This PR adds end-to-end encryption key support to devices: two new nullable columns (
public_key,key_version) are added to thedevicestable via migration, propagated through the GORM model, domain types, service, repository, handlers, and the 3rdparty API response. It also widensmessage_recipients.phone_numberto 512 characters and removes the now-unusedErrInvalidUsersentinel.DEFAULT NULLfor both columns, and the GORM model tags are consistent with the schema.domain.gocomments describe input validation (empty-string rejection and paired-field enforcement) usingErrInconsistentE2E, but that error is not defined inerrors.goand no validation code implements the described contract — the comments document planned behaviour that does not yet exist.client-gois upgraded to an untagged pseudo-version commit rather than a stable release, which is inadvisable for a production branch merge.Confidence Score: 3/5
domain.goexplicitly promise that emptyPublicKeystrings and unpairedPublicKey/KeyVersionfields are rejected, yetErrInconsistentE2Eis not defined and no validation runs in service or repository. Any client sending a bad payload silently persists invalid state. Combined with the ongoing issues from prior review rounds (orphaned users on registration failure, domain errors surfacing as 500s in the mobile handler), the feature is functionally incomplete in a way that could corrupt device E2E state in production.internal/sms-gateway/modules/devices/domain.goandinternal/sms-gateway/modules/devices/errors.goneed attention: the promisedErrInconsistentE2Esentinel and its enforcement logic are absent.internal/sms-gateway/handlers/mobile.gostill needs error mapping for device domain errors.Important Files Changed
Sequence Diagram
sequenceDiagram participant App as Android App participant MH as Mobile Handler participant AS as Auth Service participant DS as Devices Service participant DR as Devices Repository participant DB as MySQL Note over App,DB: Device Registration (POST /mobile/v1/device) App->>MH: "{name, pushToken, publicKey, keyVersion}" MH->>AS: "RegisterDevice(userID, DeviceInfo{...})" AS->>DS: Insert(ctx, userID, DeviceInfo) DS->>DR: Insert(ctx, DeviceInput) DR->>DB: INSERT INTO devices (public_key, key_version, ...) DB-->>DR: OK DR-->>DS: Device DS-->>AS: Device AS-->>MH: Device MH-->>App: "201 {id, token, login, password}" Note over App,DB: Device Update (PATCH /mobile/v1/device) App->>MH: "{id, pushToken, publicKey, keyVersion}" MH->>DS: "Update(ctx, id, DeviceUpdate{...})" DS->>DR: Update(ctx, id, DeviceUpdate) DR->>DB: "UPDATE devices SET public_key=?, key_version=? WHERE id=?" DB-->>DR: OK DR-->>DS: nil DS-->>MH: nil MH-->>App: 204 Note over App,DB: List Devices (GET /3rdparty/v1/devices) App->>MH: GET /3rdparty/v1/devices MH->>DS: Select(ctx, userID) DS->>DR: Select(ctx, filters...) DR->>DB: "SELECT * FROM devices WHERE user_id=?" DB-->>DR: []DeviceModel DR-->>DS: []Device (with PublicKey, KeyVersion) DS-->>MH: []Device MH-->>App: "200 [{..., publicKey, keyVersion}]"Prompt To Fix All With AI
Reviews (20): Last reviewed commit: "[devices] public key operations" | Re-trigger Greptile