コード例 #1
0
        private void Cleanup()
        {
            SupportTools.SafeClose(fileDescriptor);
            fileDescriptor = null;

            SupportTools.SafeDispose(vpnServiceBuilder);
            vpnServiceBuilder = null;
        }
コード例 #2
0
        public VPNManager(Context context)
        {
            m_context = context;

            EddieLogger.Init(context);

            supportTools = new SupportTools(m_context);
        }
コード例 #3
0
ファイル: VPNContext.cs プロジェクト: 3x-M4ch1nA/Eddie
        private void Cleanup()
        {
            SupportTools.SafeClose(m_fileDescriptor);
            m_fileDescriptor = null;

            SupportTools.SafeDispose(m_builder);
            m_builder = null;
        }
コード例 #4
0
        public void AddProfileString(string str)
        {
            if (SupportTools.Empty(str))
            {
                throw new Exception("invalid profile string");
            }

            m_profilesStrings.Add(str);
        }
コード例 #5
0
ファイル: VPNService.cs プロジェクト: 3x-M4ch1nA/Eddie
        private void CleanupReceivers()
        {
            if (m_screenReceiver != null)
            {
                UnregisterReceiver(m_screenReceiver);

                SupportTools.SafeDispose(m_screenReceiver);

                m_screenReceiver = null;
            }
        }
コード例 #6
0
        private string GetEventContent(ref NativeMethods.ovpn3_event oe)
        {
            string name = oe.name;
            string info = oe.info;

            if (SupportTools.Empty(info))
            {
                return(name);
            }

            return(name + ": " + info);
        }
コード例 #7
0
        private void DoStop()
        {
            DoChangeStatus(VPN.Status.DISCONNECTING);

            SupportTools.StartThread(new Java.Lang.Runnable(() =>
            {
                DoStopService();

                currentNotificationText = "";

                WaitForVpnThreadToFinish();
            }));
        }
コード例 #8
0
        private void TryRestoreLastProfile(Context context)
        {
            LogsManager.Instance.Debug("EddieBroadcastReceiver.TryRestoreLastProfile");

            if (VPNService.Prepare(context.ApplicationContext) != null)
            {
                LogsManager.Instance.Debug("VPNService.Prepare requires confirmation");

                return;
            }

            if (!settingsManager.SystemRestoreLastProfile)
            {
                LogsManager.Instance.Debug("EddieBroadcastReceiver: SystemRestoreLastProfile disabled");

                return;
            }

            if (!settingsManager.SystemLastProfileIsConnected)
            {
                LogsManager.Instance.Debug("EddieBroadcastReceiver: SystemLastProfileIsConnected false");

                return;
            }

            string lastProfile = settingsManager.SystemLastProfile;

            if (SupportTools.Empty(lastProfile))
            {
                LogsManager.Instance.Debug("EddieBroadcastReceiver: lastProfile is empty");
                return;
            }

            LogsManager.Instance.Debug("EddieBroadcastReceiver: restoring last profile");

            try
            {
                Bundle args = new Bundle();
                args.PutString(VPNService.PARAM_PROFILE, lastProfile);

                Intent intent = new Intent(context, typeof(VPNService));
                intent.PutExtra(VPNService.PARAM_START, true);
                intent.PutExtra(VPNService.EXTRA_RUN_ARGS, args);

                context.StartService(intent);
            }
            catch (Exception e)
            {
                LogsManager.Instance.Error("TryRestoreLastProfile", e);
            }
        }
コード例 #9
0
ファイル: VPNContext.cs プロジェクト: 3x-M4ch1nA/Eddie
        private void DoAddDNS(string address)
        {
            address = address.Trim();

            if (SupportTools.Empty(address))
            {
                throw new Exception("invalid DNS server");
            }

            LogsManager.Instance.Debug("Adding DNS server '{0}'", address);

            m_builder.AddDnsServer(address);
            m_hasDNS = true;
        }
コード例 #10
0
        private void ClearContexts()
        {
            LogsManager.Instance.Debug("ClearContexts");

            lock (m_contextsSync)
            {
                while (m_contexts.Count > 0)
                {
                    LogsManager.Instance.Debug("Disposing context");

                    SupportTools.SafeDispose(m_contexts.Pop());
                }
            }
        }
