diff options
Diffstat (limited to 'src/se/leap')
-rw-r--r-- | src/se/leap/bitmaskclient/ConfigHelper.java | 3 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ConfigurationWizard.java | 13 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/Dashboard.java | 47 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/EIP.java | 35 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/EipServiceFragment.java | 14 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/LogInDialog.java | 4 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/NewProviderDialog.java | 13 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/Provider.java | 2 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderAPI.java | 5 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderListFragment.java | 17 | ||||
-rw-r--r-- | src/se/leap/openvpn/ConfigParser.java | 6 | ||||
-rw-r--r-- | src/se/leap/openvpn/OpenVPN.java | 5 | ||||
-rw-r--r-- | src/se/leap/openvpn/OpenVPNThread.java | 2 | ||||
-rw-r--r-- | src/se/leap/openvpn/OpenVpnManagementThread.java | 28 | ||||
-rw-r--r-- | src/se/leap/openvpn/OpenVpnService.java | 13 | ||||
-rw-r--r-- | src/se/leap/openvpn/VpnProfile.java | 1 |
16 files changed, 164 insertions, 44 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigHelper.java b/src/se/leap/bitmaskclient/ConfigHelper.java index a29ff301..dd7049a7 100644 --- a/src/se/leap/bitmaskclient/ConfigHelper.java +++ b/src/se/leap/bitmaskclient/ConfigHelper.java @@ -58,7 +58,8 @@ public class ConfigHelper { private static boolean checkSharedPrefs() { try { - shared_preferences = Dashboard.getAppContext().getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE); + if(shared_preferences == null) + shared_preferences = Dashboard.getAppContext().getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE); } catch (Exception e) { return false; } diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java index 267fcd42..694dbf7c 100644 --- a/src/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java @@ -25,7 +25,6 @@ import org.json.JSONObject; import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -38,6 +37,7 @@ import android.content.IntentFilter; import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
+import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
@@ -68,6 +68,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn private ProviderListFragment provider_list_fragment;
private Intent mConfigState = new Intent();
+ final public static String TAG = "se.leap.bitmaskclient.ConfigurationWizard";
final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
final public static String ANON_CERTIFICATE = "anon_certificate";
final public static String AUTHED_CERTIFICATE = "authed_certificate";
@@ -185,9 +186,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn @Override
public void onItemSelected(String id) {
//TODO Code 2 pane view
+ // resetOldConnection();
ProviderItem selected_provider = getProvider(id);
int provider_index = getProviderIndex(id);
- startProgressBar(provider_index);
+ startProgressBar(provider_index); provider_list_fragment.hideAllBut(provider_index);
setUpProvider(selected_provider.providerMainUrl(), true);
}
@@ -397,7 +399,6 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn */
public void setUpProvider(String provider_main_url, boolean danger_on) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
-
Bundle parameters = new Bundle();
parameters.putString(Provider.MAIN_URL, provider_main_url);
parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
@@ -405,10 +406,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
+
startService(provider_API_command);
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.configuration_wizard_activity, menu);
@@ -445,7 +446,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn fragment_transaction.replace(R.id.configuration_wizard_layout, newFragment, AboutFragment.TAG).commit();
}
}
-
+
public void showAllProviders() {
provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(ProviderListFragment.TAG);
if(provider_list_fragment != null)
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java index 2f4c78a0..01a9c20a 100644 --- a/src/se/leap/bitmaskclient/Dashboard.java +++ b/src/se/leap/bitmaskclient/Dashboard.java @@ -35,6 +35,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.ResultReceiver; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -54,12 +55,16 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf protected static final int CONFIGURE_LEAP = 0; protected static final int SWITCH_PROVIDER = 1; + private static final String TAG_EIP_FRAGMENT = "EIP_DASHBOARD_FRAGMENT"; final public static String SHARED_PREFERENCES = "LEAPPreferences"; final public static String ACTION_QUIT = "quit"; public static final String REQUEST_CODE = "request_code"; + + + private ProgressBar mProgressBar; private TextView eipStatus; private static Context app; @@ -79,14 +84,16 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf app = this; PRNGFixes.apply(); - //mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard); + // mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard); + // mProgressBar = (ProgressBar) findViewById(R.id.eipProgress); + // eipStatus = (TextView) findViewById(R.id.eipStatus); mProgressBar = (ProgressBar) findViewById(R.id.eipProgress); ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE)); preferences = ConfigHelper.shared_preferences; - + authed_eip = ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP); if (ConfigHelper.getStringFromSharedPref(Provider.KEY).isEmpty()) startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP); @@ -101,11 +108,14 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ - if ( requestCode == CONFIGURE_LEAP ) { - if ( resultCode == RESULT_OK){ + if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { + // It should be equivalent: if ( (requestCode == CONFIGURE_LEAP) || (data!= null && data.hasExtra(STOP_FIRST))) { + if ( resultCode == RESULT_OK ){ + ConfigHelper.saveSharedPref(EIP.PARSED_SERIAL, 0); ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip); startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) ); buildDashboard(); + if(data != null && data.hasExtra(LogInDialog.VERB)) { View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0); logInDialog(view, Bundle.EMPTY); @@ -116,7 +126,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf configErrorDialog(); } } - + /** * Dialog shown when encountering a configuration error. Such errors require * reconfiguring LEAP or aborting the application. @@ -209,6 +219,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf startActivity(intent); return true; case R.id.switch_provider: + if (Provider.getInstance().hasEIP()){ + if (ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP)){ + logOut(); + } + eipStop(); + } ConfigHelper.removeFromSharedPref(Provider.KEY); startActivityForResult(new Intent(this,ConfigurationWizard.class), SWITCH_PROVIDER); return true; @@ -281,12 +297,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters); provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); - //if(mProgressDialog != null) mProgressDialog.dismiss(); - //mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.logout_title), getResources().getString(R.string.logout_message), true); + if(mProgressBar == null) mProgressBar = (ProgressBar) findViewById(R.id.eipProgress); mProgressBar.setVisibility(ProgressBar.VISIBLE); + if(eipStatus == null) eipStatus = (TextView) findViewById(R.id.eipStatus); eipStatus.setText("Starting to logout"); - //mProgressBar.setMax(1); startService(provider_API_command); + //mProgressBar.setMax(1); + } /** @@ -436,4 +453,18 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver); startService(eip_intent); } + + /** + * Send a command to EIP + * + */ + private void eipStop(){ + // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? + Intent eip_intent = new Intent(this, EIP.class); + eip_intent.setAction(EIP.ACTION_STOP_EIP); + // eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver); + startService(eip_intent); + + } + } diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java index f9384ff6..edd73e83 100644 --- a/src/se/leap/bitmaskclient/EIP.java +++ b/src/se/leap/bitmaskclient/EIP.java @@ -214,8 +214,7 @@ public final class EIP extends IntentService { * Intent to {@link se.leap.openvpn.LaunchVPN} */ private void startEIP() { - if (activeGateway==null) - activeGateway = selectGateway(); + activeGateway = selectGateway(); Intent intent = new Intent(this,LaunchVPN.class); intent.setAction(Intent.ACTION_MAIN); @@ -252,10 +251,19 @@ public final class EIP extends IntentService { private void updateEIPService() { try { eipDefinition = ConfigHelper.getJsonFromSharedPref(EIP.KEY); + parsedEipSerial = ConfigHelper.getIntFromSharedPref(PARSED_SERIAL); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } + if(parsedEipSerial == 0) { + // Delete all vpn profiles + ProfileManager vpl = ProfileManager.getInstance(context); + Collection<VpnProfile> profiles = vpl.getProfiles(); + for (VpnProfile profile : profiles){ + vpl.removeProfile(context, profile); + } + } if (eipDefinition.optInt("serial") > parsedEipSerial) updateGateways(); } @@ -431,6 +439,8 @@ public final class EIP extends IntentService { String ports = "ports"; String protos = "protocols"; String capabilities = "capabilities"; + String location_key = "location"; + String locations = "locations"; Vector<String> arg = new Vector<String>(); Vector<Vector<String>> args = new Vector<Vector<String>>(); @@ -447,7 +457,6 @@ public final class EIP extends IntentService { arg.add(word); value.add( (Vector<String>) arg.clone() ); options.put(key, (Vector<Vector<String>>) value.clone()); - value.clear(); arg.clear(); } @@ -457,7 +466,7 @@ public final class EIP extends IntentService { } try { - arg.add("remote"); + arg.add(remote); arg.add(mGateway.getString(remote)); } catch (JSONException e) { // TODO Auto-generated catch block @@ -467,7 +476,25 @@ public final class EIP extends IntentService { options.put("remote", (Vector<Vector<String>>) args.clone() ); arg.clear(); args.clear(); + + + try { + + arg.add(location_key); + String locationText = ""; + locationText = eipDefinition.getJSONObject(locations).getJSONObject(mGateway.getString(location_key)).getString("name"); + arg.add(locationText); + + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + args.add((Vector<String>) arg.clone()); + options.put("location", (Vector<Vector<String>>) args.clone() ); + + arg.clear(); + args.clear(); JSONArray protocolsJSON = null; arg.add("proto"); try { diff --git a/src/se/leap/bitmaskclient/EipServiceFragment.java b/src/se/leap/bitmaskclient/EipServiceFragment.java index 4d778b1a..b409394b 100644 --- a/src/se/leap/bitmaskclient/EipServiceFragment.java +++ b/src/se/leap/bitmaskclient/EipServiceFragment.java @@ -12,6 +12,7 @@ import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.ResultReceiver; +import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -38,6 +39,9 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli private EIPReceiver mEIPReceiver; + + public static String TAG = "se.leap.bitmask.EipServiceFragment"; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -57,6 +61,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli eipStatus.setOnClickListener(this); eipSwitch = (Switch) eipFragment.findViewById(R.id.eipSwitch); + + eipSwitch.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { @@ -66,6 +72,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli }); eipSwitch.setOnCheckedChangeListener(this); + return eipFragment; } @@ -152,6 +159,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli eipAutoSwitched = true; } + + /** * Send a command to EIP * @@ -186,13 +195,15 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli statusMessage = getString(R.string.eip_state_connected); getActivity().findViewById(R.id.eipProgress).setVisibility(View.GONE); mEipStartPending = false; - } else if ( (state.equals("NOPROCESS") && !mEipStartPending ) || state.equals("EXITING")) { + } else if ( (state.equals("NOPROCESS") && !mEipStartPending ) || state.equals("EXITING") || state.equals("FATAL")) { statusMessage = getString(R.string.eip_state_not_connected); getActivity().findViewById(R.id.eipProgress).setVisibility(View.GONE); mEipStartPending = false; switchState = false; } else if (state.equals("NOPROCESS")){ statusMessage = logmessage; + } else if (state.equals("ASSIGN_IP")){ //don't show assigning message in eipStatus + statusMessage = (String) eipStatus.getText(); } else { statusMessage = prefix + " " + logmessage; @@ -207,6 +218,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli }); } + /** * Inner class for handling messages related to EIP status and control requests * diff --git a/src/se/leap/bitmaskclient/LogInDialog.java b/src/se/leap/bitmaskclient/LogInDialog.java index 3651e9ba..81a3f764 100644 --- a/src/se/leap/bitmaskclient/LogInDialog.java +++ b/src/se/leap/bitmaskclient/LogInDialog.java @@ -86,8 +86,8 @@ public class LogInDialog extends DialogFragment { builder.setView(log_in_dialog_view) .setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - String username = username_field.getText().toString().trim(); - String password = password_field.getText().toString().trim(); + String username = username_field.getText().toString(); + String password = password_field.getText().toString(); dialog.dismiss(); interface_with_Dashboard.authenticate(username, password); } diff --git a/src/se/leap/bitmaskclient/NewProviderDialog.java b/src/se/leap/bitmaskclient/NewProviderDialog.java index 16d46c67..98686bd2 100644 --- a/src/se/leap/bitmaskclient/NewProviderDialog.java +++ b/src/se/leap/bitmaskclient/NewProviderDialog.java @@ -22,6 +22,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -38,7 +39,7 @@ import android.widget.Toast; public class NewProviderDialog extends DialogFragment { final public static String TAG = "newProviderDialog"; - + public interface NewProviderDialogInterface { public void showAndSelectProvider(String url_provider, boolean danger_on); } @@ -71,13 +72,15 @@ public class NewProviderDialog extends DialogFragment { View new_provider_dialog_view = inflater.inflate(R.layout.new_provider_dialog, null); final EditText url_input_field = (EditText)new_provider_dialog_view.findViewById(R.id.new_provider_url); final CheckBox danger_checkbox = (CheckBox)new_provider_dialog_view.findViewById(R.id.danger_checkbox); - builder.setView(new_provider_dialog_view) .setMessage(R.string.introduce_new_provider) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String entered_url = url_input_field.getText().toString().trim(); if(!entered_url.startsWith("https://")) { + if (entered_url.startsWith("http://")){ + entered_url = entered_url.substring("http://".length()); + } entered_url = "https://".concat(entered_url); } boolean danger_on = danger_checkbox.isChecked(); @@ -86,7 +89,8 @@ public class NewProviderDialog extends DialogFragment { Toast.makeText(getActivity().getApplicationContext(), R.string.valid_url_entered, Toast.LENGTH_LONG).show(); } else { url_input_field.setText(""); - Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show(); + danger_checkbox.setChecked(false); + Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show();; } } }) @@ -105,6 +109,7 @@ public class NewProviderDialog extends DialogFragment { * @return true if it's not empty nor contains only the protocol. */ boolean validURL(String entered_url) { - return !entered_url.isEmpty() && entered_url.matches("http[s]?://.+") && !entered_url.replaceFirst("http[s]?://", "").isEmpty(); + //return !entered_url.isEmpty() && entered_url.matches("http[s]?://.+") && !entered_url.replaceFirst("http[s]?://", "").isEmpty(); + return android.util.Patterns.WEB_URL.matcher(entered_url).matches(); } } diff --git a/src/se/leap/bitmaskclient/Provider.java b/src/se/leap/bitmaskclient/Provider.java index 3c029702..598999fd 100644 --- a/src/se/leap/bitmaskclient/Provider.java +++ b/src/se/leap/bitmaskclient/Provider.java @@ -166,6 +166,8 @@ public final class Provider implements Serializable { // Walk the EIP types array looking for matches in provider's service definitions if ( Arrays.asList(API_EIP_TYPES).contains( services.getString(i) ) ) return true; + } catch (NullPointerException e){ + e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java index 83afd95c..cc94edff 100644 --- a/src/se/leap/bitmaskclient/ProviderAPI.java +++ b/src/se/leap/bitmaskclient/ProviderAPI.java @@ -452,7 +452,7 @@ public class ProviderAPI extends IntentService { private boolean validCertificate(String cert_string) { boolean result = false; - if(!cert_string.isEmpty()) { + if(!ConfigHelper.checkErroneousDownload(cert_string)) { X509Certificate certCert = ConfigHelper.parseX509CertificateFromString(cert_string); try { Base64.encodeToString( certCert.getEncoded(), Base64.DEFAULT); @@ -723,6 +723,9 @@ public class ProviderAPI extends IntentService { URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.CERTIFICATE); boolean danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON); +//<<<<<<< HEAD +// String cert_string = downloadWithProviderCA(new_cert_string_url, true); +//======= String cert_string = downloadWithProviderCA(new_cert_string_url.toString(), danger_on); if(!cert_string.isEmpty()) { if(ConfigHelper.checkErroneousDownload(cert_string)) { diff --git a/src/se/leap/bitmaskclient/ProviderListFragment.java b/src/se/leap/bitmaskclient/ProviderListFragment.java index 862177a2..f074e665 100644 --- a/src/se/leap/bitmaskclient/ProviderListFragment.java +++ b/src/se/leap/bitmaskclient/ProviderListFragment.java @@ -156,11 +156,14 @@ public class ProviderListFragment extends ListFragment { // Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mCallbacks.onItemSelected(ProviderListContent.ITEMS.get(position).name());
+//<<<<<<< HEAD +//======= for(int item_position = 0; item_position < listView.getCount(); item_position++) {
if(item_position != position)
content_adapter.hide(item_position);
}
+//>>>>>>> feature/token-based-auth }
@Override
@@ -203,11 +206,23 @@ public class ProviderListFragment extends ListFragment { }
public void hideAllBut(int position) {
- for(int i = 0; i < content_adapter.getCount(); i++)
+//<<<<<<< HEAD + int real_count = content_adapter.getCount();
+ for(int i = 0; i < real_count;)
+ if(i != position) {
+ content_adapter.hide(i);
+ position--;
+ real_count--;
+ } else {
+ i++;
+ }
+//======= +/* for(int i = 0; i < content_adapter.getCount(); i++)
if(i != position)
content_adapter.hide(i);
else
content_adapter.unHide(i);
+*///>>>>>>> feature/token-based-auth }
public void unhideAll() {
diff --git a/src/se/leap/openvpn/ConfigParser.java b/src/se/leap/openvpn/ConfigParser.java index 3d369fa6..36585d29 100644 --- a/src/se/leap/openvpn/ConfigParser.java +++ b/src/se/leap/openvpn/ConfigParser.java @@ -355,6 +355,12 @@ public class ConfigParser { np.mServerName = remote.get(1); } } + + // Parse remote config + Vector<String> location = getOption("location",1,2); + if(location != null && location.size() == 2){ + np.mLocation = location.get(1).replace("__", ", "); + } Vector<Vector<String>> dhcpoptions = getAllOption("dhcp-option", 2, 2); if(dhcpoptions!=null) { diff --git a/src/se/leap/openvpn/OpenVPN.java b/src/se/leap/openvpn/OpenVPN.java index d7d17b4f..8acdc423 100644 --- a/src/se/leap/openvpn/OpenVPN.java +++ b/src/se/leap/openvpn/OpenVPN.java @@ -25,6 +25,7 @@ public class OpenVPN { private static String mLaststate; private static int mLastStateresid=R.string.state_noprocess; + public static String TAG="se.leap.openvpn.OpenVPN"; static { logbuffer = new LinkedList<LogItem>(); @@ -166,6 +167,8 @@ public class OpenVPN { return R.string.state_resolve; else if (state.equals("TCP_CONNECT")) return R.string.state_tcp_connect; + else if (state.equals("FATAL")) + return R.string.eip_state_not_connected; else return R.string.unknown_state; @@ -197,7 +200,7 @@ public class OpenVPN { } - public static void updateStateString (String state, String msg) { + public static void updateStateString (String state, String msg) { int rid = getLocalizedState(state); updateStateString(state, msg,rid); } diff --git a/src/se/leap/openvpn/OpenVPNThread.java b/src/se/leap/openvpn/OpenVPNThread.java index 0c383ab0..ffd21732 100644 --- a/src/se/leap/openvpn/OpenVPNThread.java +++ b/src/se/leap/openvpn/OpenVPNThread.java @@ -56,7 +56,7 @@ public class OpenVPNThread implements Runnable { if( exitvalue != 0)
OpenVPN.logError("Process exited with exit value " + exitvalue);
- OpenVPN.updateStateString("NOPROCESS","No process running.", R.string.state_noprocess);
+// OpenVPN.updateStateString("NOPROCESS","No process running.", R.string.state_noprocess); fixes bug #4565
if(mDumpPath!=null) {
try {
BufferedWriter logout = new BufferedWriter(new FileWriter(mDumpPath + ".log"));
diff --git a/src/se/leap/openvpn/OpenVpnManagementThread.java b/src/se/leap/openvpn/OpenVpnManagementThread.java index 78ce5a2b..27a3db65 100644 --- a/src/se/leap/openvpn/OpenVpnManagementThread.java +++ b/src/se/leap/openvpn/OpenVpnManagementThread.java @@ -19,7 +19,6 @@ import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException;
import se.leap.bitmaskclient.R;
-
import android.content.SharedPreferences;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
@@ -177,11 +176,12 @@ public class OpenVpnManagementThread implements Runnable { private void processCommand(String command) {
+ Log.d(TAG, "processCommand: " + command);
+
if (command.startsWith(">") && command.contains(":")) {
String[] parts = command.split(":",2);
String cmd = parts[0].substring(1);
String argument = parts[1];
-
if(cmd.equals("INFO")) {
// Ignore greeting from mgmt
//logStatusMessage(command);
@@ -195,6 +195,8 @@ public class OpenVpnManagementThread implements Runnable { processByteCount(argument);
} else if (cmd.equals("STATE")) {
processState(argument);
+ } else if (cmd.equals("FATAL")){
+ processState(","+cmd+","); //handles FATAL as state
} else if (cmd.equals("PROXY")) {
processProxyCMD(argument);
} else if (cmd.equals("LOG")) {
@@ -209,8 +211,11 @@ public class OpenVpnManagementThread implements Runnable { OpenVPN.logMessage(0, "MGMT:", "Got unrecognized command" + command);
Log.i(TAG, "Got unrecognized command" + command);
}
- } else if (command.startsWith("SUCCESS:")) {
- // ignore
+ } else if (command.startsWith("SUCCESS:")) { //Fixes bug LEAP #4565
+ if (command.equals("SUCCESS: signal SIGINT thrown")){
+ Log.d(TAG, "SUCCESS: signal SIGINT thrown");
+ processState(",EXITING,SIGINT,,");
+ }
} else {
Log.i(TAG, "Got unrecognized line from managment" + command);
OpenVPN.logMessage(0, "MGMT:", "Got unrecognized line from management:" + command);
@@ -272,11 +277,17 @@ public class OpenVpnManagementThread implements Runnable { private void processState(String argument) {
String[] args = argument.split(",",3);
String currentstate = args[1];
- Log.d("OpenVPN log", argument);
- if(args[2].equals(",,"))
+ if(args[2].equals(",,")){
OpenVPN.updateStateString(currentstate,"");
- else
+ }
+ else if (args[2].endsWith(",,")){ //fixes LEAP Bug #4546
+ args[2] = (String) args[2].subSequence(0, args[2].length()-2);
+ Log.d(TAG, "processState() STATE: "+ currentstate + " msg: " + args[2]);
+ OpenVPN.updateStateString(currentstate,args[2]);
+ }
+ else{
OpenVPN.updateStateString(currentstate,args[2]);
+ }
}
private static int repeated_byte_counts = 0;
@@ -333,8 +344,7 @@ public class OpenVpnManagementThread implements Runnable { mOpenVPNService.setDomain(extra);
} else if (needed.equals("ROUTE")) {
String[] routeparts = extra.split(" ");
- if(!mOpenVPNService.isRunning()) // We cannot add routes to an existing openvpn session
- mOpenVPNService.addRoute(routeparts[0], routeparts[1]);
+ mOpenVPNService.addRoute(routeparts[0], routeparts[1]);
} else if (needed.equals("ROUTE6")) {
mOpenVPNService.addRoutev6(extra);
} else if (needed.equals("IFCONFIG")) {
diff --git a/src/se/leap/openvpn/OpenVpnService.java b/src/se/leap/openvpn/OpenVpnService.java index 620de204..b5c9c798 100644 --- a/src/se/leap/openvpn/OpenVpnService.java +++ b/src/se/leap/openvpn/OpenVpnService.java @@ -106,7 +106,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac String ns = Context.NOTIFICATION_SERVICE; mNotificationManager = (NotificationManager) getSystemService(ns); int icon; - if (state.equals("NOPROCESS") || state.equals("AUTH_FAILED") || state.equals("NONETWORK")){ + if (state.equals("NOPROCESS") || state.equals("AUTH_FAILED") || state.equals("NONETWORK") || state.equals("EXITING")){ icon = R.drawable.ic_vpn_disconnected; }else{ icon = R.drawable.ic_stat_vpn; @@ -114,7 +114,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac android.app.Notification.Builder nbuilder = new Notification.Builder(this); - nbuilder.setContentTitle(getString(R.string.notifcation_title,mProfile.mName)); + nbuilder.setContentTitle(getString(R.string.notifcation_title,mProfile.mLocation)); nbuilder.setContentText(msg); nbuilder.setOnlyAlertOnce(true); nbuilder.setOngoing(persistant); @@ -350,12 +350,13 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac bconfig[4] = getString(R.string.routes_info, joinString(mRoutes)); bconfig[5] = getString(R.string.routes_info6, joinString(mRoutesv6)); - String session = mProfile.mName; + String session = mProfile.mLocation; + /* we don't want the IP address in the notification bar if(mLocalIP!=null && mLocalIPv6!=null) session = getString(R.string.session_ipv6string,session, mLocalIP, mLocalIPv6); else if (mLocalIP !=null) session= getString(R.string.session_ipv4string, session, mLocalIP); - + */ builder.setSession(session); @@ -478,9 +479,11 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac // CONNECTED String ticker = getString(resid); boolean persist = false; - if (("NOPROCESS".equals(state) ) || ("EXIT").equals(state)){ + if (("NOPROCESS".equals(state) ) || ("EXITING").equals(state)){ showNotification(state, getString(R.string.eip_state_not_connected), ticker, false, 0, persist); } + else if (state.equals("GET_CONFIG") || state.equals("ASSIGN_IP")){ //don't show them in the notification message + } else{ persist = true; showNotification(state, getString(resid) +" " + logmessage,ticker,false,0,persist); diff --git a/src/se/leap/openvpn/VpnProfile.java b/src/se/leap/openvpn/VpnProfile.java index 41cf574b..99e1c676 100644 --- a/src/se/leap/openvpn/VpnProfile.java +++ b/src/se/leap/openvpn/VpnProfile.java @@ -68,6 +68,7 @@ public class VpnProfile implements Serializable{ private UUID mUuid; public int mAuthenticationType = TYPE_CERTIFICATES ; public String mName; + public String mLocation; public String mAlias; public String mClientCertFilename; public String mTLSAuthDirection=""; |