From fd72bd2cebbf6cd7bb6f37ea13e6d3398590cde6 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Thu, 18 May 2017 16:50:38 +0200 Subject: Implement tun-mtu and auth-retry in the ui --- .../main/java/de/blinkt/openvpn/VpnProfile.java | 25 +++++++++++++++ .../java/de/blinkt/openvpn/core/ConfigParser.java | 26 ++++++++++++++- .../java/de/blinkt/openvpn/core/VpnStatus.java | 3 +- .../blinkt/openvpn/fragments/Settings_Basic.java | 6 +++- .../blinkt/openvpn/fragments/Settings_Obscure.java | 37 +++++++++++++++++++++- main/src/main/res/layout/basic_settings.xml | 23 ++++++++++++-- main/src/main/res/values/arrays.xml | 5 +++ main/src/main/res/values/strings.xml | 2 ++ main/src/main/res/xml/vpn_obscure.xml | 4 +++ 9 files changed, 125 insertions(+), 6 deletions(-) diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java index ceca611e..14354a8e 100644 --- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -88,6 +88,12 @@ public class VpnProfile implements Serializable, Cloneable { public static final int X509_VERIFY_TLSREMOTE_DN = 2; public static final int X509_VERIFY_TLSREMOTE_RDN = 3; public static final int X509_VERIFY_TLSREMOTE_RDN_PREFIX = 4; + + + public static final int AUTH_RETRY_NONE_FORGET = 0; + private static final int AUTH_RETRY_NONE_KEEP = 1; + public static final int AUTH_RETRY_NOINTERACT = 2; + private static final int AUTH_RETRY_INTERACT = 3; // variable named wrong and should haven beeen transient // but needs to keep wrong name to guarante loading of old // profiles @@ -156,6 +162,9 @@ public class VpnProfile implements Serializable, Cloneable { public String mCrlFilename; public String mProfileCreator; + public int mAuthRetry = AUTH_RETRY_NONE_FORGET; + public int mTunMtu; + public boolean mPushPeerInfo = false; public static final boolean mIsOpenVPN22 = false; @@ -171,6 +180,7 @@ public class VpnProfile implements Serializable, Cloneable { public boolean mUseUdp = true; + public VpnProfile(String name) { mUuid = UUID.randomUUID(); mName = name; @@ -406,6 +416,12 @@ public class VpnProfile implements Serializable, Cloneable { cfg += insertFileData("ca", mCaFilename); } + if (isUserPWAuth()) + { + if (mAuthenticationType == AUTH_RETRY_NOINTERACT) + cfg += "auth-retry nointeract"; + } + if (!TextUtils.isEmpty(mCrlFilename)) cfg += insertFileData("crl-verify", mCrlFilename); @@ -489,6 +505,11 @@ public class VpnProfile implements Serializable, Cloneable { cfg += "mssfix\n"; } + if (mTunMtu >= 48 && mTunMtu != 1500) + { + cfg+= String.format(Locale.US, "tun-mtu %d\n", mTunMtu); + } + if (mNobind) cfg += "nobind\n"; @@ -764,6 +785,10 @@ public class VpnProfile implements Serializable, Cloneable { } } + public void pwDidFail(Context c) { + + } + class NoCertReturnedException extends Exception { public NoCertReturnedException(String msg) { diff --git a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java index 42217e52..ce490c31 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java @@ -328,7 +328,6 @@ public class ConfigParser { "socks-proxy", "socks-proxy-retry", "explicit-exit-notify", - "mssfix" }; @@ -465,6 +464,18 @@ public class ConfigParser { } + Vector tunmtu = getOption("mtu", 1, 1); + + if (tunmtu != null) { + try { + np.mTunMtu = Integer.parseInt(tunmtu.get(1)); + } catch (NumberFormatException e) { + throw new ConfigParseError("Argument to --tun-mtu has to be an integer"); + } + } + + + Vector mode = getOption("mode", 1, 1); if (mode != null) { if (!mode.get(1).equals("p2p")) @@ -635,6 +646,19 @@ public class ConfigParser { } } + Vector authretry = getOption("auth-retry", 1, 1); + if (authretry != null) { + if (authretry.get(1).equals("none")) + np.mAuthRetry = VpnProfile.AUTH_RETRY_NONE_FORGET; + else if (authretry.get(1).equals("nointeract")) + np.mAuthRetry = VpnProfile.AUTH_RETRY_NOINTERACT; + else if (authretry.get(1).equals("interact")) + np.mAuthRetry = VpnProfile.AUTH_RETRY_NOINTERACT; + else + throw new ConfigParseError("Unknown parameter to auth-retry: " + authretry.get(2)); + } + + Vector crlfile = getOption("crl-verify", 1, 2); if (crlfile != null) { // If the 'dir' parameter is present just add it as custom option .. diff --git a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java index 0c250ad1..c1f8a736 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -125,7 +125,8 @@ public class VpnStatus { } public static void flushLog() { - mLogFileHandler.sendEmptyMessage(LogFileHandler.FLUSH_TO_DISK); + if (mLogFileHandler!=null) + mLogFileHandler.sendEmptyMessage(LogFileHandler.FLUSH_TO_DISK); } public static void setConnectedVPNProfile(String uuid) { diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java index ea8768d3..c85dc114 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java @@ -61,9 +61,10 @@ public class Settings_Basic extends Settings_Fragment implements View.OnClickLis private EditText mKeyPassword; private SparseArray fileselects = new SparseArray<>(); + private Spinner mAuthRetry; - private void addFileSelectLayout (FileSelectLayout fsl, Utils.FileType type) { + private void addFileSelectLayout (FileSelectLayout fsl, Utils.FileType type) { int i = fileselects.size() + CHOOSE_FILE_OFFSET; fileselects.put(i, fsl); fsl.setCaller(this, i, type); @@ -136,6 +137,7 @@ public class Settings_Basic extends Settings_Fragment implements View.OnClickLis mUserName = (EditText) mView.findViewById(R.id.auth_username); mPassword = (EditText) mView.findViewById(R.id.auth_password); mKeyPassword = (EditText) mView.findViewById(R.id.key_password); + mAuthRetry = (Spinner) mView.findViewById(id.auth_retry); addFileSelectLayout(mCaCert, Utils.FileType.CA_CERTIFICATE); addFileSelectLayout(mClientCert, Utils.FileType.CLIENT_CERTIFICATE); @@ -145,6 +147,7 @@ public class Settings_Basic extends Settings_Fragment implements View.OnClickLis mCaCert.setShowClear(); mType.setOnItemSelectedListener(this); + mAuthRetry.setOnItemSelectedListener(this); mView.findViewById(R.id.select_keystore_button).setOnClickListener(this); @@ -276,6 +279,7 @@ public class Settings_Basic extends Settings_Fragment implements View.OnClickLis mProfile.mPassword = mPassword.getText().toString(); mProfile.mUsername = mUserName.getText().toString(); mProfile.mKeyPassword = mKeyPassword.getText().toString(); + mProfile.mAuthRetry = mAuthRetry.getSelectedItemPosition(); } diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java index 66e20822..5c70564e 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java @@ -13,6 +13,8 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.widget.Toast; +import java.util.Locale; + import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; @@ -29,6 +31,7 @@ public class Settings_Obscure extends OpenVpnPreferencesFragment implements OnPr private ListPreference mConnectRetrymax; private EditTextPreference mConnectRetry; private EditTextPreference mConnectRetryMaxTime; + private EditTextPreference mTunMtu; public void onCreateBehaviour(Bundle savedInstanceState) { @@ -115,6 +118,9 @@ public class Settings_Obscure extends OpenVpnPreferencesFragment implements OnPr mMssFixCheckBox = (CheckBoxPreference) findPreference("mssFix"); mMssFixValue = (EditTextPreference) findPreference("mssFixValue"); mMssFixValue.setOnPreferenceChangeListener(this); + mTunMtu = (EditTextPreference) findPreference("tunmtu"); + mTunMtu.setOnPreferenceChangeListener(this);; + onCreateBehaviour(savedInstanceState); loadSettings(); @@ -135,12 +141,29 @@ public class Settings_Obscure extends OpenVpnPreferencesFragment implements OnPr mMssFixCheckBox.setChecked(true); setMssSummary(mProfile.mMssFix); } + + + int tunmtu = mProfile.mTunMtu; + if (mProfile.mTunMtu < 48) + tunmtu = 1500; + + mTunMtu.setText(String.valueOf(tunmtu)); + setMtuSummary(tunmtu); + + loadSettingsBehaviour(); } private void setMssSummary(int value) { - mMssFixValue.setSummary(String.format("Configured MSS value: %d", value)); + mMssFixValue.setSummary(String.format(Locale.getDefault(),"Configured MSS value: %d", value)); + } + + private void setMtuSummary(int value) { + if (value == 1500) + mTunMtu.setSummary(String.format(Locale.getDefault(),"Using default (1500) MTU", value)); + else + mTunMtu.setSummary(String.format(Locale.getDefault(),"Configured MTU value: %d", value)); } protected void saveSettings() { @@ -153,6 +176,7 @@ public class Settings_Obscure extends OpenVpnPreferencesFragment implements OnPr else mProfile.mMssFix=0; + mProfile.mTunMtu = Integer.parseInt(mTunMtu.getText()); saveSettingsBehaviour(); } @@ -170,6 +194,17 @@ public class Settings_Obscure extends OpenVpnPreferencesFragment implements OnPr Toast.makeText(getActivity(), R.string.mssfix_invalid_value, Toast.LENGTH_LONG).show(); return false; } + else if (preference.getKey().equals("tunmtu")) + try { + int v = Integer.parseInt((String) newValue); + if (v < 48 || v > 9000) + throw new NumberFormatException("mtu value"); + setMtuSummary(v); + + } catch(NumberFormatException e) { + Toast.makeText(getActivity(), R.string.mtu_invalid_value, Toast.LENGTH_LONG).show(); + return false; + } return onPreferenceChangeBehaviour(preference, newValue); } diff --git a/main/src/main/res/layout/basic_settings.xml b/main/src/main/res/layout/basic_settings.xml index 94963d9e..862f54b1 100644 --- a/main/src/main/res/layout/basic_settings.xml +++ b/main/src/main/res/layout/basic_settings.xml @@ -52,7 +52,7 @@ android:layout_height="wrap_content" android:orientation="vertical" android:visibility="gone" - tools:visibility="visible"> + tools:visibility="gone"> @@ -105,7 +105,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:visibility="gone" > + android:visibility="gone" + tools:visibility="visible"> + + + + + Fifty reconnection retries Unlimited reconnection retries + + Disconnect, forget password + Disconnect, keep password + Ignore, retry + diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index 8ec27578..69ddadd4 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -321,6 +321,7 @@ Import log: Vpn topology \"%3$s\" specified but ifconfig %1$s %2$s looks more like an IP address with a network mask. Assuming \"subnet\" topology. The MSS override value has to be a integer between 0 and 9000 + The MTU override value has to be a integer between 64 and 9000 Announce to TCP sessions running over the tunnel that they should limit their send packet sizes such that after OpenVPN has encapsulated them, the resulting UDP packet size that OpenVPN sends to its peer will not exceed this number of bytes. (default is 1450) Override MSS value of TCP payload Set MSS of TCP payload @@ -422,5 +423,6 @@ Profiles sorted by last recently used Profiles sorted by name Config uses option tls-remote that was deprecated in 2.3 and finally removed in 2.4 + Behaviour on AUTH_FAILED diff --git a/main/src/main/res/xml/vpn_obscure.xml b/main/src/main/res/xml/vpn_obscure.xml index 0dc91ce7..aa78050e 100644 --- a/main/src/main/res/xml/vpn_obscure.xml +++ b/main/src/main/res/xml/vpn_obscure.xml @@ -41,6 +41,10 @@ android:key="mssFixValue" android:persistent="false" android:title="@string/mssfix_dialogtitle" /> +