Skip to content

Commit

Permalink
Leave second DNS empty when importing config with only one DNS (closes
Browse files Browse the repository at this point in the history
…#1410)

When importing a configuration with only one DNS server, the second
DNS server what never overwritten, resulting in having the Google DNS
as backup server. Also change Google DNS to Quad9 by default.
  • Loading branch information
schwabe committed Oct 24, 2021
1 parent 7fb58f6 commit 86582ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions main/src/main/java/de/blinkt/openvpn/VpnProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public class VpnProfile implements Serializable, Cloneable {
private static final int AUTH_RETRY_NONE_KEEP = 1;
private static final int AUTH_RETRY_INTERACT = 3;
private static final String EXTRA_RSA_PADDING_TYPE = "de.blinkt.openvpn.api.RSA_PADDING_TYPE";
public static String DEFAULT_DNS1 = "8.8.8.8";
public static String DEFAULT_DNS2 = "8.8.4.4";
public static String DEFAULT_DNS1 = "9.9.9.9";
public static String DEFAULT_DNS2 = "2620:fe::fe\n";
// variable named wrong and should haven beeen transient
// but needs to keep wrong name to guarante loading of old
// profiles
Expand Down
4 changes: 3 additions & 1 deletion main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,10 @@ public VpnProfile convertProfile() throws ConfigParseError, IOException {
np.mSearchDomain = dhcpoption.get(2);
} else if (type.equals("DNS")) {
np.mOverrideDNS = true;
if (np.mDNS1.equals(VpnProfile.DEFAULT_DNS1))
if (np.mDNS1.equals(VpnProfile.DEFAULT_DNS1)) {
np.mDNS1 = arg;
np.mDNS2 = "";
}
else
np.mDNS2 = arg;
}
Expand Down
19 changes: 19 additions & 0 deletions main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ class TestConfigParser {
Assert.assertEquals(vp.mExcludedRoutes.trim(), "8.8.8.8/32");
}

@Test
fun testOneDNSImport()
{
val config = "client\n" +
"tun-mtu 1234\n" +
"<connection>\n" +
"remote foo.bar\n" +
"tun-mtu 1222\n" +
"</connection>\n" +
"route 8.8.8.8 255.255.255.255 net_gateway\n" +
"dhcp-option DNS 1.2.3.4\n"

val cp = ConfigParser()
cp.parseConfig(StringReader(config))
val vp = cp.convertProfile()

Assert.assertEquals("1.2.3.4", vp.mDNS1)
Assert.assertEquals("" , vp.mDNS2)
}

@Test
fun testCipherImport() {
Expand Down

0 comments on commit 86582ed

Please sign in to comment.