搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.0

openvpn_flutter

一個允許您使用 Flutter 連接 OpenVPN 服務的外掛程式

AndroidiOS
近 30 天下載
1250
喜歡數
134
Pub 分數
160

安裝套件

flutter pub add openvpn_flutter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

openvpn_flutter 套件讓 Flutter 應用程式能在 Android 與 iOS 平台上連接 OpenVPN 服務。它提供一個簡單的介面來管理 VPN 連線,允許使用者以程式化方式建立安全的網路隧道。該外掛整合了原生 OpenVPN 庫,確保與標準 OpenVPN 設定及 .ovpn 檔案相容。此套件專為希望在其應用程式中加入安全連線功能(例如私人網路存取或增強資料保護)的開發者設計。

適用情境

  • 安全的應用程式到伺服器通訊
  • 企業應用中的私有網路存取
  • 增強的使用者資料隱私
  • 繞過地區內容限制
  • 連接到企業VPN

主要特色

  • 支援 Android 和 iOS 平台
  • 與標準 .ovpn 配置文件整合
  • 程式化連接管理
  • 安全隧道建立
  • 輕量且易於整合

適合對象

  • 企業移動應用
  • 需要安全網絡存取的應用程式
  • 開發注重隱私的工具的開發者
  • 需要遠端伺服器連接的應用程式
  • 使用 OpenVPN 基礎設施的專案

使用建議

  • 需要原生 OpenVPN 庫整合
  • 在 Android 和 iOS 上可能需要額外的權限
  • 配置文件處理必須安全
  • 僅限 OpenVPN 協定
  • 可能需要特定於平台的設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Connect to the OpenVPN service using Flutter. Contributions through issues and pull requests are highly appreciated!

Android Setup

1. Permission Handler
Java

Include the following code in the onActivityResult method of MainActivity.java (if you are using Java):

OpenVPNFlutterPlugin.connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK);

The complete method should look like this:

...
import id.laskarmedia.openvpn_flutter.OpenVPNFlutterPlugin;
...

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    OpenVPNFlutterPlugin.connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK);
    super.onActivityResult(requestCode, resultCode, data);
}
Kotlin

Include the following code in the onActivityResult method of MainActivity.kt (if you are using Kotlin):

OpenVPNFlutterPlugin.connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK);

The complete method should look like this:

...
import id.laskarmedia.openvpn_flutter.OpenVPNFlutterPlugin
...
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    OpenVPNFlutterPlugin.connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK)
    super.onActivityResult(requestCode, resultCode, data)
}
2. App Bundle Build Not Connecting

If you encounter issues with the app not connecting using the latest Flutter SDK, apply the following quick fix:

Ensure that you include the following attribute within the <application> tag in your AndroidManifest.xml file:

<application
    ...
    android:extractNativeLibs="true"
    ...>
</application>

iOS Setup

1. Add Capabilities

Add the App Groups and Network Extensions capabilities to the Runner's target. Refer to the image below for detailed instructions:

2. Add New Target

Click the + button on the bottom left, choose NETWORK EXTENSION, and follow the instructions in the image below:

Add the same capabilities to the VPNExtension as you did for the Runner's target:

3. Copy and Paste

Add the following lines to your Podfile (ios/Podfile):

target 'VPNExtension' do
  use_frameworks!
  pod 'OpenVPNAdapter', :git => 'https://github.com/ss-abramchuk/OpenVPNAdapter.git', :tag => '0.8.0'
end

Open VPNExtension > PacketTunnelProvider.swift and copy-paste the script from PacketTunnelProvider.swift.

Note

You must use iOS devices instead of the simulator to connect.

Recipe

Initialize

Before starting, initialize the OpenVPN plugin:

late OpenVPN openvpn;

@override
void initState() {
    openvpn = OpenVPN(onVpnStatusChanged: _onVpnStatusChanged, onVpnStageChanged: _onVpnStageChanged);
    openvpn.initialize(
        groupIdentifier: "GROUP_IDENTIFIER", ///Example 'group.com.laskarmedia.vpn'
        providerBundleIdentifier: "NETWORK_EXTENSION_IDENTIFIER", ///Example 'id.laskarmedia.openvpnFlutterExample.VPNExtension'
        localizedDescription: "LOCALIZED_DESCRIPTION" ///Example 'Laskarmedia VPN'
    );
}

void _onVpnStatusChanged(VPNStatus? vpnStatus){
    setState((){
        this.status = vpnStatus;
    });
}

void _onVpnStageChanged(VPNStage? stage){
    setState((){
        this.stage = stage;
    });
}
Connect to VPN
void connect() {
  openvpn.connect(
    config,
    name,
    username: username,
    password: password,
    bypassPackages: [],
    // In iOS connection can get stuck in "connecting" if this flag is "false". 
    // Solution is to switch it to "true".
    certIsRequired: false,
  );
}
Disconnect
void disconnect(){
    openvpn.disconnect();
}

Publishing to Play Store and App Store

Android
  1. You can use app bundles to publish the app.
  2. Add the following to your files in the android folder (special thanks to https://github.com/nizwar/openvpn_flutter/issues/10). Otherwise, the connection may not be established in some cases and will silently report "disconnected" when trying to connect. This is likely related to some symbols being stripped by Google Play.
gradle.properties > android.bundle.enableUncompressedNativeLibs=false
AndroidManifest > android:extractNativeLibs="true" in the application tag

Add the following inside the android tag in app/build.gradle:

android {
    ...
    //from here ======
    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
    }

    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
    }

    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = false
        }
    }
    //to here
    ...
}
Notifications

As the plugin shows notifications for connection status and connection details, you must request permission using third-party packages.

Example using permission_handler:

///Put it anywhere you wish, like once you initialize the VPN or pre-connect to the server
Permission.notification.isGranted.then((_) {
  if (!_) Permission.notification.request();
});
iOS
  1. View Apple Guidelines relating to VPN.
  2. This plugin DOES use encryption, but it uses exempt encryptions.

Licenses

Support

If you appreciate my work, don't forget to give a thumbs up or support me with a cup of coffee.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。