SSH Vpn Flutter Plugin (iOS Only)
A Flutter plugin for managing SSH VPN connections on iOS. This plugin provides methods to set up, connect, disconnect, and check the status of VPN connections using SSH.
Features
- Setup VPN: Configure VPN with hostname, credentials, and protocol settings.
- Connect to VPN: Establish a VPN connection.
- Disconnect VPN: Terminate an active VPN session.
- Retrieve Connection Status: Get the last known status of the VPN connection.
Note: This plugin currently supports iOS only.
Installation
Add the package to your pubspec.yaml
:
dependencies:
sshvpn_flutter: ^latest_version
Run the command:
flutter pub get
Import the package in your Dart code:
import 'package:sshvpn_flutter/sshvpn_flutter.dart';
iOS Setup
1. Add Capabillity
Add Network Extensions capabillity on Runner's Target and enable Packet Tunnel

2. Add New Target
Click + button on bottom left, Choose NETWORK EXTENSION. And set Language and Provider Type to Objective-C and Packet Tunnel as image below.

3. Add Capabillity to sshvpn_extension
Repeat the step 1 for new target you created on previous step (sshvpn_extension)
4. Add Pod dependency
Open your Podfile , and add the following lines:
target 'sshvpn_extension' do
pod 'vpn_adapter_ios', :git => 'https://github.com/NavidShokoufeh/vpn_adapter_ios.git', :tag => '1.0.0'
end
And in your runner target do the same :
target 'Runner' do
pod 'vpn_adapter_ios', :git => 'https://github.com/NavidShokoufeh/vpn_adapter_ios.git', :tag => '1.0.0' <-- Add this line
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end
5. Copy Paste
Open sshvpn_extension > PacketTunnelProvider.m and copy paste this script PacketTunnelProvider.m
Usage
Setting up the VPN
To configure the VPN connection, use the setup method and pass an SSHServer instance with the required configuration:
import 'package:sshvpn_flutter/sshvpn_flutter.dart';
final sshVpnFlutterPlugin = SshvpnFlutter();
SSHServer server = SSHServer(
host: hostNameController.text,
port: int.parse(
sslPortController.text.isEmpty ? '443' : sslPortController.text),
username: userNameController.text,
password: passController.text,
udpgw: udpgwController.text,
udpgwPort: int.parse(
udpgwPortController.text.isEmpty ? '7300' : udpgwPortController.text),
iosConfiguration: SSHIOSConfiguration(
enableMSCHAP2: true,
enableCHAP: false,
enablePAP: false,
enableTLS: false,
),
);
await sshVpnFlutterPlugin.setup(server: server);
Connecting to VPN
To connect to the VPN:
await sshVpnFlutterPlugin.connect();
Disconnecting from VPN
To disconnect from the VPN:
await sshVpnFlutterPlugin.disconnect();
Checking Connection Status
To get the last known VPN connection status:
String status = await sshVpnFlutterPlugin.lastStatus() ?? 'disconnected'
print('Last VPN status: $status');
Limitations
- Platform: This plugin is only supported on iOS. Android support is not currently available.
- Dependencies: Ensure your iOS project is properly configured for VPN usage.
Contributions and Issues
Feel free to contribute to this project by submitting pull requests or reporting issues on the GitHub repository.
This addition emphasizes that the purpose of the plugin is to provide a secure means for web surfing using SSH VPN connections. Adjustments can be made based on your specific requirements.
Support this Project
If you find this project helpful, consider supporting it by making a donation. Major of Your contribution will spend on charity every month.
- Bitcoin (BTC):
bc1qgwfqm5e3fhyw879ycy23zljcxl2pvs575c3j7w
- USDT (TRC20):
TJc5v4ktoFaG3WamjY5rvSZy7v2F6tFuuE
Thank you for your support! 🚀
License
Copyright 2024 Navid Shokoufeh
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.