コード例 #11
0
        private void ClearContexts()
        {
            EddieLogger.Debug("ClearContexts");

            lock (contextsSync)
            {
                while (m_contexts.Count > 0)
                {
                    EddieLogger.Debug("Disposing context");

                    SupportTools.SafeDispose(m_contexts.Pop());
                }
            }
        }
コード例 #12
0
        private void DoAddDNS(string address)
        {
            address = address.Trim();

            if (SupportTools.Empty(address))
            {
                throw new Exception("Invalid DNS server");
            }

            EddieLogger.Debug("Adding DNS server '{0}'", address);

            vpnServiceBuilder.AddDnsServer(address);
            hasDNS = true;
        }
コード例 #13
0
        private int OnTunBuilderSetBlockIPV6(/*bool*/ int block_ipv6)
        {
            LogsManager.Instance.Debug("OnTunBuilderSetBlockIPV6(block_ipv6={0})", block_ipv6);

            try
            {
                ActiveContext.SetBlockIPV6(SupportTools.BoolCast(block_ipv6));

                return(NativeMethods.SUCCESS);
            }
            catch (Exception e)
            {
                LogsManager.Instance.Error("OnTunBuilderSetBlockIPV6", e);
            }

            return(NativeMethods.ERROR);
        }
コード例 #14
0
        private void DoStart(Bundle data)
        {
            LastError = "";

            DoChangeStatus(VPN.Status.CONNECTING);

            if ((Application as AndroidApplication).Initialized)
            {
                try
                {
                    TunnelSetup(data);
                }
                catch (Exception e)
                {
                    LastError = "Tunnel start failed: " + e.Message;

                    DoStopService();
                }

                Java.Lang.Thread newVpnTask = SupportTools.StartThread(new Java.Lang.Runnable(() =>
                {
                    EddieLogger.Info("Starting VPN thread");

                    vpnTunnel.Run();
                }));

                if (newVpnTask != null)
                {
                    vpnThread = newVpnTask;
                }
            }
            else
            {
                LastError = "Initialization failed";

                DoStopService();
            }
        }
コード例 #15
0
        private void InitMTU()
        {
            String customMtu = settingsManager.SystemCustomMTU.Trim();

            if (SupportTools.Empty(customMtu))
            {
                return;
            }

            try
            {
                int mtu = int.Parse(customMtu);

                if (mtu > 0)
                {
                    vpnServiceBuilder.SetMtu(mtu);
                    forceMTU = true;
                }
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("invalid mtu option '{0}': '{1}'", customMtu, e.Message));
            }
        }
コード例 #16
0
        public VPNManager(Context context)
        {
            m_context = context;

            supportTools = new SupportTools(m_context);
        }
コード例 #17
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.main_activity_layout);

            supportTools = new SupportTools(this);

            EddieLogger.Init(this);

            networkStatusReceiver = new NetworkStatusReceiver();
            networkStatusReceiver.AddListener(this);
            this.RegisterReceiver(networkStatusReceiver, new IntentFilter(Android.Net.ConnectivityManager.ConnectivityAction));

            toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            drawer       = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            drawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);
            drawer.AddDrawerListener(drawerToggle);
            drawerToggle.SyncState();

            navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);
            navigationView.NavigationItemSelected += OnNavigationViewItemSelected;

            btnSelectProfile = FindViewById <Button>(Resource.Id.select_profile_btn);

            btnSelectProfile.Click += delegate
            {
                OnClickSelectProfileButton();
            };

            txtProfileFileName      = FindViewById <TextView>(Resource.Id.profile_filename);
            txtProfileFileName.Text = Resources.GetString(Resource.String.conn_no_profile);

            llServerInfo = FindViewById <LinearLayout>(Resource.Id.server_info_layout);

            txtServerName      = FindViewById <TextView>(Resource.Id.profile_server);
            txtServerName.Text = "";

            txtServerPort      = FindViewById <TextView>(Resource.Id.profile_port);
            txtServerPort.Text = "";

            txtServerProtocol      = FindViewById <TextView>(Resource.Id.profile_protocol);
            txtServerProtocol.Text = "";

            btnConnectProfile = FindViewById <Button>(Resource.Id.connect_profile_btn);

            btnConnectProfile.Click += delegate
            {
                OnStartConnection();
            };

            btnDisconnectProfile = FindViewById <Button>(Resource.Id.disconnect_profile_btn);

            btnDisconnectProfile.Click += delegate
            {
                OnStopConnection();
            };

            txtVpnStatus      = FindViewById <TextView>(Resource.Id.vpn_connection_status);
            txtVpnStatus.Text = Resources.GetString(Resource.String.conn_status_disconnected);

            txtNetworkStatus      = FindViewById <TextView>(Resource.Id.network_connection_status);
            txtNetworkStatus.Text = Resources.GetString(Resource.String.conn_status_disconnected);

            llConnectionError = FindViewById <LinearLayout>(Resource.Id.connection_error_layout);

            txtConnectionError      = FindViewById <TextView>(Resource.Id.connection_error);
            txtConnectionError.Text = "";

            vpnManager = new VPNManager(this);

            vpnManager.StatusChanged += OnServiceStatusChanged;

            if (settingsManager.SystemRestoreLastProfile)
            {
                RestoreLastProfile();
            }
            else
            {
                txtProfileFileName.Text = Resources.GetString(Resource.String.conn_no_profile);

                llServerInfo.Visibility = ViewStates.Gone;
            }
        }
