wireguard-apple/WireGuard/WireGuard/Model/Configuration.swift

54 lines
1.4 KiB
Swift
Raw Normal View History

2018-10-24 01:37:28 +00:00
// SPDX-License-Identifier: MIT
// Copyright © 2018 WireGuard LLC. All rights reserved.
2018-10-13 12:14:46 +00:00
import Foundation
@available(OSX 10.14, iOS 12.0, *)
2018-10-13 12:14:46 +00:00
class TunnelConfiguration: Codable {
var interface: InterfaceConfiguration
2018-10-13 12:14:46 +00:00
var peers: [PeerConfiguration] = []
init(interface: InterfaceConfiguration) {
2018-10-13 12:14:46 +00:00
self.interface = interface
}
}
@available(OSX 10.14, iOS 12.0, *)
struct InterfaceConfiguration: Codable {
var name: String
2018-10-13 12:14:46 +00:00
var privateKey: Data
var addresses: [IPAddressRange] = []
var listenPort: UInt16? = nil
2018-10-24 13:31:33 +00:00
var mtu: UInt16? = nil
var dns: [DNSServer] = []
var publicKey: Data {
return Curve25519.generatePublicKey(fromPrivateKey: privateKey)
}
init(name: String, privateKey: Data) {
self.name = name
2018-10-13 12:14:46 +00:00
self.privateKey = privateKey
if (privateKey.count != 32) { fatalError("Invalid private key") }
2018-10-13 12:14:46 +00:00
}
}
@available(OSX 10.14, iOS 12.0, *)
struct PeerConfiguration: Codable {
2018-10-13 12:14:46 +00:00
var publicKey: Data
var preSharedKey: Data? {
didSet(value) {
if let value = value {
if (value.count != 32) { fatalError("Invalid pre-shared key") }
}
}
}
var allowedIPs: [IPAddressRange] = []
var endpoint: Endpoint?
var persistentKeepAlive: UInt16?
2018-10-13 12:14:46 +00:00
init(publicKey: Data) {
self.publicKey = publicKey
if (publicKey.count != 32) { fatalError("Invalid public key") }
2018-10-13 12:14:46 +00:00
}
}