diff options
author | Arne Schwabe <arne@rfc2549.org> | 2012-04-30 18:26:01 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2012-04-30 18:26:01 +0200 |
commit | c3a13c133484e0750786b33ced635cbb2c642904 (patch) | |
tree | abbc6ebdf42a04b952a496146c538bd43f50036a /src | |
parent | 73f914bdc1a681f827ed2375820c2d171e31bb0b (diff) |
- new Icon :)
- Obscure settings
- version 0.4.5
- quick launch
Diffstat (limited to 'src')
-rw-r--r-- | src/de/blinkt/openvpn/LaunchVPN.java | 305 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/LogWindow.java | 2 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnService.java | 9 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/ProfileManager.java | 4 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/Settings_Obscure.java | 71 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VPNPreferences.java | 3 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VPNProfileList.java | 100 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VpnProfile.java | 93 |
8 files changed, 440 insertions, 147 deletions
diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java new file mode 100644 index 00000000..38a3b5d7 --- /dev/null +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package de.blinkt.openvpn; + +import java.util.Collection; +import java.util.Vector; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.ListActivity; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.VpnService; +import android.os.Bundle; +import android.os.Parcelable; +import android.view.View; +import android.view.inputmethod.EditorInfo; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +/** + * This Activity actually handles two stages of a launcher shortcut's life cycle. + * + * 1. Your application offers to provide shortcuts to the launcher. When + * the user installs a shortcut, an activity within your application + * generates the actual shortcut and returns it to the launcher, where it + * is shown to the user as an icon. + * + * 2. Any time the user clicks on an installed shortcut, an intent is sent. + * Typically this would then be handled as necessary by an activity within + * your application. + * + * We handle stage 1 (creating a shortcut) by simply sending back the information (in the form + * of an {@link android.content.Intent} that the launcher will use to create the shortcut. + * + * You can also implement this in an interactive way, by having your activity actually present + * UI for the user to select the specific nature of the shortcut, such as a contact, picture, URL, + * media item, or action. + * + * We handle stage 2 (responding to a shortcut) in this sample by simply displaying the contents + * of the incoming {@link android.content.Intent}. + * + * In a real application, you would probably use the shortcut intent to display specific content + * or start a particular operation. + */ +public class LaunchVPN extends ListActivity implements OnItemClickListener { + + static final String EXTRA_KEY = "de.blinkt.openvpn.shortcutProfileUUID"; + private static final int START_VPN_PROFILE= 70; + + private ProfileManager mPM; + private VpnProfile mSelectedProfile; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // Resolve the intent + + final Intent intent = getIntent(); + final String action = intent.getAction(); + + mPM =ProfileManager.getInstance(); + if(mPM.getNumberOfProfiles() == 0) { + mPM.loadVPNList(this); + } + + + // If the intent is a request to create a shortcut, we'll do that and exit + + if(Intent.ACTION_MAIN.equals(action)) { + // we got called to be the starting point, most likely a shortcut + String shortcutUUID = intent.getStringExtra( EXTRA_KEY); + + VpnProfile profileToConnect = ProfileManager.get(shortcutUUID); + if(profileToConnect ==null) { + Toast notfound = Toast.makeText(this, R.string.shortcut_profile_notfound, Toast.LENGTH_SHORT); + notfound.show(); + finish(); + return; + } + + mSelectedProfile = profileToConnect; + launchVPN(); + + + + } else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { + createListView(); + } + + + + + + + + } + + private void createListView() { + ListView lv = getListView(); + //lv.setTextFilterEnabled(true); + + Collection<VpnProfile> vpnlist = mPM.getProfiles(); + + Vector<String> vpnnames=new Vector<String>(); + for (VpnProfile vpnProfile : vpnlist) { + vpnnames.add(vpnProfile.mName); + } + + + + ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,vpnnames); + lv.setAdapter(adapter); + + lv.setOnItemClickListener(this); + } + + /** + * This function creates a shortcut and returns it to the caller. There are actually two + * intents that you will send back. + * + * The first intent serves as a container for the shortcut and is returned to the launcher by + * setResult(). This intent must contain three fields: + * + * <ul> + * <li>{@link android.content.Intent#EXTRA_SHORTCUT_INTENT} The shortcut intent.</li> + * <li>{@link android.content.Intent#EXTRA_SHORTCUT_NAME} The text that will be displayed with + * the shortcut.</li> + * <li>{@link android.content.Intent#EXTRA_SHORTCUT_ICON} The shortcut's icon, if provided as a + * bitmap, <i>or</i> {@link android.content.Intent#EXTRA_SHORTCUT_ICON_RESOURCE} if provided as + * a drawable resource.</li> + * </ul> + * + * If you use a simple drawable resource, note that you must wrapper it using + * {@link android.content.Intent.ShortcutIconResource}, as shown below. This is required so + * that the launcher can access resources that are stored in your application's .apk file. If + * you return a bitmap, such as a thumbnail, you can simply put the bitmap into the extras + * bundle using {@link android.content.Intent#EXTRA_SHORTCUT_ICON}. + * + * The shortcut intent can be any intent that you wish the launcher to send, when the user + * clicks on the shortcut. Typically this will be {@link android.content.Intent#ACTION_VIEW} + * with an appropriate Uri for your content, but any Intent will work here as long as it + * triggers the desired action within your Activity. + * @param profile + */ + private void setupShortcut(VpnProfile profile) { + // First, set up the shortcut intent. For this example, we simply create an intent that + // will bring us directly back to this activity. A more typical implementation would use a + // data Uri in order to display a more specific result, or a custom action in order to + // launch a specific operation. + + Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); + shortcutIntent.setClass(this, LaunchVPN.class); + shortcutIntent.putExtra(EXTRA_KEY,profile.getUUID().toString()); + + // Then, set up the container intent (the response to the caller) + + Intent intent = new Intent(); + intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); + intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profile.getName()); + Parcelable iconResource = Intent.ShortcutIconResource.fromContext( + this, R.drawable.icon); + intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); + + // Now, return the result to the launcher + + setResult(RESULT_OK, intent); + } + + + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, + long id) { + String profilename = ((TextView) view).getText().toString(); + + VpnProfile profile = mPM.getProfileByName(profilename); + + // if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { + setupShortcut(profile); + finish(); + return; + // } + + } + + private void askForPW(String type) { + + final EditText entry = new EditText(this); + entry.setSingleLine(); + entry.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); + + AlertDialog.Builder dialog = new AlertDialog.Builder(this); + dialog.setTitle("Need " + type); + dialog.setMessage("Enter the password for profile " + mSelectedProfile.mName); + dialog.setView(entry); + + dialog.setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String pw = entry.getText().toString(); + mSelectedProfile.mTransientPW = pw; + onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); + + } + + }); + dialog.setNegativeButton(android.R.string.cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } + }); + + dialog.create().show(); + + } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if(requestCode==START_VPN_PROFILE && resultCode == Activity.RESULT_OK) { + + if(mSelectedProfile.needUserPWInput()!=null) { + askForPW(mSelectedProfile.needUserPWInput()); + } else { + new startOpenVpnThread().start(); + } + + } + } + + void showConfigErrorDialog(int vpnok) { + AlertDialog.Builder d = new AlertDialog.Builder(this); + d.setTitle(R.string.config_error_found); + d.setMessage(vpnok); + d.setPositiveButton("Ok", null); + d.show(); + } + + void launchVPN () { + + + int vpnok = mSelectedProfile.checkProfile(); + if(vpnok!= R.string.no_error_found) { + showConfigErrorDialog(vpnok); + return; + } + + Intent intent = VpnService.prepare(this); + + if (intent != null) { + // Start the query + startActivityForResult(intent, START_VPN_PROFILE); + } else { + onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); + } + + } + + private class startOpenVpnThread extends Thread { + + @Override + public void run() { + startOpenVpn(); + } + + void startOpenVpn() { + Intent startLW = new Intent(getBaseContext(),LogWindow.class); + startActivity(startLW); + + + OpenVPN.logMessage(0, "", "Building configration..."); + + Intent startVPN = mSelectedProfile.prepareIntent(getBaseContext()); + + startService(startVPN); + finish(); + + } + } + + +} diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index b5e7008f..16f54b12 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -21,8 +21,6 @@ public class LogWindow extends ListActivity { class LogWindowListAdapter implements ListAdapter,LogListener, Callback { - private static final int LIST_CHANGED = 0; - private Vector<String> myEntries=new Vector<String>(); private Handler mHandler; diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index 644b060f..8da49bad 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -19,9 +19,7 @@ package de.blinkt.openvpn; import java.io.IOException; import java.util.Vector; -import android.app.NotificationManager; import android.app.PendingIntent; -import android.content.Context; import android.content.Intent; import android.net.LocalSocket; import android.net.LocalSocketAddress; @@ -32,8 +30,6 @@ import android.os.ParcelFileDescriptor; import android.widget.Toast; public class OpenVpnService extends VpnService implements Handler.Callback { - private static final String TAG = "OpenVpnService"; - Handler mHandler; private Thread mServiceThread; @@ -53,8 +49,6 @@ public class OpenVpnService extends VpnService implements Handler.Callback { private Thread mSocketManagerThread; - private NotificationManager mNotificationManager; - class CIDRIP{ @@ -135,9 +129,6 @@ public class OpenVpnService extends VpnService implements Handler.Callback { mHandler = new Handler(this); } - mNotificationManager=(NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); - - // Stop the previous session by interrupting the thread. if (mSocketManager != null) { mSocketManager.managmentCommand("signal SIGINT\n"); diff --git a/src/de/blinkt/openvpn/ProfileManager.java b/src/de/blinkt/openvpn/ProfileManager.java index 5e6b7912..9e5b1602 100644 --- a/src/de/blinkt/openvpn/ProfileManager.java +++ b/src/de/blinkt/openvpn/ProfileManager.java @@ -116,4 +116,8 @@ public class ProfileManager { } } + public int getNumberOfProfiles() { + return profiles.size(); + } + } diff --git a/src/de/blinkt/openvpn/Settings_Obscure.java b/src/de/blinkt/openvpn/Settings_Obscure.java index 83754663..55615917 100644 --- a/src/de/blinkt/openvpn/Settings_Obscure.java +++ b/src/de/blinkt/openvpn/Settings_Obscure.java @@ -1,21 +1,74 @@ package de.blinkt.openvpn; import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -public class Settings_Obscure extends PreferenceFragment { +public class Settings_Obscure extends PreferenceFragment implements OnPreferenceChangeListener { + private VpnProfile mProfile; + private CheckBoxPreference mUseRandomHostName; + private CheckBoxPreference mUseFloat; + private CheckBoxPreference mUseCustomConfig; + private EditTextPreference mCustomConfig; + private ListPreference mLogverbosity; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - // Make sure default values are applied. In a real app, you would - // want this in a shared function that is used to retrieve the - // SharedPreferences wherever they are needed. - PreferenceManager.setDefaultValues(getActivity(), - R.xml.vpn_ipsettings, false); - // Load the preferences from an XML resource addPreferencesFromResource(R.xml.vpn_obscure); + + String profileUUID = getArguments().getString(getActivity().getPackageName() + ".profileUUID"); + mProfile = ProfileManager.get(profileUUID); + + + mUseRandomHostName = (CheckBoxPreference) findPreference("useRandomHostname"); + mUseFloat = (CheckBoxPreference) findPreference("useFloat"); + mUseCustomConfig = (CheckBoxPreference) findPreference("enableCustomOptions"); + mCustomConfig = (EditTextPreference) findPreference("customOptions"); + mLogverbosity = (ListPreference) findPreference("verblevel"); + + mLogverbosity.setOnPreferenceChangeListener(this); + + loadSettings(); + + } + + private void loadSettings() { + mUseRandomHostName.setChecked(mProfile.mUseRandomHostname); + mUseFloat.setChecked(mProfile.mUseFloat); + mUseCustomConfig.setChecked(mProfile.mUseCustomConfig); + mCustomConfig.setText(mProfile.mCustomConfigOptions); + + mLogverbosity.setValue(mProfile.mVerb); + onPreferenceChange(mLogverbosity, mProfile.mVerb); } + + @Override + public void onPause() { + saveSettings(); + super.onPause(); + } + + private void saveSettings() { + mProfile.mUseRandomHostname = mUseRandomHostName.isChecked(); + mProfile.mUseFloat = mUseFloat.isChecked(); + mProfile.mUseCustomConfig = mUseCustomConfig.isChecked(); + mProfile.mCustomConfigOptions = mCustomConfig.getText(); + mProfile.mVerb = mLogverbosity.getValue(); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if(preference==mLogverbosity) { + mLogverbosity.setDefaultValue(newValue); + } + + return true; + } + }
\ No newline at end of file diff --git a/src/de/blinkt/openvpn/VPNPreferences.java b/src/de/blinkt/openvpn/VPNPreferences.java index 38de9d3e..e1c8a401 100644 --- a/src/de/blinkt/openvpn/VPNPreferences.java +++ b/src/de/blinkt/openvpn/VPNPreferences.java @@ -37,11 +37,10 @@ public class VPNPreferences extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { - // profileUUID mProfileUUID = getIntent().getStringExtra(getPackageName() + ".profileUUID"); super.onCreate(savedInstanceState); - + /* if (hasHeaders()) { Button button = new Button(this); diff --git a/src/de/blinkt/openvpn/VPNProfileList.java b/src/de/blinkt/openvpn/VPNProfileList.java index bc61dddb..42c881a8 100644 --- a/src/de/blinkt/openvpn/VPNProfileList.java +++ b/src/de/blinkt/openvpn/VPNProfileList.java @@ -5,7 +5,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.net.VpnService; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; @@ -13,7 +12,6 @@ import android.preference.PreferenceScreen; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.Toast; import de.blinkt.openvpn.VPNConfigPreference.VpnPreferencesClickListener; @@ -21,7 +19,6 @@ import de.blinkt.openvpn.VPNConfigPreference.VpnPreferencesClickListener; public class VPNProfileList extends PreferenceFragment implements VpnPreferencesClickListener { private static final int MENU_ADD_PROFILE = Menu.FIRST; - private static final int START_VPN_PROFILE= 70; private static final int START_VPN_CONFIG = 92; @@ -59,38 +56,7 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference } } - private void askForPW(String type) { - final EditText entry = new EditText(getActivity()); - entry.setSingleLine(); - entry.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); - - AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); - dialog.setTitle("Need " + type); - dialog.setMessage("Enter the password for profile " + mSelectedVPN.mName); - dialog.setView(entry); - - dialog.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String pw = entry.getText().toString(); - mSelectedVPN.mTransientPW = pw; - onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); - - } - - }); - dialog.setNegativeButton(android.R.string.cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - } - }); - - dialog.create().show(); - - } private void onAddProfileClicked() { Context context = getActivity(); @@ -192,15 +158,7 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if(requestCode==START_VPN_PROFILE && resultCode == Activity.RESULT_OK) { - - if(mSelectedVPN.needUserPWInput()!=null) { - askForPW(mSelectedVPN.needUserPWInput()); - } else { - new startOpenVpnThread().start(); - } - - } else if (requestCode == START_VPN_CONFIG && resultCode == Activity.RESULT_OK) { + if (requestCode == START_VPN_CONFIG && resultCode == Activity.RESULT_OK) { String configuredVPN = data.getStringExtra(getActivity().getPackageName() + ".profileUUID"); VpnProfile profile = ProfileManager.get(configuredVPN); @@ -211,41 +169,7 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference } - private class startOpenVpnThread extends Thread { - - @Override - public void run() { - startOpenVpn(); - } - - void startOpenVpn() { - Intent startLW = new Intent(getActivity().getBaseContext(),LogWindow.class); - startActivity(startLW); - - - OpenVPN.logMessage(0, "", "Building configration..."); - - Intent startVPN = mSelectedVPN.prepareIntent(getActivity()); - - getActivity().startService(startVPN); - getActivity().finish(); - - } - } - - void showConfigErrorDialog(int vpnok) { - - AlertDialog.Builder d = new AlertDialog.Builder(getActivity()); - - d.setTitle(R.string.config_error_found); - - d.setMessage(vpnok); - - d.setPositiveButton("Ok", null); - - d.show(); - } @Override public void onStartVPNClick(VPNConfigPreference preference) { @@ -253,23 +177,13 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference // Query the System for permission mSelectedVPN = ProfileManager.get(preference.getKey()); - int vpnok = mSelectedVPN.checkProfile(); - if(vpnok!= R.string.no_error_found) { - showConfigErrorDialog(vpnok); - return; - } - - getPM().saveProfile(getActivity(), mSelectedVPN); - Intent intent = VpnService.prepare(getActivity()); - - if (intent != null) { - // Start the query - intent.putExtra("FOO", "WAR BIER"); - startActivityForResult(intent, START_VPN_PROFILE); - } else { - onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); - } + Intent intent = new Intent(getActivity(),LaunchVPN.class); + intent.putExtra(LaunchVPN.EXTRA_KEY, mSelectedVPN.getUUID().toString()); + intent.setAction(Intent.ACTION_MAIN); + startActivity(intent); + + getActivity().finish(); } } diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index a1b7a06f..11f2fffa 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -17,7 +17,6 @@ import java.util.Random; import java.util.UUID; import java.util.Vector; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Parcel; @@ -38,9 +37,11 @@ public class VpnProfile implements Serializable{ public static final int TYPE_STATICKEYS = 4; private static final String OVPNCONFIGFILE = "android.conf"; - - // Keep in order of parceling + protected transient String mTransientPW=null; + private static transient String mTempPKCS12Password; + + // Public attributes, since I got mad with getter/setter // set members to default values private UUID mUuid; @@ -74,16 +75,19 @@ public class VpnProfile implements Serializable{ public String mPassword=""; public String mUsername=""; public boolean mRoutenopull=false; + public boolean mUseRandomHostname=false; + public boolean mUseFloat=false; + public boolean mUseCustomConfig=false; + public String mCustomConfigOptions=""; + public String mVerb="1"; - - protected transient String mTransientPW=null; - private static transient String mTempPKCS12Password; public int describeContents() { return 0; } + // Not used public void writeToParcel(Parcel out, int flags) { out.writeInt(mAuthenticationType); out.writeLong(mUuid.getMostSignificantBits()); @@ -164,7 +168,7 @@ public class VpnProfile implements Serializable{ cfg +=cacheDir.getAbsolutePath() + "/" + "mgmtsocket"; cfg += " unix\n"; cfg += "management-hold\n\n"; - + cfg+="# tmp does not exist on Android\n"; cfg+="tmp-dir "; cfg+=cacheDir.getAbsolutePath(); @@ -180,10 +184,10 @@ public class VpnProfile implements Serializable{ cfg+="tls-client\n"; - cfg+="verb 2\n"; + cfg+="verb " + mVerb + "\n"; + - // quit after 5 tries cfg+="connect-retry-max 5\n"; @@ -239,7 +243,7 @@ public class VpnProfile implements Serializable{ cfg+="auth-user-pass\n"; cfg+="management-query-passwords\n"; break; - + } @@ -294,6 +298,26 @@ public class VpnProfile implements Serializable{ } if(mExpectTLSCert) cfg += "remote-cert-tls server\n"; + + + + + // Obscure Settings dialog + if(mUseRandomHostname) + cfg += "#my favorite options :)\nremote-random-hostname\n"; + + if(mUseFloat) + cfg+= "float\n"; + + if(mUseCustomConfig) { + cfg += "# Custom configuration options\n"; + cfg += "# You are on your on own here :)\n"; + cfg += mCustomConfigOptions; + cfg += "\n"; + + } + + return cfg; } @@ -309,11 +333,11 @@ public class VpnProfile implements Serializable{ String cidrroute = cidrToIPAndNetmask(route); if(cidrRoutes == null) return null; - + cidrRoutes.add(cidrroute); } } - + return cidrRoutes; } @@ -344,7 +368,7 @@ public class VpnProfile implements Serializable{ } - + private String[] buildOpenvpnArgv(File cacheDir) { Vector<String> args = new Vector<String>(); @@ -359,21 +383,21 @@ public class VpnProfile implements Serializable{ return (String[]) args.toArray(new String[args.size()]); } - public Intent prepareIntent(Activity activity) { - String prefix = activity.getPackageName(); + public Intent prepareIntent(Context context) { + String prefix = context.getPackageName(); - Intent intent = new Intent(activity,OpenVpnService.class); - - if(mAuthenticationType == VpnProfile.TYPE_KEYSTORE) { - savePKCS12(activity); - } + Intent intent = new Intent(context,OpenVpnService.class); - intent.putExtra(prefix + ".ARGV" , buildOpenvpnArgv(activity.getCacheDir())); + if(mAuthenticationType == VpnProfile.TYPE_KEYSTORE) { + savePKCS12(context); + } + + intent.putExtra(prefix + ".ARGV" , buildOpenvpnArgv(context.getCacheDir())); intent.putExtra(prefix + ".profileUUID", mUuid.toString()); try { - FileWriter cfg = new FileWriter(activity.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE); - cfg.write(getConfigFile(activity.getCacheDir())); + FileWriter cfg = new FileWriter(context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE); + cfg.write(getConfigFile(context.getCacheDir())); cfg.flush(); cfg.close(); } catch (IOException e) { @@ -386,7 +410,7 @@ public class VpnProfile implements Serializable{ public String getTemporaryPKCS12Password() { if(mTempPKCS12Password!=null) return mTempPKCS12Password; - + String pw= ""; // Put enough digits togher to make a password :) Random r = new Random(); @@ -439,7 +463,7 @@ public class VpnProfile implements Serializable{ if(!mUsePull) { if(mIPv4Address == null || cidrToIPAndNetmask(mIPv4Address) == null) return R.string.ipv4_format_error; - + } if(!mUseDefaultRoute && getCustomRoutes()==null) return R.string.custom_route_format_error; @@ -453,15 +477,17 @@ public class VpnProfile implements Serializable{ // public String getPasswordPrivateKey() { if(mTransientPW!=null) { - return mTransientPW; + String pwcopy = mTransientPW; + mTransientPW=null; + return pwcopy; } switch (mAuthenticationType) { case TYPE_KEYSTORE: return getTemporaryPKCS12Password(); - + case TYPE_PKCS12: return mPKCS12Password; - + case TYPE_USERPASS: case TYPE_STATICKEYS: case TYPE_CERTIFICATES: @@ -485,13 +511,16 @@ public class VpnProfile implements Serializable{ } public String getPasswordAuth() { - if(mTransientPW!=null) - return mTransientPW; - else + if(mTransientPW!=null) { + String pwcopy = mTransientPW; + mTransientPW=null; + return pwcopy; + } else { return mPassword; + } } - + } |