Git Product home page Git Product logo

wireguard_flutter's Introduction

wireguard_flutter

A flutter plugin to setup and control VPN connection via Wireguard tunnel.

Usage

To use this plugin, add wireguard_flutter or visit Flutter Tutorial.

flutter pub add wireguard_flutter

Initialize

Initialize a wireguard instance with a valid name using initialize:

final wireguard = WireGuardFlutter.instance;

// initialize the interface
await wireguard.initialize(interfaceName: 'wg0');

and declare the .conf data:

const String conf = '''[Interface]
PrivateKey = 0IZmHsxiNQ54TsUs0EQ71JNsa5f70zVf1LmDvON1CXc=
Address = 10.8.0.4/32
DNS = 1.1.1.1


[Peer]
PublicKey = 6uZg6T0J1bHuEmdqPx8OmxQ2ebBJ8TnVpnCdV8jHliQ=
PresharedKey = As6JiXcYcqwjSHxSOrmQT13uGVlBG90uXZWmtaezZVs=
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 0
Endpoint = 38.180.13.85:51820''';

For more info on the configuration data, see the documentation with examples.

Connect

After initializing, connect using startVpn:

await wireguard.startVpn(
  serverAddress: address, // the server address (e.g 'demo.wireguard.com:51820')
  wgQuickConfig: conf, // the quick-config file
  providerBundleIdentifier: 'com.example', // your app identifier
);

Disconnect

After connecting, disconnect using stopVpn:

await wireguard.stopVpn();

Stage

Listen to stage change using vpnStageSnapshot:

wireguard.vpnStageSnapshot.listen((event) {
  debugPrint("status changed $event");
});

Or get the current stage using getStage:

final stage = await wireguard.stage();

The available stages are:

Code Description
connecting The interface is connecting
connected The interface is connected
disconnecting The interface is disconnecting
disconnected The interface is disconnected
waitingConnection Waiting for a user interaction
authenticating Authenticating with the server
reconnect Reconnecting the the interface
noConnection Any connection has not been made
preparing Preparing to connect
denied The connection has been denied by the system, usually by refused permissions
exiting Exiting the interface

Supported Platforms

Android iOS macOS Windows Linux
Version SDK 21+ 15.0+ 12+ 7+ Any

Windows

On Windows, the app must be run as administrator to be able to create and manipulate the tunnel. To debug the app, run flutter run from an elevated command prompt. To run the app normally, the system will request your app to be run as administrator. No code changes or external dependencies are required.

Linux

Install dependencies

The required dependencies need to be installed: wireguard and wireguard-tools.

On Ubuntu/Debian, use the following command to install the dependencies:

sudo apt install wireguard wireguard-tools openresolv

For other Linux distros, see this.

Note

If openresolv is not installed in the system, configuration files with a DNS provided may not connect. See this issue for more information.

Initializing

When wireguard.initialize is called, the application will request your user password ([sudo] password for <user>:). This is necessary because wireguard must run as a root to be able to create AND manipulate the tunnels. This is true for either debug and release modes or a distributed executable.

Caution

Do not run the app in root mode (e.g sudo ./executable, sudo flutter run), otherwise the connection will not be established.

FAQ & Troubleshooting

Linux error resolvconf: command not found

On Linux, you may receive the error resolvconf: command not found. This is because wireguard tried to adjust the nameserver. Make sure to install openresolv or not provide the "DNS" field.


"WireGuard" is a registered trademark of Jason A. Donenfeld.

Fork from mysteriumnetwork tunnel.

Many Thanks for Bruno D'Luka for help me.

wireguard_flutter's People

Contributors

bdlukaa avatar caqil avatar imgbotapp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.