summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java157
1 files changed, 76 insertions, 81 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
index 6f260f55..0b9c5832 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2013 LEAP Encryption Access Project and contributers
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -16,16 +16,11 @@
*/
package se.leap.bitmaskclient.eip;
-import android.content.SharedPreferences;
-import android.util.Log;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.*;
-import java.util.Iterator;
+import java.util.*;
-import se.leap.bitmaskclient.Provider;
+import se.leap.bitmaskclient.*;
public class VpnConfigGenerator {
@@ -37,79 +32,79 @@ public class VpnConfigGenerator {
private final String new_line = System.getProperty("line.separator"); // Platform new line
public VpnConfigGenerator(JSONObject general_configuration, JSONObject secrets, JSONObject gateway) {
- this.general_configuration = general_configuration;
- this.gateway = gateway;
+ this.general_configuration = general_configuration;
+ this.gateway = gateway;
this.secrets = secrets;
}
-
+
public String generate() {
- return
- generalConfiguration()
- + new_line
- + gatewayConfiguration()
- + new_line
- + secretsConfiguration()
- + new_line
- + androidCustomizations();
+ return
+ generalConfiguration()
+ + new_line
+ + gatewayConfiguration()
+ + new_line
+ + secretsConfiguration()
+ + new_line
+ + androidCustomizations();
}
private String generalConfiguration() {
- String common_options = "";
- try {
- Iterator keys = general_configuration.keys();
- while ( keys.hasNext() ){
- String key = keys.next().toString();
-
- common_options += key + " ";
- for ( String word : general_configuration.getString(key).split(" ") )
- common_options += word + " ";
- common_options += new_line;
-
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- common_options += "client";
-
- return common_options;
+ String common_options = "";
+ try {
+ Iterator keys = general_configuration.keys();
+ while (keys.hasNext()) {
+ String key = keys.next().toString();
+
+ common_options += key + " ";
+ for (String word : general_configuration.getString(key).split(" "))
+ common_options += word + " ";
+ common_options += new_line;
+
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ common_options += "client";
+
+ return common_options;
}
-
+
private String gatewayConfiguration() {
- String remotes = "";
-
- String ip_address_keyword = "ip_address";
- String remote_keyword = "remote";
- String ports_keyword = "ports";
- String protocol_keyword = "protocols";
- String capabilities_keyword = "capabilities";
- String udp = "udp";
-
- try {
- String ip_address = gateway.getString(ip_address_keyword);
- JSONObject capabilities = gateway.getJSONObject(capabilities_keyword);
- JSONArray ports = capabilities.getJSONArray(ports_keyword);
- for (int i=0; i<ports.length(); i++) {
- String port_specific_remotes = "";
- int port = ports.getInt(i);
- JSONArray protocols = capabilities.getJSONArray(protocol_keyword);
- for ( int j=0; j<protocols.length(); j++ ) {
- String protocol = protocols.optString(j);
- String new_remote = remote_keyword + " " + ip_address + " " + port + " " + protocol + new_line;
-
- port_specific_remotes = protocol.equalsIgnoreCase(udp) ?
- port_specific_remotes.replaceFirst(remote_keyword, new_remote + new_line + remote_keyword) :
- new_remote;
- }
- remotes += port_specific_remotes;
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return remotes;
+ String remotes = "";
+
+ String ip_address_keyword = "ip_address";
+ String remote_keyword = "remote";
+ String ports_keyword = "ports";
+ String protocol_keyword = "protocols";
+ String capabilities_keyword = "capabilities";
+ String udp = "udp";
+
+ try {
+ String ip_address = gateway.getString(ip_address_keyword);
+ JSONObject capabilities = gateway.getJSONObject(capabilities_keyword);
+ JSONArray ports = capabilities.getJSONArray(ports_keyword);
+ for (int i = 0; i < ports.length(); i++) {
+ String port_specific_remotes = "";
+ int port = ports.getInt(i);
+ JSONArray protocols = capabilities.getJSONArray(protocol_keyword);
+ for (int j = 0; j < protocols.length(); j++) {
+ String protocol = protocols.optString(j);
+ String new_remote = remote_keyword + " " + ip_address + " " + port + " " + protocol + new_line;
+
+ port_specific_remotes = protocol.equalsIgnoreCase(udp) ?
+ port_specific_remotes.replaceFirst(remote_keyword, new_remote + new_line + remote_keyword) :
+ new_remote;
+ }
+ remotes += port_specific_remotes;
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return remotes;
}
private String secretsConfiguration() {
@@ -136,18 +131,18 @@ public class VpnConfigGenerator {
+ "</cert>";
return ca + new_line + key + new_line + openvpn_cert;
- } catch(JSONException e) {
+ } catch (JSONException e) {
e.printStackTrace();
return "";
}
}
private String androidCustomizations() {
- return
- "remote-cert-tls server"
- + new_line
- + "persist-tun"
- + new_line
- + "auth-retry nointeract";
+ return
+ "remote-cert-tls server"
+ + new_line
+ + "persist-tun"
+ + new_line
+ + "auth-retry nointeract";
}
}