Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DoH/DoT options to WireGuardKit #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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