summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2017-05-18 16:50:38 +0200
committerArne Schwabe <arne@rfc2549.org>2017-05-18 16:50:38 +0200
commitfd72bd2cebbf6cd7bb6f37ea13e6d3398590cde6 (patch)
tree62244e144705782f21eec4c09baa20108552e393 /main
parent997b8b2072d9ca3b2c3bd7f6d67fe52065e2eecd (diff)
Implement tun-mtu and auth-retry in the ui
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java25
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java26
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java3
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java6
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java37
-rw-r--r--main/src/main/res/layout/basic_settings.xml23
-rw-r--r--main/src/main/res/values/arrays.xml5
-rwxr-xr-xmain/src/main/res/values/strings.xml2
-rw-r--r--main/src/main/res/xml/vpn_obscure.xml4
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<String> 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<String> mode = getOption("mode", 1, 1);
if (mode != null) {
if (!mode.get(1).equals("p2p"))
@@ -635,6 +646,19 @@ public class ConfigParser {
}
}
+ Vector<String> 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<String> 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<FileSelectLayout> 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">
<include layout="@layout/keystore_selector" />
@@ -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">
<TextView
style="@style/item"
@@ -159,6 +160,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
+ tools:visibility="visible"
android:visibility="gone" >
<TextView
@@ -189,6 +191,23 @@
android:layout_marginRight="8dip"
android:hint="@string/pw_query_hint"
android:inputType="textPassword" />
+
+ <TextView
+ style="@style/item"
+ android:layout_marginLeft="8dip"
+ android:layout_marginRight="8dip"
+ android:text="@string/auth_failed_behaviour"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ <Spinner
+ android:id="@+id/auth_retry"
+ style="@style/item"
+ android:layout_marginLeft="8dip"
+ android:layout_marginRight="8dip"
+ android:prompt="@string/auth_failed_behaviour"
+ android:entries="@array/auth_retry_type"
+ />
+
</LinearLayout>
<LinearLayout
diff --git a/main/src/main/res/values/arrays.xml b/main/src/main/res/values/arrays.xml
index b8cfa7a1..bbb77fe1 100644
--- a/main/src/main/res/values/arrays.xml
+++ b/main/src/main/res/values/arrays.xml
@@ -29,4 +29,9 @@
<item>Fifty reconnection retries</item>
<item>Unlimited reconnection retries</item>
</string-array>
+ <string-array name="auth_retry_type">
+ <item>Disconnect, forget password</item>
+ <item>Disconnect, keep password</item>
+ <item>Ignore, retry</item>
+ </string-array>
</resources>
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 @@
<string name="import_log">Import log:</string>
<string name="ip_looks_like_subnet">Vpn topology \"%3$s\" specified but ifconfig %1$s %2$s looks more like an IP address with a network mask. Assuming \"subnet\" topology.</string>
<string name="mssfix_invalid_value">The MSS override value has to be a integer between 0 and 9000</string>
+ <string name="mtu_invalid_value">The MTU override value has to be a integer between 64 and 9000</string>
<string name="mssfix_value_dialog">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)</string>
<string name="mssfix_checkbox">Override MSS value of TCP payload</string>
<string name="mssfix_dialogtitle">Set MSS of TCP payload</string>
@@ -422,5 +423,6 @@
<string name="sorted_lru">Profiles sorted by last recently used</string>
<string name="sorted_az">Profiles sorted by name</string>
<string name="deprecated_tls_remote">Config uses option tls-remote that was deprecated in 2.3 and finally removed in 2.4</string>
+ <string name="auth_failed_behaviour">Behaviour on AUTH_FAILED</string>
</resources>
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" />
+ <EditTextPreference
+ android:key="tunmtu"
+ android:persistent="false"
+ android:title="Tunnel MTU (tun-mtu)"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/custom_config_title">
<CheckBoxPreference