Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f15b664fc | |||
| 49f287439e | |||
| 150cd119c7 | |||
| e2384e143c | |||
| 52c59704de | |||
| 0b828f9b96 |
@@ -1,4 +1,4 @@
|
|||||||
Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import os.log
|
import os.log
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import os.log
|
import os.log
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: MIT
|
/* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
* Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
* Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: MIT
|
/* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
* Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
* Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RINGLOGGER_H
|
#ifndef RINGLOGGER_H
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>FILEHEADER</key>
|
<key>FILEHEADER</key>
|
||||||
<string> SPDX-License-Identifier: MIT
|
<string> SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.</string>
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
// Generic alert action names
|
// Generic alert action names
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
VERSION_NAME = 0.0.20181225
|
VERSION_NAME = 0.0.20190107
|
||||||
VERSION_ID = 1
|
VERSION_ID = 1
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0+
|
/* SPDX-License-Identifier: GPL-2.0+
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
* Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Curve25519 ECDH functions, based on TweetNaCl but cleaned up.
|
* Curve25519 ECDH functions, based on TweetNaCl but cleaned up.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import os.log
|
import os.log
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import os.log
|
import os.log
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import os.log
|
import os.log
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import MobileCoreServices
|
import MobileCoreServices
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
protocol WireGuardAppError: Error {
|
protocol WireGuardAppError: Error {
|
||||||
typealias AlertText = (title: String, message: String)
|
typealias AlertText = (title: String, message: String)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
enum WireGuardResult<T> {
|
enum WireGuardResult<T> {
|
||||||
case success(_ value: T)
|
case success(_ value: T)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Network
|
import Network
|
||||||
import Foundation
|
import Foundation
|
||||||
@@ -45,7 +45,6 @@ class DNSResolver {
|
|||||||
let resolvedEndpoint = tuple.1
|
let resolvedEndpoint = tuple.1
|
||||||
if let endpoint = endpoint {
|
if let endpoint = endpoint {
|
||||||
if resolvedEndpoint == nil {
|
if resolvedEndpoint == nil {
|
||||||
// DNS resolution failed
|
|
||||||
guard let hostname = endpoint.hostname() else { fatalError() }
|
guard let hostname = endpoint.hostname() else { fatalError() }
|
||||||
hostnamesWithDnsResolutionFailure.append(hostname)
|
hostnamesWithDnsResolutionFailure.append(hostname)
|
||||||
}
|
}
|
||||||
@@ -57,81 +56,97 @@ class DNSResolver {
|
|||||||
}
|
}
|
||||||
return resolvedEndpoints
|
return resolvedEndpoints
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
extension DNSResolver {
|
|
||||||
// Based on DNS resolution code by Jason Donenfeld <jason@zx2c4.com>
|
|
||||||
// in parse_endpoint() in src/tools/config.c in the WireGuard codebase
|
|
||||||
|
|
||||||
//swiftlint:disable:next cyclomatic_complexity
|
|
||||||
private static func resolveSync(endpoint: Endpoint) -> Endpoint? {
|
private static func resolveSync(endpoint: Endpoint) -> Endpoint? {
|
||||||
switch endpoint.host {
|
switch endpoint.host {
|
||||||
case .name(let name, _):
|
case .name(let name, _):
|
||||||
var resultPointer = UnsafeMutablePointer<addrinfo>(OpaquePointer(bitPattern: 0))
|
var resultPointer = UnsafeMutablePointer<addrinfo>(OpaquePointer(bitPattern: 0))
|
||||||
|
var hints = addrinfo(
|
||||||
|
ai_flags: AI_ALL, // We set this to ALL so that we get v4 addresses even on DNS64 networks
|
||||||
|
ai_family: AF_UNSPEC,
|
||||||
|
ai_socktype: SOCK_DGRAM,
|
||||||
|
ai_protocol: IPPROTO_UDP,
|
||||||
|
ai_addrlen: 0,
|
||||||
|
ai_canonname: nil,
|
||||||
|
ai_addr: nil,
|
||||||
|
ai_next: nil)
|
||||||
|
if getaddrinfo(name, "\(endpoint.port)", &hints, &resultPointer) != 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var next = resultPointer
|
||||||
|
var ipv4Address: IPv4Address?
|
||||||
|
var ipv6Address: IPv6Address?
|
||||||
|
while next != nil {
|
||||||
|
let result = next!.pointee
|
||||||
|
next = result.ai_next
|
||||||
|
if result.ai_family == AF_INET && result.ai_addrlen == MemoryLayout<sockaddr_in>.size {
|
||||||
|
var sa4 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in.self).pointee
|
||||||
|
ipv4Address = IPv4Address(Data(bytes: &sa4.sin_addr, count: MemoryLayout<in_addr>.size))
|
||||||
|
break // If we found an IPv4 address, we can stop
|
||||||
|
} else if result.ai_family == AF_INET6 && result.ai_addrlen == MemoryLayout<sockaddr_in6>.size {
|
||||||
|
var sa6 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in6.self).pointee
|
||||||
|
ipv6Address = IPv6Address(Data(bytes: &sa6.sin6_addr, count: MemoryLayout<in6_addr>.size))
|
||||||
|
continue // If we already have an IPv6 address, we can skip this one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
freeaddrinfo(resultPointer)
|
||||||
|
|
||||||
// The endpoint is a hostname and needs DNS resolution
|
// We prefer an IPv4 address over an IPv6 address
|
||||||
if addressInfo(for: name, port: endpoint.port, resultPointer: &resultPointer) == 0 {
|
if let ipv4Address = ipv4Address {
|
||||||
// getaddrinfo succeeded
|
return Endpoint(host: .ipv4(ipv4Address), port: endpoint.port)
|
||||||
let ipv4Buffer = UnsafeMutablePointer<Int8>.allocate(capacity: Int(INET_ADDRSTRLEN))
|
} else if let ipv6Address = ipv6Address {
|
||||||
let ipv6Buffer = UnsafeMutablePointer<Int8>.allocate(capacity: Int(INET6_ADDRSTRLEN))
|
return Endpoint(host: .ipv6(ipv6Address), port: endpoint.port)
|
||||||
var ipv4AddressString: String?
|
|
||||||
var ipv6AddressString: String?
|
|
||||||
while resultPointer != nil {
|
|
||||||
let result = resultPointer!.pointee
|
|
||||||
resultPointer = result.ai_next
|
|
||||||
if result.ai_family == AF_INET && result.ai_addrlen == MemoryLayout<sockaddr_in>.size {
|
|
||||||
var sa4 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in.self).pointee
|
|
||||||
if inet_ntop(result.ai_family, &sa4.sin_addr, ipv4Buffer, socklen_t(INET_ADDRSTRLEN)) != nil {
|
|
||||||
ipv4AddressString = String(cString: ipv4Buffer)
|
|
||||||
// If we found an IPv4 address, we can stop
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else if result.ai_family == AF_INET6 && result.ai_addrlen == MemoryLayout<sockaddr_in6>.size {
|
|
||||||
if ipv6AddressString != nil {
|
|
||||||
// If we already have an IPv6 address, we can skip this one
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var sa6 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in6.self).pointee
|
|
||||||
if inet_ntop(result.ai_family, &sa6.sin6_addr, ipv6Buffer, socklen_t(INET6_ADDRSTRLEN)) != nil {
|
|
||||||
ipv6AddressString = String(cString: ipv6Buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ipv4Buffer.deallocate()
|
|
||||||
ipv6Buffer.deallocate()
|
|
||||||
// We prefer an IPv4 address over an IPv6 address
|
|
||||||
if let ipv4AddressString = ipv4AddressString, let ipv4Address = IPv4Address(ipv4AddressString) {
|
|
||||||
return Endpoint(host: .ipv4(ipv4Address), port: endpoint.port)
|
|
||||||
} else if let ipv6AddressString = ipv6AddressString, let ipv6Address = IPv6Address(ipv6AddressString) {
|
|
||||||
return Endpoint(host: .ipv6(ipv6Address), port: endpoint.port)
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// getaddrinfo failed
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// The endpoint is already resolved
|
|
||||||
return endpoint
|
return endpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static func addressInfo(for name: String, port: NWEndpoint.Port, resultPointer: inout UnsafeMutablePointer<addrinfo>?) -> Int32 {
|
extension Endpoint {
|
||||||
|
func withReresolvedIP() -> Endpoint {
|
||||||
|
var ret = self
|
||||||
|
let hostname: String
|
||||||
|
switch host {
|
||||||
|
case .name(let name, _):
|
||||||
|
hostname = name
|
||||||
|
case .ipv4(let address):
|
||||||
|
hostname = "\(address)"
|
||||||
|
case .ipv6(let address):
|
||||||
|
hostname = "\(address)"
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultPointer = UnsafeMutablePointer<addrinfo>(OpaquePointer(bitPattern: 0))
|
||||||
var hints = addrinfo(
|
var hints = addrinfo(
|
||||||
ai_flags: 0,
|
ai_flags: 0, // We set this to zero so that we actually resolve this using DNS64
|
||||||
ai_family: AF_UNSPEC,
|
ai_family: AF_UNSPEC,
|
||||||
ai_socktype: SOCK_DGRAM, // WireGuard is UDP-only
|
ai_socktype: SOCK_DGRAM,
|
||||||
ai_protocol: IPPROTO_UDP, // WireGuard is UDP-only
|
ai_protocol: IPPROTO_UDP,
|
||||||
ai_addrlen: 0,
|
ai_addrlen: 0,
|
||||||
ai_canonname: nil,
|
ai_canonname: nil,
|
||||||
ai_addr: nil,
|
ai_addr: nil,
|
||||||
ai_next: nil)
|
ai_next: nil)
|
||||||
|
if getaddrinfo(hostname, "\(port)", &hints, &resultPointer) != 0 || resultPointer == nil {
|
||||||
return getaddrinfo(
|
return ret
|
||||||
name.cString(using: .utf8), // Hostname
|
}
|
||||||
"\(port)".cString(using: .utf8), // Port
|
let result = resultPointer!.pointee
|
||||||
&hints,
|
if result.ai_family == AF_INET && result.ai_addrlen == MemoryLayout<sockaddr_in>.size {
|
||||||
&resultPointer)
|
var sa4 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in.self).pointee
|
||||||
|
let addr = IPv4Address(Data(bytes: &sa4.sin_addr, count: MemoryLayout<in_addr>.size))
|
||||||
|
ret = Endpoint(host: .ipv4(addr!), port: port)
|
||||||
|
} else if result.ai_family == AF_INET6 && result.ai_addrlen == MemoryLayout<sockaddr_in6>.size {
|
||||||
|
var sa6 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in6.self).pointee
|
||||||
|
let addr = IPv6Address(Data(bytes: &sa6.sin6_addr, count: MemoryLayout<in6_addr>.size))
|
||||||
|
ret = Endpoint(host: .ipv6(addr!), port: port)
|
||||||
|
}
|
||||||
|
freeaddrinfo(resultPointer)
|
||||||
|
if ret.host != host {
|
||||||
|
wg_log(.debug, message: "DNS64: mapped \(host) to \(ret.host)")
|
||||||
|
} else {
|
||||||
|
wg_log(.debug, message: "DNS64: mapped \(host) to itself.")
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
@@ -17,6 +17,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||||||
networkMonitor?.cancel()
|
networkMonitor?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//swiftlint:disable:next function_body_length
|
||||||
override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
|
override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
|
||||||
let activationAttemptId = options?["activationAttemptId"] as? String
|
let activationAttemptId = options?["activationAttemptId"] as? String
|
||||||
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)
|
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)
|
||||||
@@ -65,6 +66,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||||||
if getsockopt(fileDescriptor, 2 /* SYSPROTO_CONTROL */, 2 /* UTUN_OPT_IFNAME */, ifnamePtr, &ifnameSize) == 0 {
|
if getsockopt(fileDescriptor, 2 /* SYSPROTO_CONTROL */, 2 /* UTUN_OPT_IFNAME */, ifnamePtr, &ifnameSize) == 0 {
|
||||||
self.ifname = String(cString: ifnamePtr)
|
self.ifname = String(cString: ifnamePtr)
|
||||||
}
|
}
|
||||||
|
ifnamePtr.deallocate()
|
||||||
wg_log(.info, message: "Tunnel interface is \(self.ifname ?? "unknown")")
|
wg_log(.info, message: "Tunnel interface is \(self.ifname ?? "unknown")")
|
||||||
let handle = self.packetTunnelSettingsGenerator!.uapiConfiguration().withGoString { return wgTurnOn($0, fileDescriptor) }
|
let handle = self.packetTunnelSettingsGenerator!.uapiConfiguration().withGoString { return wgTurnOn($0, fileDescriptor) }
|
||||||
if handle < 0 {
|
if handle < 0 {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
@@ -18,7 +18,7 @@ class PacketTunnelSettingsGenerator {
|
|||||||
var wgSettings = ""
|
var wgSettings = ""
|
||||||
for (index, peer) in tunnelConfiguration.peers.enumerated() {
|
for (index, peer) in tunnelConfiguration.peers.enumerated() {
|
||||||
wgSettings.append("public_key=\(peer.publicKey.hexEncodedString())\n")
|
wgSettings.append("public_key=\(peer.publicKey.hexEncodedString())\n")
|
||||||
if let endpoint = resolvedEndpoints[index] {
|
if let endpoint = resolvedEndpoints[index]?.withReresolvedIP() {
|
||||||
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
|
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
|
||||||
wgSettings.append("endpoint=\(endpoint.stringRepresentation)\n")
|
wgSettings.append("endpoint=\(endpoint.stringRepresentation)\n")
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ class PacketTunnelSettingsGenerator {
|
|||||||
if let preSharedKey = peer.preSharedKey {
|
if let preSharedKey = peer.preSharedKey {
|
||||||
wgSettings.append("preshared_key=\(preSharedKey.hexEncodedString())\n")
|
wgSettings.append("preshared_key=\(preSharedKey.hexEncodedString())\n")
|
||||||
}
|
}
|
||||||
if let endpoint = resolvedEndpoints[index] {
|
if let endpoint = resolvedEndpoints[index]?.withReresolvedIP() {
|
||||||
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
|
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
|
||||||
wgSettings.append("endpoint=\(endpoint.stringRepresentation)\n")
|
wgSettings.append("endpoint=\(endpoint.stringRepresentation)\n")
|
||||||
}
|
}
|
||||||
@@ -63,46 +63,36 @@ class PacketTunnelSettingsGenerator {
|
|||||||
* make sense. So, we fill it in with this placeholder, which is not
|
* make sense. So, we fill it in with this placeholder, which is not
|
||||||
* a valid IP address that will actually route over the Internet.
|
* a valid IP address that will actually route over the Internet.
|
||||||
*/
|
*/
|
||||||
var remoteAddress = "0.0.0.0"
|
let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "127.0.0.1")
|
||||||
let endpointsCompact = resolvedEndpoints.compactMap { $0 }
|
|
||||||
if endpointsCompact.count == 1 {
|
|
||||||
switch endpointsCompact.first!.host {
|
|
||||||
case .ipv4(let address):
|
|
||||||
remoteAddress = "\(address)"
|
|
||||||
case .ipv6(let address):
|
|
||||||
remoteAddress = "\(address)"
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: remoteAddress)
|
|
||||||
|
|
||||||
let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation }
|
let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation }
|
||||||
let dnsSettings = NEDNSSettings(servers: dnsServerStrings)
|
let dnsSettings = NEDNSSettings(servers: dnsServerStrings)
|
||||||
dnsSettings.matchDomains = [""] // All DNS queries must first go through the tunnel's DNS
|
dnsSettings.matchDomains = [""] // All DNS queries must first go through the tunnel's DNS
|
||||||
networkSettings.dnsSettings = dnsSettings
|
networkSettings.dnsSettings = dnsSettings
|
||||||
|
|
||||||
let mtu = tunnelConfiguration.interface.mtu ?? 0
|
var mtu = tunnelConfiguration.interface.mtu ?? 0
|
||||||
|
|
||||||
|
/* 0 means automatic MTU. In theory, we should just do
|
||||||
|
* `networkSettings.tunnelOverheadBytes = 80` but in
|
||||||
|
* practice there are too many broken networks out there.
|
||||||
|
* Instead set it to 1280. Boohoo. Maybe someday we'll
|
||||||
|
* add a nob, maybe, or iOS will do probing for us.
|
||||||
|
*/
|
||||||
if mtu == 0 {
|
if mtu == 0 {
|
||||||
// 0 imples automatic MTU, where we set overhead as 80 bytes, which is the worst case for WireGuard
|
mtu = 1280
|
||||||
networkSettings.tunnelOverheadBytes = 80
|
|
||||||
} else {
|
|
||||||
networkSettings.mtu = NSNumber(value: mtu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
networkSettings.mtu = NSNumber(value: mtu)
|
||||||
|
|
||||||
let (ipv4Routes, ipv6Routes) = routes()
|
let (ipv4Routes, ipv6Routes) = routes()
|
||||||
let (ipv4IncludedRoutes, ipv6IncludedRoutes) = includedRoutes()
|
let (ipv4IncludedRoutes, ipv6IncludedRoutes) = includedRoutes()
|
||||||
let (ipv4ExcludedRoutes, ipv6ExcludedRoutes) = excludedRoutes()
|
|
||||||
|
|
||||||
let ipv4Settings = NEIPv4Settings(addresses: ipv4Routes.map { $0.destinationAddress }, subnetMasks: ipv4Routes.map { $0.destinationSubnetMask })
|
let ipv4Settings = NEIPv4Settings(addresses: ipv4Routes.map { $0.destinationAddress }, subnetMasks: ipv4Routes.map { $0.destinationSubnetMask })
|
||||||
ipv4Settings.includedRoutes = ipv4IncludedRoutes
|
ipv4Settings.includedRoutes = ipv4IncludedRoutes
|
||||||
ipv4Settings.excludedRoutes = ipv4ExcludedRoutes
|
|
||||||
networkSettings.ipv4Settings = ipv4Settings
|
networkSettings.ipv4Settings = ipv4Settings
|
||||||
|
|
||||||
let ipv6Settings = NEIPv6Settings(addresses: ipv6Routes.map { $0.destinationAddress }, networkPrefixLengths: ipv6Routes.map { $0.destinationNetworkPrefixLength })
|
let ipv6Settings = NEIPv6Settings(addresses: ipv6Routes.map { $0.destinationAddress }, networkPrefixLengths: ipv6Routes.map { $0.destinationNetworkPrefixLength })
|
||||||
ipv6Settings.includedRoutes = ipv6IncludedRoutes
|
ipv6Settings.includedRoutes = ipv6IncludedRoutes
|
||||||
ipv6Settings.excludedRoutes = ipv6ExcludedRoutes
|
|
||||||
networkSettings.ipv6Settings = ipv6Settings
|
networkSettings.ipv6Settings = ipv6Settings
|
||||||
|
|
||||||
return networkSettings
|
return networkSettings
|
||||||
@@ -152,24 +142,6 @@ class PacketTunnelSettingsGenerator {
|
|||||||
}
|
}
|
||||||
return (ipv4IncludedRoutes, ipv6IncludedRoutes)
|
return (ipv4IncludedRoutes, ipv6IncludedRoutes)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func excludedRoutes() -> ([NEIPv4Route], [NEIPv6Route]) {
|
|
||||||
var ipv4ExcludedRoutes = [NEIPv4Route]()
|
|
||||||
var ipv6ExcludedRoutes = [NEIPv6Route]()
|
|
||||||
for endpoint in resolvedEndpoints {
|
|
||||||
guard let endpoint = endpoint else { continue }
|
|
||||||
switch endpoint.host {
|
|
||||||
case .ipv4(let address):
|
|
||||||
ipv4ExcludedRoutes.append(NEIPv4Route(destinationAddress: "\(address)", subnetMask: "255.255.255.255"))
|
|
||||||
case .ipv6(let address):
|
|
||||||
ipv6ExcludedRoutes.append(NEIPv6Route(destinationAddress: "\(address)", networkPrefixLength: NSNumber(value: UInt8(128))))
|
|
||||||
default:
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (ipv4ExcludedRoutes, ipv6ExcludedRoutes)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension Data {
|
private extension Data {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
#
|
#
|
||||||
# Copyright (C) 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
# Copyright (C) 2018-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
||||||
|
|
||||||
# These are generally passed to us by xcode, but we set working defaults for standalone compilation too.
|
# These are generally passed to us by xcode, but we set working defaults for standalone compilation too.
|
||||||
ARCHS ?= arm64 armv7
|
ARCHS ?= arm64 armv7
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0
|
/* SPDX-License-Identifier: GPL-2.0
|
||||||
*
|
*
|
||||||
* Copyright (C) 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
* Copyright (C) 2018-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0
|
/* SPDX-License-Identifier: GPL-2.0
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017-2018 WireGuard LLC. All Rights Reserved.
|
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0
|
/* SPDX-License-Identifier: GPL-2.0
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
* Copyright (C) 2017-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package tun
|
package tun
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0
|
/* SPDX-License-Identifier: GPL-2.0
|
||||||
*
|
*
|
||||||
* Copyright (C) 2018 WireGuard LLC. All Rights Reserved.
|
* Copyright (C) 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WIREGUARD_H
|
#ifndef WIREGUARD_H
|
||||||
|
|||||||
Reference in New Issue
Block a user