fix: use wall-clock time for the WireGuard handshake timestamp - #13
Merged
Conversation
wireguard_tai64n_now() used esp_timer_get_time() (uptime) for the TAI64N handshake-initiation timestamp. A peer keeps the greatest timestamp it has seen from us and rejects any handshake initiation whose timestamp is not greater (replay protection, WireGuard spec 5.1). With uptime, every reboot restarts the counter near zero, so a device that ran for hours cannot reconnect after a reboot until its new uptime passes the previous session's. Switch to gettimeofday() (wall-clock, expected to be set e.g. by SNTP before connecting). Also drops the now-unused esp_timer.h include. Adapted from CamM2325/microlink@6a4447c5 and CamM2325/microlink@a8d769e3 (this fix originated in the microlink monorepo before wireguard_lwip was split into its own submodule/repo). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
fudio101
added a commit
to fugo101/microlink
that referenced
this pull request
Aug 18, 2026
Picks up the TAI64N wall-clock handshake-timestamp fix (fugo101/wireguard-lwip#13, released as v1.0.1) for local/submodule builds. Registry-based builds already resolve it automatically via idf_component.yml's existing "^1.0.0" pin — no change needed there. Refs fugo101/wireguard-lwip#13 Co-authored-by: Adrian.Nguyen-Qualgo <nguyen.ndt@qualgo.net> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
wireguard_tai64n_now()insrc/wireguard-platform-esp32.cusedesp_timer_get_time()(deviceuptime) for the TAI64N handshake-initiation timestamp. Per WireGuard's replay protection (spec
5.1), a peer keeps the greatest timestamp it has seen from us and rejects any handshake initiation
whose timestamp is not greater. With uptime as the source, every reboot restarts the counter near
zero — so a device that ran for hours cannot reconnect at all after a reboot, until its new uptime
happens to exceed the previous session's.
Fix: use
gettimeofday()(wall-clock time, expected to be SNTP-synced before connecting) instead.Also drops the now-unused
esp_timer.hinclude (confirmedesp_timer_get_time()was its only usein this file —
wireguard_sys_now()uses lwIP'ssys_now(), unaffected).Attribution
Adapted from
CamM2325/microlink@6a4447c5and
CamM2325/microlink@a8d769e3— thisfix originated in the
microlinkmonorepo beforewireguard_lwipwas split out into thisstandalone repo/submodule, as part of absorbing the bugfix/hardening subset of upstream
CamM2325/microlink#22(see
fugo101/microlink#44, already merged).Test plan
before merging.
wireguard_sys_now()untouched, confirmed noother use of
esp_timer_get_time()in this file.scenario this fix targets — a fresh boot needs the system clock set (SNTP) before the WG
handshake for the fix to take effect as intended.
🤖 Generated with Claude Code