Skip to content

Add comprehensive PuTTY session import feature#6

Closed
steffen-heil-secforge wants to merge 1 commit into
wifi-hotspot-forwardingfrom
putty-import
Closed

Add comprehensive PuTTY session import feature#6
steffen-heil-secforge wants to merge 1 commit into
wifi-hotspot-forwardingfrom
putty-import

Conversation

@steffen-heil-secforge

@steffen-heil-secforge steffen-heil-secforge commented Oct 19, 2025

Copy link
Copy Markdown
Owner

Summary

Implements full import of PuTTY sessions from Windows registry export files, including connection settings and port forwards. Users can import multiple sessions at once through an interactive dialog with selective import and bind address configuration.

Note: This PR is based on #5 (wifi-hotspot-forwarding branch) and should be merged after that PR.

Features

PuTTY Registry Parsing

  • Parse PuTTY registry export files (.reg format)
  • Extract session configurations: hostname, port, protocol (ssh/telnet/local/serial), username, compression
  • Parse all port forward types:
    • Local forwards (-L): L<sourceport>=<destaddr>:<destport>
    • Remote forwards (-R): R<sourceport>=<destaddr>:<destport>
    • Dynamic SOCKS (-D): D<sourceport>
  • Handle complex syntax: IPv6 addresses, bind addresses, custom ports
  • Validate port numbers and addresses
  • Convert PuTTY constants to ConnectBot database constants
  • Truncate at 100 sessions with user notification

Interactive Import Dialog

  • Multi-select session list with checkboxes
  • Session details displayed: username@hostname:port
  • Indicators for existing hosts (shows which will be updated vs. new)
  • Filtered list excludes identical sessions already in database
  • Select all / deselect all buttons
  • Sorted alphabetically by session name
  • Bind address configuration for imported port forwards:
    • localhost (default, matches PuTTY semantics)
    • All interfaces (0.0.0.0)
    • WiFi hotspot (access_point)
  • Security warnings for network-exposed bind options

Smart Merge Behavior

  • When session name matches existing host:
    • Updates only PuTTY-related fields: protocol, hostname, port, username, compression
    • Preserves all ConnectBot settings: colors, key usage, font size, stay-connected, quick-disconnect, auth agent, post-login, session flags, encoding
  • Port forwards are fully replaced (old deleted, new imported) to prevent duplicates on re-import
  • Sessions identical to existing hosts are filtered out

Background Import

  • AsyncTask with progress dialog
  • Import results: success count, skipped count, errors
  • Toast notifications for all result states:
    • Full success: "Imported N sessions"
    • Partial success: "Imported N sessions (M skipped)"
    • Error: Specific error message
  • Automatic host list refresh after import

Lifecycle Handling

  • Graceful handling of fragment recreation (configuration changes)
  • Dialog dismisses on recreation rather than attempting to serialize non-serializable data
  • User can simply re-trigger import if needed

UI Integration

  • "Import from PuTTY" menu action in HostListActivity
  • File picker for selecting .reg files
  • Custom layouts:
    • dia_putty_import.xml: Main import dialog
    • item_putty_session.xml: Session list item
  • Comprehensive string resources for all UI text

Parser Capabilities

Supported PuTTY Fields

  • HostName: Target hostname/IP
  • PortNumber: SSH/telnet port
  • Protocol: ssh, telnet, local, serial
  • UserName: Login username
  • Compression: Enable/disable compression
  • PortForwardingX: All port forward definitions

Port Forward Parsing

  • Handles all formats:
    • L8080=localhost:80 (local forward)
    • R2222=192.168.1.100:22 (remote forward)
    • D1080 (dynamic SOCKS proxy)
    • L6[::1]:8080=[2001:db8::1]:80 (IPv6 with bind address)
  • Validates port ranges (1-65535)
  • Extracts bind addresses when specified
  • Provides informative warnings for malformed entries

Testing

