Skip to content

feat: Add Windows support to openvpn_flutter#147

Open
Spokplacenta wants to merge 51 commits into
nizwar:masterfrom
Spokplacenta:dev_branch
Open

feat: Add Windows support to openvpn_flutter#147
Spokplacenta wants to merge 51 commits into
nizwar:masterfrom
Spokplacenta:dev_branch

Conversation

@Spokplacenta

Copy link
Copy Markdown

Add Windows Support to openvpn_flutter

Summary

This PR adds comprehensive Windows support to the openvpn_flutter plugin, allowing Flutter applications to connect to OpenVPN servers on Windows platforms.

Key Features

1. Windows Binary Management

  • Embedded Binary: Uses openvpn.exe.bin from assets (assets/openvpn/windows/)
  • Binary Source: The binary was extracted from official OpenVPN MSI installers available at https://openvpn.net/client/
  • Asset Loading: Automatically loads and extracts the embedded binary on first use
  • Binary Extraction: Copies the embedded binary to a temporary location for execution

2. Windows Plugin Implementation

  • Rust FFI Layer: Native Windows plugin implemented in Rust for process management
  • C++ Bridge: C++ wrapper connecting Flutter MethodChannels to Rust FFI
  • Process Management: Launches and monitors openvpn.exe process
  • Output Parsing: Parses OpenVPN output for connection stages and statistics
  • Event Streaming: Real-time VPN stage updates via EventChannel

3. Dart API Integration

  • Platform Detection: Automatically detects Windows platform
  • Binary Preparation: Loads embedded openvpn.exe.bin from assets and extracts it for use
  • Status Monitoring: Provides detailed connection status (bytes in/out, packets, timestamps)
  • Error Handling: Comprehensive error handling for missing binaries and connection failures

4. Technical Implementation

Rust Components

  • lib.rs: FFI interface exposing C-compatible functions
  • openvpn.rs: OpenVPN process management and output parsing
  • manager.rs: Thread-safe singleton for OpenVPN manager
  • error.rs: Custom error types using thiserror

C++ Components

  • openvpn_flutter_plugin.h/cpp: Flutter plugin bridge
  • CMake integration for building Rust library

Dart Components

  • windows_binary_manager.dart: Embedded binary loading and management
  • windows_tap_manager.dart: TAP adapter management (optional)
  • vpn_engine.dart: Windows-specific integration

Files Changed

New Files

  • lib/src/windows_binary_manager.dart - Embedded binary loading and management
  • lib/src/windows_tap_manager.dart - TAP adapter management
  • windows/rust/ - Rust implementation
  • windows/openvpn_flutter_plugin.h/cpp - C++ bridge
  • windows/CMakeLists.txt - Build configuration
  • assets/openvpn/windows/openvpn.exe.bin - Embedded OpenVPN binary
  • test_integration/ - Integration test application

Modified Files

  • lib/src/vpn_engine.dart - Windows platform support
  • pubspec.yaml - Windows platform entry and dependencies
  • android/build.gradle - Updated NDK version and OpenVPN library

Dependencies Added

  • path_provider: ^2.1.1 - For file system access
  • path: ^1.8.3 - For path manipulation

Rust Dependencies

  • tokio - Async runtime
  • anyhow - Error handling
  • thiserror - Custom errors
  • serde / serde_json - JSON serialization
  • tempfile - Temporary file management
  • chrono - Timestamp handling

Testing

An integration test application is included in test_integration/ demonstrating:

  • Embedded binary loading
  • VPN connection establishment
  • Status monitoring
  • Connection teardown

Breaking Changes

None. This is a purely additive feature that doesn't affect existing Android/iOS functionality.

Compatibility

  • Windows: Windows 10/11 (x64)
  • Flutter: >=2.5.0
  • Dart: >=2.15.0 <4.0.0

Notes

  • The plugin uses the embedded openvpn.exe.bin from assets
  • The binary was extracted from official OpenVPN MSI installers available at https://openvpn.net/client/
  • Binary is extracted to a temporary location on first use
  • Temporary config and auth files are created per connection
  • Process monitoring handles connection lifecycle

Related Issues

This PR addresses the need for Windows support in the openvpn_flutter plugin.

nizwar and others added 30 commits August 29, 2025 02:24
…ndling. Update dependencies in pubspec.yaml.
- Correction de l'erreur CMake avec add_custom_command POST_BUILD qui référençait une cible inexistante
- Remplacement par set(openvpn_flutter_bundled_libraries) pour laisser Flutter gérer l'installation
- Ajout des répertoires d'inclusion cpp_client_wrapper/include pour trouver les headers Flutter
- Correction des noms de fichiers header (tirets -> underscores) pour correspondre aux fichiers réels
- Ajout de l'héritage public Plugin pour permettre l'utilisation avec AddPlugin()
- Utilisation de file(TO_CMAKE_PATH) pour normaliser les chemins Windows
- Ajout d'un message STATUS quand les artefacts précompilés sont trouvés
- Correction de la vérification d'existence des fichiers
… absolus

- Conversion en chemin absolu pour une détection plus fiable des fichiers prebuilt
- Correction du problème de détection des artefacts Rust sur Windows
- file(GLOB) fonctionne mieux que EXISTS avec les liens symboliques sur Windows
- Correction de la détection des artefacts Rust précompilés
…bsolue

- Vérification EXISTS avec chemin relatif plus fiable avec les liens symboliques
- Conversion en chemin absolu seulement après confirmation de l'existence
- StreamHandler est une classe abstraite et ne peut pas être instanciée directement
- StreamHandlerFunctions est la classe helper fournie par Flutter pour utiliser des fonctions
- Ajout de l'include event_stream_handler_functions.h
- Rust génère openvpn_flutter_rust.dll.lib et non openvpn_flutter_rust.lib
- Correction du nom de fichier pour correspondre à la sortie de Rust
…egistrant

- Permet à generated_plugin_registrant.cc de trouver openvpn_flutter_plugin.h
- Correction de l'erreur d'inclusion du header
- Création du sous-répertoire openvpn_flutter avec le header
- Permet à generated_plugin_registrant.cc de trouver openvpn_flutter/openvpn_flutter_plugin.h
- Ajout de la déclaration OpenvpnFlutterPluginRegisterWithRegistrar
- Permet à generated_plugin_registrant.cc de trouver la fonction
…ktopPluginRegistrarRef

- Évite la redéfinition du type
- Utilise le type officiel de Flutter
@Spokplacenta Spokplacenta mentioned this pull request Dec 23, 2025
@Spokplacenta

Spokplacenta commented Jan 20, 2026

Copy link
Copy Markdown
Author

Hi @nizwar, would you have some time to review this PR ?

Spokplacenta and others added 16 commits March 13, 2026 16:56
…t to prebuilt Rust binaries for Windows consumers and fall back to cargo builds only when artifacts are missing or explicitly disabled. Add CI verification to keep committed prebuilt artifacts in sync with Rust sources.
Replace strict prebuilt artifact diff checks with drift detection and patch upload in CI, because Windows Rust binaries can vary between environments. Keep artifact generation/upload and document the new drift handling flow for maintainers.
Refactor the release workflow to build Android APKs and Windows Rust prebuilt binaries in dedicated jobs, then publish both artifact sets in a single GitHub Release. Restrict publishing to version tags to avoid creating releases on regular branch pushes.
… adapter release, and improve error detection for TAP/TUN issues
… elevation and updating error classification
…onality and adjusting connection timeout settings
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.

2 participants