Block sending loop commands with same TOTP code #450
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Block Sending Loop Commands with Same TOTP Code
Overview
This commit implements a security enhancement to prevent the reuse of Time-based One-Time Password (TOTP) codes when sending Loop commands via APNS (Apple Push Notification Service). The change ensures that each TOTP code can only be used once within its 30-second validity period.
Key Changes
Added loopAPNSTOTPUsed: Boolean flag to track if a TOTP code has been used
Added loopAPNSTOTPLastUsed: Timestamp tracking when the TOTP was last used
Bolus View (LoopAPNSBolusView.swift): Added isTOTPBlocked computed property
Carbs View (LoopAPNSCarbsView.swift): Added identical isTOTPBlocked computed property
Both views now check TOTP usage status before allowing command submission
Warning Display: Added visual warning section when TOTP is blocked, showing:
Orange warning icon with "TOTP Code Already Used" message
Explanatory text about waiting for the next code
Button State Management: Send buttons are disabled when TOTP is blocked
Timer-based Reset: Automatically resets TOTP usage flag when a new 30-second period begins
Safety Checks: Multiple validation points ensure TOTP blocking is properly managed:
When moving to a new TOTP period
At the start of each new period (≥29 seconds remaining)
Fallback check for 30+ seconds elapsed since last use
TOTP usage is marked with timestamp when commands are successfully sent
Prevents immediate reuse of the same TOTP code