|
|
@@ -136,6 +136,7 @@ public class PsiphonVpn extends Psi.PsiphonProvider.Stub {
|
|
|
private final static String VPN_INTERFACE_NETMASK = "255.255.255.0";
|
|
|
private final static int VPN_INTERFACE_MTU = 1500;
|
|
|
private final static int UDPGW_SERVER_PORT = 7300;
|
|
|
+ private final static String DEFAULT_DNS_SERVER = "8.8.4.4";
|
|
|
|
|
|
private boolean startVpn() throws Exception {
|
|
|
|
|
|
@@ -237,6 +238,18 @@ public class PsiphonVpn extends Psi.PsiphonProvider.Stub {
|
|
|
return hasNetworkConnectivity(mHostService.getVpnService()) ? 1 : 0;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String GetDnsServer() {
|
|
|
+ String dnsResolver = null;
|
|
|
+ try {
|
|
|
+ dnsResolver = getFirstActiveNetworkDnsResolver(mHostService.getVpnService());
|
|
|
+ } catch (Exception e) {
|
|
|
+ mHostService.logWarning("failed to get active network DNS resolver: " + e.getMessage());
|
|
|
+ dnsResolver = DEFAULT_DNS_SERVER;
|
|
|
+ }
|
|
|
+ return dnsResolver;
|
|
|
+ }
|
|
|
+
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
// Psiphon Tunnel Core
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
@@ -264,26 +277,12 @@ public class PsiphonVpn extends Psi.PsiphonProvider.Stub {
|
|
|
private String loadPsiphonConfig(Context context)
|
|
|
throws IOException, JSONException {
|
|
|
|
|
|
- // If we can obtain a DNS resolver for the active network,
|
|
|
- // prefer that for DNS resolution in BindToDevice mode.
|
|
|
- String dnsResolver = null;
|
|
|
- try {
|
|
|
- dnsResolver = getFirstActiveNetworkDnsResolver(context);
|
|
|
- } catch (Exception e) {
|
|
|
- mHostService.logWarning("failed to get active network DNS resolver: " + e.getMessage());
|
|
|
- // Proceed with default value in config file
|
|
|
- }
|
|
|
-
|
|
|
// Load settings from the raw resource JSON config file and
|
|
|
// update as necessary. Then write JSON to disk for the Go client.
|
|
|
JSONObject json = new JSONObject(
|
|
|
readInputStreamToString(
|
|
|
mHostService.getPsiphonConfigResource()));
|
|
|
|
|
|
- if (dnsResolver != null) {
|
|
|
- json.put("BindToDeviceDnsServer", dnsResolver);
|
|
|
- }
|
|
|
-
|
|
|
// On Android, these directories must be set to the app private storage area.
|
|
|
// The Psiphon library won't be able to use its current working directory
|
|
|
// and the standard temporary directories do not exist.
|
|
|
@@ -419,7 +418,7 @@ public class PsiphonVpn extends Psi.PsiphonProvider.Stub {
|
|
|
// which private address range isn't in use.
|
|
|
|
|
|
Map<String, PrivateAddress> candidates = new HashMap<String, PrivateAddress>();
|
|
|
- candidates.put("10", new PrivateAddress("10.0.0.1", "10.0.0.0", 8, "10.0.0.2"));
|
|
|
+ candidates.put( "10", new PrivateAddress("10.0.0.1", "10.0.0.0", 8, "10.0.0.2"));
|
|
|
candidates.put("172", new PrivateAddress("172.16.0.1", "172.16.0.0", 12, "172.16.0.2"));
|
|
|
candidates.put("192", new PrivateAddress("192.168.0.1", "192.168.0.0", 16, "192.168.0.2"));
|
|
|
candidates.put("169", new PrivateAddress("169.254.1.1", "169.254.1.0", 24, "169.254.1.2"));
|
|
|
@@ -486,16 +485,18 @@ public class PsiphonVpn extends Psi.PsiphonProvider.Stub {
|
|
|
Class<?> LinkPropertiesClass = Class.forName("android.net.LinkProperties");
|
|
|
Method getActiveLinkPropertiesMethod = ConnectivityManager.class.getMethod("getActiveLinkProperties", new Class []{});
|
|
|
Object linkProperties = getActiveLinkPropertiesMethod.invoke(connectivityManager);
|
|
|
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- Method getDnsesMethod = LinkPropertiesClass.getMethod("getDnses", new Class []{});
|
|
|
- Collection<?> dnses = (Collection<?>)getDnsesMethod.invoke(linkProperties);
|
|
|
- for (Object dns : dnses) {
|
|
|
- dnsAddresses.add((InetAddress)dns);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // LinkProperties is public in API 21 (and the DNS function signature has changed)
|
|
|
- for (InetAddress dns : ((LinkProperties)linkProperties).getDnsServers()) {
|
|
|
- dnsAddresses.add(dns);
|
|
|
+ if (linkProperties != null) {
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ Method getDnsesMethod = LinkPropertiesClass.getMethod("getDnses", new Class []{});
|
|
|
+ Collection<?> dnses = (Collection<?>)getDnsesMethod.invoke(linkProperties);
|
|
|
+ for (Object dns : dnses) {
|
|
|
+ dnsAddresses.add((InetAddress)dns);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // LinkProperties is public in API 21 (and the DNS function signature has changed)
|
|
|
+ for (InetAddress dns : ((LinkProperties)linkProperties).getDnsServers()) {
|
|
|
+ dnsAddresses.add(dns);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (ClassNotFoundException e) {
|