コード例 #18
0
 public static void Fatal(String prefix, Exception e)
 {
     Log(Level.Severe, prefix, SupportTools.GetExceptionDetails(e));
 }
コード例 #19
0
ファイル: OpenVPNDispatcher.cs プロジェクト: 3x-M4ch1nA/Eddie
        /*
         * private ParcelFileDescriptor WaitTun()
         * {
         *      while(!m_cancellationToken.IsCancellationRequested)
         *      {
         *              ParcelFileDescriptor tun = m_channel.FileDescriptor;
         *              if(tun != null)
         *                      return tun;
         *
         *              Utils.Sleep(THREAD_DELAY);
         *      }
         *
         *      return null;
         * }
         */
        private void DoUpdate()
        {
            LogsManager.Instance.Debug("DoUpdate - Begin");

            while (!m_cancellationToken.IsCancellationRequested)
            {
                SupportTools.Sleep(THREAD_DELAY);

                NativeMethods.ovpn3_transport_stats stats = m_tunnel.GetTransportStats();
                //	LogsManager.Instance.Debug("Tunnel stats: bytes_in={0}, bytes_out={1}, packets_in={2}, packets_out={3}, last_packet_received={4}", stats.bytes_in, stats.bytes_out, stats.packets_in, stats.packets_out, stats.last_packet_received);
            }

            LogsManager.Instance.Debug("DoUpdate - End");

            /*
             * FileInputStream channelIn = null;
             * FileOutputStream channelOut = null;
             * FileInputStream tunnelIn = null;
             * FileOutputStream tunnelOut = null;
             *
             * try
             * {
             *      string inError = null;
             *      string outError = null;
             *
             *      channelIn = new FileInputStream(m_channelFileDescriptor.FileDescriptor);
             *      channelOut = new FileOutputStream(m_channelFileDescriptor.FileDescriptor);
             *
             *      tunnelIn = new FileInputStream(m_tunnelFileDescriptor.FileDescriptor);
             *      tunnelOut = new FileOutputStream(m_tunnelFileDescriptor.FileDescriptor);
             *
             *      TaskEx taskIn = Service.TasksManager.Add((CancellationToken c) =>
             *      {
             *              ReadPackets(channelIn, tunnelOut, c, out inError);
             *      });
             *
             *      TaskEx taskOut = Service.TasksManager.Add((CancellationToken c) =>
             *      {
             *              WritePackets(tunnelIn, channelOut, c, out outError);
             *      });
             *
             *      bool loop = true;
             *
             *      while(loop)
             *      {
             *              Utils.Sleep(THREAD_DELAY);
             *
             *              // TODO: update stats
             *
             *              if(taskIn.IsCompleted || taskOut.IsCompleted || m_cancellationToken.IsCancellationRequested)
             *                      loop = false;
             *      }
             *
             *      LogsManager.Instance.Debug("ExchangeData2");
             *
             *      taskIn.Cancel();
             *      taskIn.Wait();
             *
             *      LogsManager.Instance.Debug("ExchangeData3");
             *
             *      taskOut.Cancel();
             *      taskOut.Wait();
             *
             *      LogsManager.Instance.Debug("ExchangeData4");
             *
             *      if(Utils.Empty(inError) == false)
             *              throw new Exception(inError);
             *
             *      if(Utils.Empty(outError) == false)
             *              throw new Exception(outError);
             * }
             * finally
             * {
             *      Utils.SafeDispose(channelIn);
             *      Utils.SafeDispose(channelOut);
             *
             *      Utils.SafeDispose(tunnelIn);
             *      Utils.SafeDispose(tunnelOut);
             * }
             *
             * LogsManager.Instance.Debug("ExchangeData5");
             */
        }
