Skip to content

Commit 057dd90

Browse files
committed
Add DoH/DoT options
Signed-off-by: Davide De Rosa <[email protected]>
1 parent 2fec12a commit 057dd90

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Sources/WireGuardKit/InterfaceConfiguration.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public struct InterfaceConfiguration {
1111
public var mtu: UInt16?
1212
public var dns = [DNSServer]()
1313
public var dnsSearch = [String]()
14+
public var dnsHTTPSURL: URL?
15+
public var dnsTLSServerName: String?
1416

1517
public init(privateKey: PrivateKey) {
1618
self.privateKey = privateKey
@@ -27,6 +29,8 @@ extension InterfaceConfiguration: Equatable {
2729
lhs.listenPort == rhs.listenPort &&
2830
lhs.mtu == rhs.mtu &&
2931
lhs.dns == rhs.dns &&
30-
lhs.dnsSearch == rhs.dnsSearch
32+
lhs.dnsSearch == rhs.dnsSearch &&
33+
lhs.dnsHTTPSURL == rhs.dnsHTTPSURL &&
34+
lhs.dnsTLSServerName == rhs.dnsTLSServerName
3135
}
3236
}

Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,25 @@ class PacketTunnelSettingsGenerator {
8585

8686
if !tunnelConfiguration.interface.dnsSearch.isEmpty || !tunnelConfiguration.interface.dns.isEmpty {
8787
let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation }
88-
let dnsSettings = NEDNSSettings(servers: dnsServerStrings)
88+
89+
let dnsSettings: NEDNSSettings
90+
if let dnsHTTPSURL = tunnelConfiguration.interface.dnsHTTPSURL {
91+
let dohSettings = NEDNSOverHTTPSSettings(servers: dnsServerStrings)
92+
dohSettings.serverURL = dnsHTTPSURL
93+
dnsSettings = dohSettings
94+
} else if let dnsTLSServerName = tunnelConfiguration.interface.dnsTLSServerName {
95+
let dotSettings = NEDNSOverTLSSettings(servers: dnsServerStrings)
96+
dotSettings.serverName = dnsTLSServerName
97+
dnsSettings = dotSettings
98+
} else {
99+
dnsSettings = NEDNSSettings(servers: dnsServerStrings)
100+
}
101+
89102
dnsSettings.searchDomains = tunnelConfiguration.interface.dnsSearch
90103
if !tunnelConfiguration.interface.dns.isEmpty {
91104
dnsSettings.matchDomains = [""] // All DNS queries must first go through the tunnel's DNS
92105
}
106+
93107
networkSettings.dnsSettings = dnsSettings
94108
}
95109

0 commit comments

Comments
 (0)