-
Notifications
You must be signed in to change notification settings - Fork 1k
Enable APNS feedback to LoopFollow for Trio remote commands #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Companion PR: The server-side implementation for this feature can be found in the Trio repository: nightscout/Trio#740 |
|
I've pushed the latest updates to this PR, which now implements end-to-end encryption flow for remote commands. Instead of sending the shared secret for verification, I now use it as a key to encrypt the entire command payload. Here are the technical details of the implementation: Encryption Algorithm: I've implemented this using AES-256-GCM. The GCM (Galois/Counter Mode) is important because it's an authenticated encryption mode, meaning it not only ensures confidentiality but also provides data integrity, protecting against tampering. Key Derivation: The encryption key is derived from the existing shared secret (the GUID). I pass the secret through a SHA-256 hash to produce the consistent 256-bit key required for the AES algorithm. Nonce Handling: For each message sent, a new, cryptographically secure 12-byte nonce (Initialization Vector) is generated. This ensures that even identical commands result in unique ciphertext. Authentication: The shared secret is no longer sent over the network. Authentication is now implicit: if Trio can successfully decrypt the payload, the sender is proven to be authentic. Important: This is a breaking change. Current versions of LoopFollow and Trio dev will not be compatible with these new versions. Both apps must be updated together for the remote control feature to work. |
|
Important step for Browser Builders: Now that LF receives push notifications, you need to enable the Push Notifications capability at the Apple Developer site. |
TestTrio PR 740 and LoopFollow PR 445 were tested together Summary:
Comment:
Test ResultsFor these tests, Trio and LoopFollow are on the same phone, SE 3rd gen running iOS 18.6.2
The tests consisted of sending Remote Bolus from LoopFollow to Trio.
✅ LoopFollow Modal says OK - message got the Apple successfully, Trio successfully got the message, LFN bolus initiating, LFN properly reported result from Trio phone (success or failure with reason) Summary Table for Bolus Remote Commands
Detailed Tests Remote CommandsConfigure so Trio and LoopFollow are on 2 different phones.
Status: Trio Phone is available
Trio Phone is off When LoopFollow Modal says OK, it means the message got the Apple successfully. There is no response if Trio phone is offline.
|
marionbarker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did all the testing and review (see #445 (comment)).
Checking the approval box now. The timing for this needs to be coordinated with Trio and LoopFollowDocs
TestRepeat Test because of intervening merges to both Trio and LoopFollow. Summary: Trio, with PR 740 merged, and LoopFollow, with PR 445 merged, still provide the updates described in this PR. The updates for Trio, LoopFollow and LoopFollowDocs need to be coordinated - this will happen via direct messaging between developers. Test DetailsRepeat Test because of intervening merges to both Trio and LoopFollow. Configuration:
The tests consisted of sending Remote Bolus from LoopFollow to Trio.
✅ LoopFollow Modal says OK - message got to Apple successfully, Trio successfully got the message, LFN bolus initiating, LFN properly reported result from Trio phone (success or failure with reason) Summary Table for Bolus Remote Commands
|
Description
This pull request implements the client-side functionality for receiving real-time status notifications for remote commands sent to Trio or Loop. This complements the backend changes and completes the feature, allowing users to get immediate push notification feedback confirming the success or failure of their actions.
To achieve this, the app is now capable of:
return_notificationpayload to attach to every outgoing remote command.Technical Implementation
1. Push Notification Registration and Handling
AppDelegate: The app now registers for remote notifications on launch. New delegate methods have been implemented to:.entitlementsandInfo.plistfiles have been updated with the requiredaps-environmentandremote-notificationbackground mode capabilities, which are necessary for receiving push notifications.2. Dynamic Return Payload Creation
createReturnNotificationInfo(), has been added to theLoopAPNSServiceandPushNotificationManager. This method is now called before any remote command is sent.return_notificationobject containing all the information the remote peer (Trio) needs to send a notification back to this specific Loop Follow app instance. This payload includes:3. Support for Mismatched Developer Teams
A core part of this implementation is handling cases where Loop Follow is built with a different Apple Developer account than the target Loop/Trio app.
DEVELOPMENT_TEAMID at compile time and stores it inBuildDetails.swift.Remote Settingsview. This prompts the user to enter the APNS Key and Key ID associated with their Loop Follow developer account. These credentials are then used exclusively for the return notification path, ensuring that Trio can authenticate correctly to send the feedback notification. If the Team IDs are the same, the primary APNS credentials are reused for the return path, and no extra configuration is needed.