コード例 #20
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            supportTools = new SupportTools(this);

            SetContentView(Resource.Layout.settings_activity_layout);

            llVpnMinimumTLSVersion = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_tls_min_version);
            llVpnTransportProtocol = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_protocol);
            llVpnIPV6                 = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_ipv6);
            llVpnTimeout              = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_timeout);
            llVpnTunPersist           = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_tun_persist);
            llVpnCompressionMode      = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_compression_mode);
            llDnsOverride             = FindViewById <LinearLayout>(Resource.Id.setting_dns_override);
            llDnsOverrideSettings     = FindViewById <LinearLayout>(Resource.Id.dns_override_layout);
            llDnsCustom               = FindViewById <LinearLayout>(Resource.Id.setting_dns_custom);
            llDnsAlternative          = FindViewById <LinearLayout>(Resource.Id.setting_alternative_dns);
            llVpnUsername             = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_username);
            llVpnPassword             = FindViewById <LinearLayout>(Resource.Id.setting_ovpn3_password);
            llPauseVpnWhenScreenIsOff = FindViewById <LinearLayout>(Resource.Id.setting_pause_vpn_when_screen_is_off);
            llShowNotification        = FindViewById <LinearLayout>(Resource.Id.setting_show_notification);
            llRestoreLastProfile      = FindViewById <LinearLayout>(Resource.Id.setting_restore_last_profile);
            llApplicationFilterType   = FindViewById <LinearLayout>(Resource.Id.setting_application_filter_type);
            llApplicationFilter       = FindViewById <LinearLayout>(Resource.Id.setting_application_filter);
            llProxyEnable             = FindViewById <LinearLayout>(Resource.Id.setting_proxy_enable);
            llProxySettings           = FindViewById <LinearLayout>(Resource.Id.proxy_settings_layout);
            llProxyHost               = FindViewById <LinearLayout>(Resource.Id.setting_proxy_host);
            llProxyPort               = FindViewById <LinearLayout>(Resource.Id.setting_proxy_port);
            llProxyUsername           = FindViewById <LinearLayout>(Resource.Id.setting_proxy_username);
            llProxyPassword           = FindViewById <LinearLayout>(Resource.Id.setting_proxy_password);
            llProxyAllowClearTextAuth = FindViewById <LinearLayout>(Resource.Id.setting_proxy_allow_cleartext_auth);
            llSynchronousDnsLookup    = FindViewById <LinearLayout>(Resource.Id.setting_synchronous_dns_lookup);
            llCustomMtu               = FindViewById <LinearLayout>(Resource.Id.setting_custom_mtu);
            llAutologinSessions       = FindViewById <LinearLayout>(Resource.Id.setting_autologin_sessions);
            llDisableClientCert       = FindViewById <LinearLayout>(Resource.Id.setting_disable_client_cert);
            llSslDebugLevel           = FindViewById <LinearLayout>(Resource.Id.setting_ssl_debug_level);
            llPrivateKeyPassword      = FindViewById <LinearLayout>(Resource.Id.setting_private_key_password);
            llDefaultKeyDirection     = FindViewById <LinearLayout>(Resource.Id.setting_default_key_direction);
            llForceAesCbcCiphers      = FindViewById <LinearLayout>(Resource.Id.setting_force_aes_cbc_ciphers);
            llTlsCertProfile          = FindViewById <LinearLayout>(Resource.Id.setting_tls_cert_profile);
            llCustomDirectives        = FindViewById <LinearLayout>(Resource.Id.setting_custom_directives);

            swVpnTunPersist           = FindViewById <Switch>(Resource.Id.switch_ovpn3_tun_persist);
            swDnsOverride             = FindViewById <Switch>(Resource.Id.switch_dns_override);
            swPauseVpnWhenScreeIsOff  = FindViewById <Switch>(Resource.Id.switch_pause_vpn_when_screen_is_off);
            swShowNotification        = FindViewById <Switch>(Resource.Id.switch_show_notification);
            swRestoreLastProfile      = FindViewById <Switch>(Resource.Id.switch_restore_last_profile);
            swProxyEnable             = FindViewById <Switch>(Resource.Id.switch_proxy_enable);
            swProxyAllowClearTextAuth = FindViewById <Switch>(Resource.Id.switch_proxy_allow_cleartext_auth);
            swSynchronousDnsLookup    = FindViewById <Switch>(Resource.Id.switch_synchronous_dns_lookup);
            swAutologinSessions       = FindViewById <Switch>(Resource.Id.switch_autologin_sessions);
            swDisableClientCert       = FindViewById <Switch>(Resource.Id.switch_disable_client_cert);
            swForceAesCbcCiphers      = FindViewById <Switch>(Resource.Id.switch_force_aes_cbc_ciphers);

            btnResetOptions = FindViewById <Button>(Resource.Id.btn_reset_settings);

            txtApplicationFilterTitle = FindViewById <TextView>(Resource.Id.settings_application_filter_title);

            llVpnMinimumTLSVersion.Click += delegate
            {
                SelectVpnMinimumTLSVersion();
            };

            llVpnTransportProtocol.Click += delegate
            {
                SelectVpnTransportProtocol();
            };

            llVpnIPV6.Click += delegate
            {
                SelectVpnIPV6();
            };

            llVpnTimeout.Click += delegate
            {
                SelectVpnTimeout();
            };

            llVpnTunPersist.Click += delegate
            {
                SelectVpnTunPersist();
            };

            llVpnCompressionMode.Click += delegate
            {
                SelectVpnCompressionMode();
            };

            llDnsOverride.Click += delegate
            {
                SelectDnsOverrideSettings();
            };

            llDnsCustom.Click += delegate
            {
                SelectDnsCustom();
            };

            llDnsAlternative.Click += delegate
            {
                SelectDnsAlternative();
            };

            llVpnUsername.Click += delegate
            {
                SelectVpnUsername();
            };

            llVpnPassword.Click += delegate
            {
                SelectVpnPassword();
            };

            llPauseVpnWhenScreenIsOff.Click += delegate
            {
                SelectPauseVpnWhenScreenIsOff();
            };

            llShowNotification.Click += delegate
            {
                SelectShowNotification();
            };

            llRestoreLastProfile.Click += delegate
            {
                SelectRestoreLastProfile();
            };

            llApplicationFilterType.Click += delegate
            {
                SelectApplicationFilterType();
            };

            llApplicationFilter.Click += delegate
            {
                SelectApplicationFilter();
            };

            llProxyEnable.Click += delegate
            {
                SelectProxyEnable();
            };

            llProxyHost.Click += delegate
            {
                SelectProxyHost();
            };

            llProxyPort.Click += delegate
            {
                SelectProxyPort();
            };

            llProxyUsername.Click += delegate
            {
                SelectProxyUsername();
            };

            llProxyPassword.Click += delegate
            {
                SelectProxyPassword();
            };

            llProxyAllowClearTextAuth.Click += delegate
            {
                SelectProxyAllowClearTextAuth();
            };

            llSynchronousDnsLookup.Click += delegate
            {
                SelectSynchronousDnsLookup();
            };

            llCustomMtu.Click += delegate
            {
                SelectCustomMtu();
            };

            llAutologinSessions.Click += delegate
            {
                SelectAutologinSessions();
            };

            llDisableClientCert.Click += delegate
            {
                SelectDisableClientCert();
            };

            llSslDebugLevel.Click += delegate
            {
                SelectSslDebugLevel();
            };

            llPrivateKeyPassword.Click += delegate
            {
                SelectPrivateKeyPassword();
            };

            llDefaultKeyDirection.Click += delegate
            {
                SelectDefaultKeyDirection();
            };

            llForceAesCbcCiphers.Click += delegate
            {
                SelectForceAesCbcCiphers();
            };

            llTlsCertProfile.Click += delegate
            {
                SelectTlsCertProfile();
            };

            llCustomDirectives.Click += delegate
            {
                SelectCustomDirectives();
            };

            btnResetOptions.Click += delegate
            {
                ResetToDefaultOptions();
            };

            SetupSettingControls();
        }