diff options
author | Parménides GV <parmegv@sdf.org> | 2015-03-19 15:09:08 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2015-03-19 15:09:08 +0100 |
commit | 5ccaa263e3bafd212b8f4f037a87bf0770ee65e3 (patch) | |
tree | 4c5a23dcb1a7bc22ec06faf399756bd4bcb7e817 /app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java | |
parent | f476425c42a08e92ecb0cea99908e9b8d635fa69 (diff) | |
parent | bb2a944265da15eeba35106f2e2bcda288855527 (diff) |
Merge branch 'feature/Warn-users-about-browser-and-vpn-inconsistency-#6783' into develop
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.java | 144 |
1 files changed, 72 insertions, 72 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..5f5dcabd 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 @@ -37,79 +37,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() { @@ -143,11 +143,11 @@ public class VpnConfigGenerator { } 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"; } } |