Skip to content

Commit

Permalink
Add DoH/DoT options
Browse files Browse the repository at this point in the history
Signed-off-by: Davide De Rosa <[email protected]>
  • Loading branch information
keeshux committed Mar 18, 2023
1 parent 2fec12a commit 057dd90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Sources/WireGuardKit/InterfaceConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public struct InterfaceConfiguration {
public var mtu: UInt16?
public var dns = [DNSServer]()
public var dnsSearch = [String]()
public var dnsHTTPSURL: URL?
public var dnsTLSServerName: String?

public init(privateKey: PrivateKey) {
self.privateKey = privateKey
Expand All @@ -27,6 +29,8 @@ extension InterfaceConfiguration: Equatable {
lhs.listenPort == rhs.listenPort &&
lhs.mtu == rhs.mtu &&
lhs.dns == rhs.dns &&
lhs.dnsSearch == rhs.dnsSearch
lhs.dnsSearch == rhs.dnsSearch &&
lhs.dnsHTTPSURL == rhs.dnsHTTPSURL &&
lhs.dnsTLSServerName == rhs.dnsTLSServerName
}
}
16 changes: 15 additions & 1 deletion Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,25 @@ class PacketTunnelSettingsGenerator {

if !tunnelConfiguration.interface.dnsSearch.isEmpty || !tunnelConfiguration.interface.dns.isEmpty {
let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation }
let dnsSettings = NEDNSSettings(servers: dnsServerStrings)

let dnsSettings: NEDNSSettings
if let dnsHTTPSURL = tunnelConfiguration.interface.dnsHTTPSURL {
let dohSettings = NEDNSOverHTTPSSettings(servers: dnsServerStrings)
dohSettings.serverURL = dnsHTTPSURL
dnsSettings = dohSettings
} else if let dnsTLSServerName = tunnelConfiguration.interface.dnsTLSServerName {
let dotSettings = NEDNSOverTLSSettings(servers: dnsServerStrings)
dotSettings.serverName = dnsTLSServerName
dnsSettings = dotSettings
} else {
dnsSettings = NEDNSSettings(servers: dnsServerStrings)
}

dnsSettings.searchDomains = tunnelConfiguration.interface.dnsSearch
if !tunnelConfiguration.interface.dns.isEmpty {
dnsSettings.matchDomains = [""] // All DNS queries must first go through the tunnel's DNS
}

networkSettings.dnsSettings = dnsSettings
}

Expand Down

0 comments on commit 057dd90

Please sign in to comment.