Skip to content

fix: guard unsupported AmneziaWG s3/s4 keys#33

Closed
hawkff wants to merge 2 commits into
mainfrom
feat/guard-awg-s3s4-uapi
Closed

fix: guard unsupported AmneziaWG s3/s4 keys#33
hawkff wants to merge 2 commits into
mainfrom
feat/guard-awg-s3s4-uapi

Conversation

@hawkff

@hawkff hawkff commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • keep AmneziaWG s3/s4 fields importable and storable
  • avoid emitting unsupported s3/s4 UAPI keys with the currently bundled amneziawg-go core

Validation

  • CodeRabbit CLI review: 0 findings

Greptile Summary

This PR replaces a silent pass-through of unsupported s3/s4 AmneziaWG obfuscation parameters with an explicit error() call that halts tunnel start-up and surfaces a descriptive message to the user. Import and in-database storage of these fields are unchanged.

  • The Kotlin error() call throws IllegalStateException, which propagates through buildConfig() and is caught by catch (exc: Throwable) in BaseService.kt, causing the VPN service to stop with "Service failed: AmneziaWG S3/S4 are not supported by the bundled core" shown to the user.
  • The same exception is also caught by the catch (e: Exception) block in ConfigurationFragment.kt when a user attempts a sing-box JSON export of a profile with non-zero s3/s4, showing a snackbar with the error text — so that export path also fails gracefully.
  • Standard link / universal link export paths (toStdLink, toUniversalLink) do not go through buildConfig, so those remain fully functional for profiles with s3/s4 set.

Confidence Score: 5/5

Safe to merge — the one-line guard is a strict improvement over the previous silent pass-through, and every call site already catches the thrown exception and presents a user-visible message.

The change is minimal and surgical: two lines are replaced by a guard that throws an explicit exception. All three call paths that reach this code (VPN service start, sing-box JSON export, URL test) already wrap the call in appropriate catch blocks, so the exception is handled gracefully in every case. Import and storage of s3/s4 values are unaffected.

No files require special attention.

Important Files Changed

Filename Overview
app/src/main/java/io/nekohasekai/sagernet/fmt/amneziawg/AmneziaWGFmt.kt Replaces silent s3/s4 pass-through with an explicit error() guard; all call sites (BaseService, ConfigurationFragment, TestInstance) catch the resulting IllegalStateException and surface it as a user-visible message.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User connects / exports sing-box config] --> B[buildConfig called]
    B --> C[buildSingBoxOutboundAmneziaWGBean]
    C --> D{bean.s3 != 0 or bean.s4 != 0?}
    D -- No --> E[Emit jc/jmin/jmax/s1/s2/h1-h4/i1-i5 normally]
    E --> F[Tunnel starts / config exported]
    D -- Yes --> G[error throws IllegalStateException]
    G --> H{Caller context?}
    H -- VPN service start BaseService.kt --> I[catch Throwable stopRunner with message]
    I --> J[User sees: Service failed: AmneziaWG S3/S4 not supported]
    H -- Sing-box JSON export ConfigurationFragment.kt --> K[catch Exception snackbar shown]
    K --> L[User sees snackbar error message]
    H -- URL test TestInstance.kt --> M[catch Exception returned to caller]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[User connects / exports sing-box config] --> B[buildConfig called]
    B --> C[buildSingBoxOutboundAmneziaWGBean]
    C --> D{bean.s3 != 0 or bean.s4 != 0?}
    D -- No --> E[Emit jc/jmin/jmax/s1/s2/h1-h4/i1-i5 normally]
    E --> F[Tunnel starts / config exported]
    D -- Yes --> G[error throws IllegalStateException]
    G --> H{Caller context?}
    H -- VPN service start BaseService.kt --> I[catch Throwable stopRunner with message]
    I --> J[User sees: Service failed: AmneziaWG S3/S4 not supported]
    H -- Sing-box JSON export ConfigurationFragment.kt --> K[catch Exception snackbar shown]
    K --> L[User sees snackbar error message]
    H -- URL test TestInstance.kt --> M[catch Exception returned to caller]
Loading

Reviews (2): Last reviewed commit: "fix: reject unsupported nonzero AWG s3 s..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

buildSingBoxOutboundAmneziaWGBean in AmneziaWGFmt.kt is updated to stop writing the s3 and s4 obfuscation parameters into the SingBoxOptions.Outbound_AmneziaWGOptions output. The removed conditional assignment is replaced with inline comments explaining that the bundled amneziawg-go UAPI does not yet accept these fields.

Changes

AmneziaWG s3/s4 suppression

Layer / File(s) Summary
Suppress s3/s4 emission with explanatory comments
app/src/main/java/io/nekohasekai/sagernet/fmt/amneziawg/AmneziaWGFmt.kt
Conditional assignment of s3/s4 into the outbound options is removed and replaced with comments noting the fields are intentionally withheld pending UAPI support; the fields remain importable and storable.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A tiny hop, two fields held back,
The UAPI's not ready—cut it some slack!
s3 and s4 still sleep in store,
Waiting for support to open the door.
Comments now whisper the reason why,
Little rabbit says: patience, stand by! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and specifically describes the main change: guarding against unsupported AmneziaWG s3/s4 keys, which aligns perfectly with the changeset's purpose.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the changes: keeping AmneziaWG s3/s4 fields importable/storable while avoiding emission of unsupported s3/s4 UAPI keys with the bundled amneziawg-go core.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread app/src/main/java/io/nekohasekai/sagernet/fmt/amneziawg/AmneziaWGFmt.kt Outdated
Comment on lines +26 to +28
// The bundled amneziawg-go v1.0.4 UAPI does not accept s3/s4 yet.
// Keep these fields importable/storable, but do not emit them until
// the core supports the corresponding device keys.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No TODO / issue reference for eventual re-enablement

The comment hard-codes the version number (v1.0.4) but there is no // TODO: marker or issue tracker link — so when the bundled amneziawg-go is bumped to a version that does accept s3/s4, the suppression will remain silently in place unless someone remembers to revisit this file. Adding a short TODO with a link to the upstream issue would make the re-enablement self-discoverable.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@hawkff

hawkff commented Jun 19, 2026

Copy link
Copy Markdown
Owner Author

Closing as superseded by #34.

This guard was correct only for the old bundled amneziawg-go core, where nonzero S3/S4 were unsupported. After #34, the app pins the updated sing-box/libcore with amneziawg-go v0.2.19, and we verified a real Android -> AWS AmneziaWG tunnel using nonzero S3/S4. Merging this PR now would reject the feature we just enabled.

@hawkff hawkff closed this Jun 19, 2026
@hawkff hawkff deleted the feat/guard-awg-s3s4-uapi branch June 19, 2026 17:24
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