From 488a41cc60636298581c2b44b4706b259fc98a36 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sat, 21 Apr 2012 18:36:35 +0200 Subject: wip --- .hgignore | 4 + AndroidManifest.xml | 5 +- res/drawable-hdpi/ic_sysbar_quicksettings.png | Bin 0 -> 773 bytes res/drawable-mdpi/ic_sysbar_quicksettings.png | Bin 0 -> 653 bytes res/drawable-xhdpi/ic_sysbar_quicksettings.png | Bin 0 -> 956 bytes res/layout/config.xml | 40 ++++++- res/layout/vpn_preference_layout.xml | 94 +++++++++++++++++ res/layout/vpn_preference_widget.xml | 8 ++ res/values/arrays.xml | 2 + res/values/strings.xml | 13 +++ res/xml/vpn_authentification.xml | 11 ++ res/xml/vpn_headers.xml | 46 +++++++++ res/xml/vpn_ipsettings.xml | 53 ++++++++++ res/xml/vpn_obscure.xml | 42 ++++++++ res/xml/vpn_overview.xml | 15 +++ res/xml/vpn_preferences.xml | 7 ++ src/de/blinkt/openvpn/OpenVPNClient.java | 28 +++-- src/de/blinkt/openvpn/OpenVpnService.java | 23 ++++- src/de/blinkt/openvpn/VPNConfigPreference.java | 15 +++ src/de/blinkt/openvpn/VPNPreferences.java | 138 +++++++++++++++++++++++++ src/de/blinkt/openvpn/VPNProfileList.java | 22 ++++ src/de/blinkt/openvpn/VpnProfile.java | 4 +- 22 files changed, 559 insertions(+), 11 deletions(-) create mode 100644 .hgignore create mode 100644 res/drawable-hdpi/ic_sysbar_quicksettings.png create mode 100644 res/drawable-mdpi/ic_sysbar_quicksettings.png create mode 100644 res/drawable-xhdpi/ic_sysbar_quicksettings.png create mode 100644 res/layout/vpn_preference_layout.xml create mode 100644 res/layout/vpn_preference_widget.xml create mode 100644 res/xml/vpn_authentification.xml create mode 100644 res/xml/vpn_headers.xml create mode 100644 res/xml/vpn_ipsettings.xml create mode 100644 res/xml/vpn_obscure.xml create mode 100644 res/xml/vpn_overview.xml create mode 100644 res/xml/vpn_preferences.xml create mode 100644 src/de/blinkt/openvpn/VPNConfigPreference.java create mode 100644 src/de/blinkt/openvpn/VPNPreferences.java create mode 100644 src/de/blinkt/openvpn/VPNProfileList.java diff --git a/.hgignore b/.hgignore new file mode 100644 index 00000000..154c2a9b --- /dev/null +++ b/.hgignore @@ -0,0 +1,4 @@ +obj +bin +libs +gen \ No newline at end of file diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f25a1b62..24c8f164 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -17,8 +17,8 @@ + android:versionCode="8" + android:versionName="0.0.4" > @@ -34,6 +34,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/vpn_preference_widget.xml b/res/layout/vpn_preference_widget.xml new file mode 100644 index 00000000..fef23003 --- /dev/null +++ b/res/layout/vpn_preference_widget.xml @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 52e3afd8..eb2c1b1c 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -4,6 +4,8 @@ Certificates PKCS12 File Android Certficate + Username/Password + Static Keys diff --git a/res/values/strings.xml b/res/values/strings.xml index 4e191d8a..a9c1b1dc 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -80,6 +80,19 @@ Show advanced settings Use TLS Authentication TLS Direction + VPN List + Add OpenVPN Config + Saved VPN Configs + + Enter IPv6 Address/Netmask in CIDR Format (e.g. 2000:dd::23/64) + Enter IPv4 Address/Netmask in CIDR Format (e.g. 1.2.3.4/24) + IPv4 Address + IPv6 Address + Enter custom OpenVPN. Use with great care. Also note that many of the tun related Openvpn settings cannot be supported by design of the VPNSettings. If you think an important option is missing contact the author + Username + Password + For the static configuration the TLS Auth Keys will be used as static keys. + Configure the VPN diff --git a/res/xml/vpn_authentification.xml b/res/xml/vpn_authentification.xml new file mode 100644 index 00000000..11ea3abe --- /dev/null +++ b/res/xml/vpn_authentification.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/res/xml/vpn_headers.xml b/res/xml/vpn_headers.xml new file mode 100644 index 00000000..7d0ade3f --- /dev/null +++ b/res/xml/vpn_headers.xml @@ -0,0 +1,46 @@ + + + +
+ android:title="Basic Setting" + +
+ +
+ +
+ + + +
+ + + +
+ + +
+ +
+ + \ No newline at end of file diff --git a/res/xml/vpn_ipsettings.xml b/res/xml/vpn_ipsettings.xml new file mode 100644 index 00000000..8aacaaca --- /dev/null +++ b/res/xml/vpn_ipsettings.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/xml/vpn_obscure.xml b/res/xml/vpn_obscure.xml new file mode 100644 index 00000000..09b237f2 --- /dev/null +++ b/res/xml/vpn_obscure.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + android:key="customOptions" + android:title="Custom Options" /> + + \ No newline at end of file diff --git a/res/xml/vpn_overview.xml b/res/xml/vpn_overview.xml new file mode 100644 index 00000000..053f2526 --- /dev/null +++ b/res/xml/vpn_overview.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/res/xml/vpn_preferences.xml b/res/xml/vpn_preferences.xml new file mode 100644 index 00000000..16c330c0 --- /dev/null +++ b/res/xml/vpn_preferences.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/de/blinkt/openvpn/OpenVPNClient.java b/src/de/blinkt/openvpn/OpenVPNClient.java index 27073459..f1a32b63 100644 --- a/src/de/blinkt/openvpn/OpenVPNClient.java +++ b/src/de/blinkt/openvpn/OpenVPNClient.java @@ -52,6 +52,7 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; import android.widget.ToggleButton; @@ -103,6 +104,12 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI private Spinner mTLSDirection; + + private EditText mUserName; + + + private EditText mPassword; + @Override protected void onStop(){ super.onStop(); @@ -264,7 +271,8 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI mShowAdvanced = (CheckBox) findViewById(R.id.show_advanced); mTlsFile = (FileSelectLayout) findViewById(R.id.tlsAuth); - + mUserName = (EditText) findViewById(R.id.auth_username); + mPassword = (EditText) findViewById(R.id.auth_password); addFileSelectLayout(mCaCert); @@ -304,7 +312,7 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI // hide everything findViewById(R.id.pkcs12).setVisibility(View.GONE); findViewById(R.id.certs).setVisibility(View.GONE); - findViewById(R.id.commonsecret).setVisibility(View.GONE); + findViewById(R.id.statickeys).setVisibility(View.GONE); findViewById(R.id.keystore).setVisibility(View.GONE); switch(type) { @@ -314,12 +322,15 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI case VpnProfile.TYPE_PKCS12: findViewById(R.id.pkcs12).setVisibility(View.VISIBLE); break; - case VpnProfile.COMMON_SECRET: - findViewById(R.id.commonsecret).setVisibility(View.VISIBLE); + case VpnProfile.TYPE_STATICKEYS: + findViewById(R.id.statickeys).setVisibility(View.VISIBLE); break; case VpnProfile.TYPE_KEYSTORE: findViewById(R.id.keystore).setVisibility(View.VISIBLE); break; + + case VpnProfile.TYPE_USERPASS: + findViewById(R.id.userpassword).setVisibility(View.VISIBLE); } @@ -477,7 +488,8 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI onActivityResult(START_OPENVPN, RESULT_OK, null); } } else if (v == findViewById(R.id.about)) { - Intent intent = new Intent(getBaseContext(),AboutActivity.class); + //Intent intent = new Intent(getBaseContext(),AboutActivity.class); + Intent intent = new Intent(getBaseContext(),VPNPreferences.class); startActivity(intent); } else if (v == findViewById(R.id.select_keystore_button)) { showCertDialog(); @@ -500,7 +512,11 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI String pkcs12pw = savePKCS12(); intent.putExtra(prefix + ".PKCS12PASS", pkcs12pw); } - + + if(mType.getSelectedItemPosition() == VpnProfile.TYPE_USERPASS) { + intent.putExtra(prefix + ".USERNAME", mUserName.getText().toString()); + intent.putExtra(prefix + ".PASSWORD", mPassword.getText().toString()); + } startService(intent); Intent startLW = new Intent(getBaseContext(),LogWindow.class); diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index e8174bcb..4aad9318 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -117,13 +117,34 @@ public class OpenVpnService extends VpnService implements Handler.Callback, Runn } } + if(intent.hasExtra(prefix +".USERNAME")) + { + try { + String user = managmentEscape(intent.getStringExtra(prefix +".USERNAME")); + String pw = managmentEscape(intent.getStringExtra(prefix +".PASSWORD")); + Thread.sleep(3000); + + + managmentCommand("username 'Auth' " + user+ "\n" + + "password 'Auth' " + pw + "\n"); + } catch (InterruptedException e) { + } + } return START_STICKY; } - @Override + private String managmentEscape(String unescape) { + String escapedString = unescape.replace("\\", "\\\\"); + escapedString = escapedString.replace("\"","\\\""); + escapedString = escapedString.replace("\n","\\n"); + return '"' + escapedString + '"'; + } + + + @Override public void onDestroy() { if (mThread != null) { managmentCommand("signal SIGINT\n"); diff --git a/src/de/blinkt/openvpn/VPNConfigPreference.java b/src/de/blinkt/openvpn/VPNConfigPreference.java new file mode 100644 index 00000000..3afcfccb --- /dev/null +++ b/src/de/blinkt/openvpn/VPNConfigPreference.java @@ -0,0 +1,15 @@ +package de.blinkt.openvpn; + +import android.content.Context; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.util.AttributeSet; + +public class VPNConfigPreference extends Preference { + + public VPNConfigPreference(Context context, AttributeSet attrs) { + super(context, attrs); + setWidgetLayoutResource(R.layout.vpn_preference_layout); + } + +} diff --git a/src/de/blinkt/openvpn/VPNPreferences.java b/src/de/blinkt/openvpn/VPNPreferences.java new file mode 100644 index 00000000..69485efd --- /dev/null +++ b/src/de/blinkt/openvpn/VPNPreferences.java @@ -0,0 +1,138 @@ +package de.blinkt.openvpn; + +import java.util.List; + +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; +import android.preference.SwitchPreference; +import android.widget.Button; + + +public class VPNPreferences extends PreferenceActivity { + + public VPNPreferences() { + super(); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (hasHeaders()) { + Button button = new Button(this); + button.setText("Some action"); + setListFooter(button); + } + } + @Override + public void onBuildHeaders(List
target) { + loadHeadersFromResource(R.xml.vpn_headers, target); + } + + public static class IP_Settings extends PreferenceFragment implements OnPreferenceChangeListener { + private EditTextPreference mIPv4; + private EditTextPreference mIPv6; + private SwitchPreference mUsePull; + private CheckBoxPreference mOverrideDNS; + private Preference mSearchdomain; + private Preference mDNS1; + private Preference mDNS2; + + @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_ipsettings); + mIPv4 = (EditTextPreference) findPreference("ipv4_address"); + mIPv6 = (EditTextPreference) findPreference("ipv6_address"); + mUsePull = (SwitchPreference) findPreference("usePull"); + mOverrideDNS = (CheckBoxPreference) findPreference("overrideDNS"); + mSearchdomain =findPreference("searchdomain"); + mDNS1 = findPreference("dns1"); + mDNS2 = findPreference("dns2"); + + mIPv4.setOnPreferenceChangeListener(this); + mIPv6.setOnPreferenceChangeListener(this); + mDNS1.setOnPreferenceChangeListener(this); + mDNS2.setOnPreferenceChangeListener(this); + mUsePull.setOnPreferenceChangeListener(this); + mOverrideDNS.setOnPreferenceChangeListener(this); + setDNSState(); + + } + + @Override + public boolean onPreferenceChange(Preference preference, + Object newValue) { + if(preference==mIPv4 || preference == mIPv6 || + preference==mDNS1 || preference == mDNS2) + preference.setSummary((String)newValue); + + if(preference== mUsePull || preference == mOverrideDNS) + setDNSState(); + + return true; + } + + private void setDNSState() { + boolean enabled; + mOverrideDNS.setEnabled(mUsePull.isChecked()); + if(!mUsePull.isChecked()) + enabled =true; + else if (mOverrideDNS.isChecked()) + enabled = true; + else + enabled = false; + + mDNS1.setEnabled(enabled); + mDNS2.setEnabled(enabled); + mSearchdomain.setEnabled(enabled); + + } + + + } + public static class Authentication extends PreferenceFragment { + @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_authentification, false); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.vpn_authentification); + } + } + public static class Obscure extends PreferenceFragment { + @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); + } + } +} + diff --git a/src/de/blinkt/openvpn/VPNProfileList.java b/src/de/blinkt/openvpn/VPNProfileList.java new file mode 100644 index 00000000..fb7af280 --- /dev/null +++ b/src/de/blinkt/openvpn/VPNProfileList.java @@ -0,0 +1,22 @@ +package de.blinkt.openvpn; + +import android.os.Bundle; +import android.preference.PreferenceActivity; + + +import android.app.ProfileManager; + +public class VPNProfileList extends PreferenceActivity { + private ProfileManager mProfileManager; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (getPreferenceManager() != null) { + addPreferencesFromResource(R.xml.profiles_settings); + mProfileManager = (ProfileManager) getActivity().getSystemService(PROFILE_SERVICE); + + } + } +} diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index d01b1104..8d5fbe32 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -3,6 +3,8 @@ package de.blinkt.openvpn; public class VpnProfile { static final int TYPE_CERTIFICATES=0; static final int TYPE_PKCS12=1; - static final int COMMON_SECRET=3; static final int TYPE_KEYSTORE=2; + public static final int TYPE_USERPASS = 3; + public static final int TYPE_STATICKEYS = 4; + } -- cgit v1.2.3