summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/de/blinkt/openvpn/core/ConfigParser.java')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/ConfigParser.java82
1 files changed, 52 insertions, 30 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/ConfigParser.java b/app/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
index 232c454b..d14e643e 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2014 Arne Schwabe
+ * Copyright (c) 2012-2016 Arne Schwabe
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
*/
@@ -32,11 +32,11 @@ public class ConfigParser {
private HashMap<String, Vector<Vector<String>>> options = new HashMap<String, Vector<Vector<String>>>();
private HashMap<String, Vector<String>> meta = new HashMap<String, Vector<String>>();
private String auth_user_pass_file;
- private String crl_verify_file;
-
public void parseConfig(Reader reader) throws IOException, ConfigParseError {
+ HashMap<String, String> optionAliases = new HashMap<>();
+ optionAliases.put("server-poll-timeout", "timeout-connect");
BufferedReader br = new BufferedReader(reader);
@@ -48,9 +48,15 @@ public class ConfigParser {
if (line == null)
break;
- if (lineno == 1 && (line.startsWith("PK\003\004")
- || (line.startsWith("PK\007\008"))))
- throw new ConfigParseError("Input looks like a ZIP Archive. Import is only possible for OpenVPN config files (.ovpn/.conf)");
+ if (lineno == 1) {
+ if ((line.startsWith("PK\003\004")
+ || (line.startsWith("PK\007\008")))) {
+ throw new ConfigParseError("Input looks like a ZIP Archive. Import is only possible for OpenVPN config files (.ovpn/.conf)");
+ }
+ if (line.startsWith("\uFEFF")) {
+ line = line.substring(1);
+ }
+ }
// Check for OpenVPN Access Server Meta information
if (line.startsWith("# OVPN_ACCESS_SERVER_")) {
@@ -70,6 +76,9 @@ public class ConfigParser {
checkinlinefile(args, br);
String optionname = args.get(0);
+ if (optionAliases.get(optionname)!=null)
+ optionname = optionAliases.get(optionname);
+
if (!options.containsKey(optionname)) {
options.put(optionname, new Vector<Vector<String>>());
}
@@ -121,10 +130,6 @@ public class ConfigParser {
return auth_user_pass_file;
}
- public String getCrlVerifyFile() {
- return crl_verify_file;
- }
-
enum linestate {
initial,
readin_single_quote, reading_quoted, reading_unquoted, done
@@ -137,7 +142,7 @@ public class ConfigParser {
}
- public class ConfigParseError extends Exception {
+ public static class ConfigParseError extends Exception {
private static final long serialVersionUID = -60L;
public ConfigParseError(String msg) {
@@ -288,7 +293,8 @@ public class ConfigParser {
{
{"setenv", "IV_GUI_VER"},
{"setenv", "IV_OPENVPN_GUI_VERSION"},
- {"engine", "dynamic"}
+ {"engine", "dynamic"},
+ {"setenv", "CLIENT_CERT"}
};
final String[] connectionOptions = {
@@ -388,6 +394,10 @@ public class ConfigParser {
np.mCustomRoutesv6 = customIPv6Routes;
}
+ Vector<String> routeNoPull = getOption("route-nopull", 1, 1);
+ if (routeNoPull!=null)
+ np.mRoutenopull=true;
+
// Also recognize tls-auth [inline] direction ...
Vector<Vector<String>> tlsauthoptions = getAllOption("tls-auth", 1, 2);
if (tlsauthoptions != null) {
@@ -567,6 +577,9 @@ public class ConfigParser {
if (getOption("persist-tun", 0, 0) != null)
np.mPersistTun = true;
+ if (getOption("push-peer-info", 0, 0) != null)
+ np.mPushPeerInfo = true;
+
Vector<String> connectretry = getOption("connect-retry", 1, 1);
if (connectretry != null)
np.mConnectRetry = connectretry.get(1);
@@ -603,11 +616,12 @@ public class ConfigParser {
Vector<String> crlfile = getOption("crl-verify", 1, 2);
if (crlfile != null) {
// If the 'dir' parameter is present just add it as custom option ..
- np.mCustomConfigOptions += TextUtils.join(" ", crlfile) + "\n";
- if (crlfile.size() == 2) {
+ if (crlfile.size() == 3 && crlfile.get(2).equals("dir"))
+ np.mCustomConfigOptions += TextUtils.join(" ", crlfile) + "\n";
+ else
// Save the filename for the config converter to add later
- crl_verify_file = crlfile.get(1);
- }
+ np.mCrlFilename = crlfile.get(1);
+
}
@@ -709,8 +723,18 @@ public class ConfigParser {
conn.mUseUdp = isUdpProto(proto.get(1));
}
+ Vector<String> connectTimeout = getOption("connect-timeout", 1, 1);
+ if (connectTimeout != null) {
+ try {
+ conn.mConnectTimeout = Integer.parseInt(connectTimeout.get(1));
+ } catch (NumberFormatException nfe) {
+ throw new ConfigParseError(String.format("Argument to connect-timeout (%s) must to be an integer: %s",
+ connectTimeout.get(1), nfe.getLocalizedMessage()));
+
+ }
+ }
- // Parse remote config
+ // Parse remote config
Vector<Vector<String>> remotes = getAllOption("remote", 1, 3);
@@ -785,16 +809,6 @@ public class ConfigParser {
}
}
- public static void removeCRLCustomOption(VpnProfile np) {
- String lines[] = np.mCustomConfigOptions.split("\\r?\\n");
- Vector<String> keeplines = new Vector<>();
- for (String l : lines) {
- if (!l.startsWith("crl-verify "))
- keeplines.add(l);
- }
- np.mCustomConfigOptions = TextUtils.join("\n", keeplines);
- }
-
private void checkIgnoreAndInvalidOptions(VpnProfile np) throws ConfigParseError {
for (String option : unsupportedOptions)
if (options.containsKey(option))
@@ -838,13 +852,21 @@ public class ConfigParser {
return false;
}
+ //! Generate options for custom options
private String getOptionStrings(Vector<Vector<String>> option) {
String custom = "";
for (Vector<String> optionsline : option) {
if (!ignoreThisOption(optionsline)) {
- for (String arg : optionsline)
- custom += VpnProfile.openVpnEscape(arg) + " ";
- custom += "\n";
+ // Check if option had been inlined and inline again
+ if (optionsline.size() == 2 && "extra-certs".equals(optionsline.get(0)) ) {
+ custom += VpnProfile.insertFileData(optionsline.get(0), optionsline.get(1));
+
+
+ } else {
+ for (String arg : optionsline)
+ custom += VpnProfile.openVpnEscape(arg) + " ";
+ custom += "\n";
+ }
}
}
return custom;