Skip to content

fix(network): ask before trusting an SFTP host key (#223) - #281

Merged
BGLuis merged 2 commits into
developfrom
fix/223-sftp-host-key-prompt
Nov 21, 2026
Merged

BGLuis merged 2 commits into
developfrom
fix/223-sftp-host-key-prompt

Conversation

@BGLuis

@BGLuis BGLuis commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Description

The first SFTP connection trusted the server's host key without asking: Test connection retried with whatever fingerprint the server presented, and Save pinned the key returned by nativeSftpProbeHostKey. A man-in-the-middle on that first connection became the trusted key.

  • Prompt before trusting (NetworkSftpScreen.kt): Test connection, Save, and browsing a saved server with no pinned key now stop on HOST_KEY_CONFIRM and open a confirmation modal (reusing ConfirmDeleteModal, which gained an onCancel callback) with the SHA-256 fingerprint and the key type. The key is pinned only after Trust and connect; Cancel stores nothing. The screen no longer calls nativeSftpProbeHostKey (the debug broadcast in VRActivity still does).
  • Changed key: HOST_KEY_CHANGED shows a translated "server identity changed" message; the expected and presented fingerprints go to the log only.
  • Forget: editing a saved SFTP server with a pinned key shows the key and a Forget host key button (SftpCredentialStore.setHostKeyFingerprint), so the next connection asks again.
  • Key type (rust/protocols/src/sftp/): the confirmation now reads HOST_KEY_CONFIRM:<fp> type=<algorithm> needs confirmation: <fp>, the algorithm coming from PublicKey::algorithm() (ssh-key 0.7.0-rc.11). The fingerprint stays the first token, so probe_server_fingerprint parses it unchanged.
  • Parsing (SftpHostKeyStatus.kt): the HOST_KEY_* parsing lives in a pure-Kotlin class covered on the JVM with the exact strings captured from the sftp-test container.
  • Strings: 9 new keys in values, values-pt-rBR, and values-es, in mirrored order with positional placeholders.

Behavior kept on purpose: if the server is unreachable on Save, the server is saved without a pinned key (as before), and the trust prompt appears on the first browse.

Design note: Figma 04c shows the confirmation as an inline card in the form; this PR uses the modal in both the form and the browser, so the browse path can ask too.

Closes #223

Type of change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Technical refactor / Code improvement
  • 📝 Documentation update
  • 🚀 Performance optimization
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

Affected layers

  • 🟣 Kotlin (app/) — app shell, UI panels, credentials, history, i18n
  • 🔵 C++ (native/) — OpenXR session, Vulkan/GLES render loop, controller input
  • 🦀 Rust (rust/) — demux, decode, audio, network protocols
  • 🔧 Build / CI / scripts
  • 📚 Docs only

How has this been tested?

  • Unit tests (JVM / cargo test)
  • Native/Vulkan build compiled without errors
  • Physically tested on a device (Quest 3 / Quest 3s)

Ran locally:

  • ./gradlew ktlintCheck testDebugUnitTest -PrustBuildMode=skip: 582 tests, 0 failures (SftpHostKeyStatusTest 6/6, I18nParityTest, UiSourceGuardsTest).
  • ./gradlew :app:lintDebug -PrustBuildMode=skip: passed.
  • cargo fmt --all --check, cargo clippy -p protocols -p media-logic --all-targets --all-features -- -D warnings, cargo test -p protocols -p media-logic: passed.
  • Against the sftp-test container (docker/network-tests/): the SFTP TOFU integration tests (tofu_first_connection_without_fingerprint_returns_needs_confirmation, different_fingerprint_fails_with_identity_changed) pass; a first connection returns HOST_KEY_CONFIRM:<fp> type=ssh-ed25519 …, a connection with the pinned key lists the directory, and after recreating the container the same pin returns HOST_KEY_CHANGED.

Not verified:

  • The modal in the running app (prompt shown, Cancel storing nothing, the forget button): no device was available.
  • Readability and use with the controllers only on a Quest 3.
  • The native APK build (NDK/cross-compile) and the full ./scripts/test-network-protocols.sh.

Checklist:

  • My code follows the project's style guidelines (ktlint, rustfmt, clippy -D warnings).
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added new tests that prove my fix is effective or that my feature works.
  • The CI checks (Security & Workflows, Rust, C++, Android and Markdown Lint, gated by CI Gate) are passing for this PR.

If applicable

  • Kotlin never calls Rust directly — the Kotlin → JNI → C++ → C ABI → Rust path is preserved (ADR-002).
  • I changed the screen/stereo mode enum and kept it in sync across all four places: SCREEN_MODE in rust/bridge/src/lib.rs, enum class ScreenMode in native/include/screen_mode.h, the catalog in ScreenFormatCatalog.kt, and Format3D::to_screen_mode_index in rust/media-logic/src/format3d.rs.
  • I added or changed user-facing strings and updated all supported locales (values/strings.xml and all values-*/strings.xml), keeping the key order mirrored and using positional placeholders (%1$s).
  • Pure logic I added lives in media-logic (host-testable) rather than in core, where it could not be tested.
  • No credential is stored or logged in plain text.

Screenshots / Videos (if applicable)

None: the UI has not been run on a device yet.

Follow-ups

🤖 Generated with Claude Code

https://claude.ai/code/session_01DKhrqRd1enKzdZs6PNpWco

BGLuis and others added 2 commits November 20, 2026 13:21
The SFTP trust prompt has to show the server's key type next to its
SHA-256 fingerprint so the user can compare both with `ssh-keygen -lf`
on the server. The confirmation error now reads
`HOST_KEY_CONFIRM:<fp> type=<algorithm> needs confirmation: <fp>`, with
the algorithm from `PublicKey::algorithm()` (ssh-key 0.7.0-rc.11). The
fingerprint stays the first token, so `probe_server_fingerprint` keeps
parsing it unchanged.

Refs #223

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DKhrqRd1enKzdZs6PNpWco
Test connection retried with whatever fingerprint the server presented,
and Save pinned the key from `nativeSftpProbeHostKey` without asking, so
a man-in-the-middle on the first connection became the trusted key.

Both paths now stop on HOST_KEY_CONFIRM and show a confirmation with the
fingerprint and key type; the key is pinned only after "Trust and
connect", and Cancel stores nothing. Browsing a saved server that has no
pinned key asks the same way. HOST_KEY_CHANGED shows a translated
"identity changed" message and logs the expected/presented fingerprints
only. Editing a saved SFTP server can forget its pinned key, so the next
connection asks again. The HOST_KEY_* parsing lives in the pure-Kotlin
SftpHostKeyStatus, covered on the JVM with strings captured from the
sftp-test container.

Closes #223

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DKhrqRd1enKzdZs6PNpWco
@BGLuis
BGLuis merged commit 5b6f6ef into develop Nov 21, 2026
7 of 9 checks passed
@BGLuis
BGLuis deleted the fix/223-sftp-host-key-prompt branch November 21, 2026 02:33
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