2018-10-24 01:37:28 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2018-10-30 02:57:35 +00:00
|
|
|
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
2018-10-13 12:14:46 +00:00
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2018-10-13 13:35:52 +00:00
|
|
|
@available(OSX 10.14, iOS 12.0, *)
|
2018-10-13 12:14:46 +00:00
|
|
|
class TunnelConfiguration: Codable {
|
2018-10-25 05:40:18 +00:00
|
|
|
var interface: InterfaceConfiguration
|
2018-10-13 12:14:46 +00:00
|
|
|
var peers: [PeerConfiguration] = []
|
2018-10-17 10:41:22 +00:00
|
|
|
init(interface: InterfaceConfiguration) {
|
2018-10-13 12:14:46 +00:00
|
|
|
self.interface = interface
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 13:35:52 +00:00
|
|
|
@available(OSX 10.14, iOS 12.0, *)
|
2018-10-20 11:00:14 +00:00
|
|
|
struct InterfaceConfiguration: Codable {
|
2018-10-17 10:41:22 +00:00
|
|
|
var name: String
|
2018-10-13 12:14:46 +00:00
|
|
|
var privateKey: Data
|
2018-10-13 13:35:52 +00:00
|
|
|
var addresses: [IPAddressRange] = []
|
2018-11-03 18:35:25 +00:00
|
|
|
var listenPort: UInt16?
|
|
|
|
var mtu: UInt16?
|
2018-10-23 10:58:24 +00:00
|
|
|
var dns: [DNSServer] = []
|
2018-10-20 10:35:25 +00:00
|
|
|
|
2018-10-17 10:41:22 +00:00
|
|
|
init(name: String, privateKey: Data) {
|
|
|
|
self.name = name
|
2018-10-13 12:14:46 +00:00
|
|
|
self.privateKey = privateKey
|
2018-10-28 12:42:18 +00:00
|
|
|
if (name.isEmpty) { fatalError("Empty name") }
|
2018-10-20 10:35:25 +00:00
|
|
|
if (privateKey.count != 32) { fatalError("Invalid private key") }
|
2018-10-13 12:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 13:35:52 +00:00
|
|
|
@available(OSX 10.14, iOS 12.0, *)
|
2018-10-20 11:00:14 +00:00
|
|
|
struct PeerConfiguration: Codable {
|
2018-10-13 12:14:46 +00:00
|
|
|
var publicKey: Data
|
2018-10-20 10:35:25 +00:00
|
|
|
var preSharedKey: Data? {
|
|
|
|
didSet(value) {
|
|
|
|
if let value = value {
|
2018-11-01 17:59:58 +00:00
|
|
|
if (value.count != 32) { fatalError("Invalid preshared key") }
|
2018-10-20 10:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-13 13:35:52 +00:00
|
|
|
var allowedIPs: [IPAddressRange] = []
|
2018-10-19 14:04:51 +00:00
|
|
|
var endpoint: Endpoint?
|
2018-10-23 10:21:19 +00:00
|
|
|
var persistentKeepAlive: UInt16?
|
2018-10-20 10:35:25 +00:00
|
|
|
|
2018-10-13 12:14:46 +00:00
|
|
|
init(publicKey: Data) {
|
|
|
|
self.publicKey = publicKey
|
2018-10-20 10:35:25 +00:00
|
|
|
if (publicKey.count != 32) { fatalError("Invalid public key") }
|
2018-10-13 12:14:46 +00:00
|
|
|
}
|
|
|
|
}
|