Comprehensive unit tests in PuttyRegistryParserTest:

  • Local, remote, and dynamic port forwards
  • IPv6 address handling
  • Custom port numbers
  • Bind address extraction
  • Malformed input handling
  • Session truncation behavior
  • Warning collection

@steffen-heil-secforge steffen-heil-secforge changed the base branch from main to wifi-hotspot-forwarding October 19, 2025 09:41
@steffen-heil-secforge steffen-heil-secforge force-pushed the putty-import branch 2 times, most recently from 2f3bfcf to a44d388 Compare October 19, 2025 10:14
@steffen-heil-secforge steffen-heil-secforge force-pushed the putty-import branch 2 times, most recently from 955675c to a4bdb3a Compare October 19, 2025 12:23
@steffen-heil-secforge steffen-heil-secforge force-pushed the putty-import branch 3 times, most recently from 9b99d66 to 4611f60 Compare October 19, 2025 12:38
@steffen-heil-secforge steffen-heil-secforge changed the title Add comprehensive PuTTY import feature and host management improvements Add comprehensive PuTTY session import feature Oct 19, 2025
@steffen-heil-secforge steffen-heil-secforge force-pushed the wifi-hotspot-forwarding branch 3 times, most recently from 812eaa9 to d55f47e Compare November 5, 2025 16:14
@steffen-heil-secforge steffen-heil-secforge force-pushed the putty-import branch 3 times, most recently from 11abdeb to 265c0dd Compare November 5, 2025 16:46
Implements full import of PuTTY sessions from Windows registry export files,
including connection settings and port forwards. Users can import multiple
sessions at once through an interactive dialog with selective import and
bind address configuration.

Features:
- Parse PuTTY registry export files (.reg format) to extract session
  configurations and port forwards
- Interactive import dialog with multi-select session list, showing:
  - Session details (username@hostname:port)
  - Existing host indicators with update vs. new host distinction
  - Filtered list excludes identical sessions already in database
  - Select all / deselect all buttons for bulk operations
  - Sorted session list by name for easy navigation
- Bind address selection for imported port forwards:
  - localhost (default, matches PuTTY semantics)
  - All interfaces (0.0.0.0)
  - WiFi hotspot (access_point)
  - Security warnings for network-exposed options
- Background import task with progress dialog
- Result notifications showing import success/partial success/error states
- Graceful handling of fragment recreation (configuration changes) by
  dismissing dialog rather than attempting to serialize non-serializable
  session data

Parser capabilities:
- Extracts hostname, port, protocol (ssh/telnet/local/serial), username,
  compression settings
- Parses all three port forward types: local (-L), remote (-R), dynamic
  SOCKS (-D)
- Handles complex port forward syntax including IPv6 addresses, bind
  addresses, and destination specifications
- Validates port numbers and bind addresses
- Converts PuTTY constants to ConnectBot database constants
- Truncates session list at 100 entries with user notification
- Collects and displays parsing warnings for malformed entries

Smart merge behavior:
- When importing session matching existing host nickname:
  - Updates only PuTTY-related fields (protocol, hostname, port, username,
    compression)
  - Preserves all ConnectBot-specific settings (colors, key usage, font
    size, stay-connected, quick-disconnect, auth agent, post-login,
    session flags, encoding)
- Port forwards are fully replaced (old ones deleted, new ones imported)
  to prevent duplicates on re-import
- Sessions identical to existing hosts are filtered out of import dialog

UI integration:
- "Import from PuTTY" menu action in HostListActivity
- File picker for selecting .reg files
- Automatic host list refresh after successful import
- Informative toast messages for all result states

Testing:
- Comprehensive unit tests for PuttyRegistryParser covering all port
  forward types, edge cases, IPv6, malformed input, truncation behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@steffen-heil-secforge

Copy link
Copy Markdown
Owner Author

Superseded by #9 (ported to new Kotlin/Compose/Room architecture)

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