diff --git a/CZiti.xcodeproj/project.pbxproj b/CZiti.xcodeproj/project.pbxproj index aa4759d..d927fe3 100644 --- a/CZiti.xcodeproj/project.pbxproj +++ b/CZiti.xcodeproj/project.pbxproj @@ -89,6 +89,8 @@ 5AB830CA247489C70089AF93 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5AB830C9247489C70089AF93 /* Assets.xcassets */; }; 5AB830CD247489C70089AF93 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5AB830CB247489C70089AF93 /* LaunchScreen.storyboard */; }; 5AB830D224748A1B0089AF93 /* libCZiti.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5AB6DFAF244B990A00F4B4E0 /* libCZiti.a */; }; + 5AD1FBC325D4A8A10035CE6C /* ZitiHostConfigV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AD1FBC225D4A8A10035CE6C /* ZitiHostConfigV1.swift */; }; + 5AD1FBC425D4A8A10035CE6C /* ZitiHostConfigV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AD1FBC225D4A8A10035CE6C /* ZitiHostConfigV1.swift */; }; 5AE14C882471D32E00179365 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE14C872471D32E00179365 /* main.swift */; }; 5AE14C8C2471DDA000179365 /* libCZiti.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5AB6DF68244B7C3C00F4B4E0 /* libCZiti.a */; }; 5AF0C4112489987500CD4DAE /* ZitiClaims.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AF0C4102489987500CD4DAE /* ZitiClaims.swift */; }; @@ -221,6 +223,7 @@ 5AB830C9247489C70089AF93 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 5AB830CC247489C70089AF93 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 5AB830CE247489C70089AF93 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 5AD1FBC225D4A8A10035CE6C /* ZitiHostConfigV1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZitiHostConfigV1.swift; sourceTree = ""; }; 5AE14C852471D32E00179365 /* sample-mac-host */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "sample-mac-host"; sourceTree = BUILT_PRODUCTS_DIR; }; 5AE14C872471D32E00179365 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 5AF0C4102489987500CD4DAE /* ZitiClaims.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZitiClaims.swift; sourceTree = ""; }; @@ -393,6 +396,7 @@ 5AB83098247432C40089AF93 /* ZitiTunnelClientConfigV1.swift */, 5A8B0C1C2594119900182437 /* ZitiTunnelServerConfigV1.swift */, 5A69FBFE25D1934A007B3B43 /* ZitiInterceptConfigV1.swift */, + 5AD1FBC225D4A8A10035CE6C /* ZitiHostConfigV1.swift */, 5A5538E72556F92100C02F03 /* ZitiPostureChecks.swift */, 5AB8308F247432C40089AF93 /* ZitiError.swift */, 5AB83094247432C40089AF93 /* ZitiLog.swift */, @@ -654,6 +658,7 @@ 5AB8309E247432C40089AF93 /* ZitiError.swift in Sources */, 5AB830A7247432C40089AF93 /* ZitiTunnelClientConfigV1.swift in Sources */, 5AB830A5247432C40089AF93 /* ZitiUrlProtocol.swift in Sources */, + 5AD1FBC325D4A8A10035CE6C /* ZitiHostConfigV1.swift in Sources */, 5A5538E82556F92100C02F03 /* ZitiPostureChecks.swift in Sources */, 5AB830A8247432C40089AF93 /* ZitiEnroller.swift in Sources */, 5AB830A9247432C50089AF93 /* ZitiIdentity.swift in Sources */, @@ -683,6 +688,7 @@ 5AB830AC2474330D0089AF93 /* ZitiError.swift in Sources */, 5AB830B52474332E0089AF93 /* ZitiTunnelClientConfigV1.swift in Sources */, 5AB830B3247433270089AF93 /* ZitiUrlProtocol.swift in Sources */, + 5AD1FBC425D4A8A10035CE6C /* ZitiHostConfigV1.swift in Sources */, 5A5538E92556F92100C02F03 /* ZitiPostureChecks.swift in Sources */, 5AB830B6247433310089AF93 /* ZitiEnroller.swift in Sources */, 5AB830B7247433350089AF93 /* ZitiIdentity.swift in Sources */, diff --git a/lib/ZitiHostConfigV1.swift b/lib/ZitiHostConfigV1.swift new file mode 100644 index 0000000..7c8859e --- /dev/null +++ b/lib/ZitiHostConfigV1.swift @@ -0,0 +1,50 @@ +/* +Copyright NetFoundry, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +import Foundation + +public class ZitiHostConfigV1 : Codable, ZitiConfig { + static var configType = "host.v1" + + enum CodingKeys: String, CodingKey { + case proto = "protocol" + case dialInterceptedProtocol + case address + case dialInterceptedAddress + case port + case dialInterceptedPort + case listenOptions + } + + public class ListenOptions : Codable { + public var cost:Int? + public var precedence:String? + public var connectTimeoutSeconds:Int? + public var maxConnections:Int? + public var identity:String? + public var bindUsingEdgeIdentity:Bool? + } + + public var proto:String? + public var dialInterceptedProtocol:Bool? + + public var address:String? + public var dialInterceptedAddress:Bool? + + public var port:Int? + public var dialInterceptedPort:Bool? + + public var listenOptions:ListenOptions? +} diff --git a/lib/ZitiInterceptConfigV1.swift b/lib/ZitiInterceptConfigV1.swift index d71431b..7dd57d1 100644 --- a/lib/ZitiInterceptConfigV1.swift +++ b/lib/ZitiInterceptConfigV1.swift @@ -1,5 +1,5 @@ /* -Copyright 2021 NetFoundry, Inc. +Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,7 +23,15 @@ public class ZitiInterceptConfigV1 : Codable, ZitiConfig { public let high:Int } + public class DialOptions : Codable { + public var identity:String? + public var connectTimeoutSeconds:Int? + } + public let protocols:[String] public let addresses:[String] public let portRanges:[PortRange] + + public var dialOptions:DialOptions? + public var sourceIp:String? } diff --git a/lib/ZitiService.swift b/lib/ZitiService.swift index af75ee2..cfe8f57 100644 --- a/lib/ZitiService.swift +++ b/lib/ZitiService.swift @@ -1,5 +1,5 @@ /* -Copyright 2020 NetFoundry, Inc. +Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ import Foundation case tunnelClientConfigV1 = "ziti-tunneler-client.v1" case tunnelServerConfigV1 = "ziti-tunneler-server.v1" case urlClientConfigV1 = "ziti-url-client.v1" + case interceptConfigV1 = "intercept.v1" + case hostConfigV1 = "host.v1" } public var cService:UnsafeMutablePointer? @@ -34,6 +36,7 @@ import Foundation public var tunnelServerConfigV1:ZitiTunnelServerConfigV1? public var urlClientConfigV1:ZitiUrlClientConfigV1? public var interceptConfigV1:ZitiInterceptConfigV1? + public var hostConfigV1:ZitiHostConfigV1? init(_ cService:UnsafeMutablePointer) { self.cService = cService @@ -54,6 +57,9 @@ import Foundation if let cfg = ZitiService.parseConfig(ZitiInterceptConfigV1.self, &(cService.pointee)) { interceptConfigV1 = cfg } + if let cfg = ZitiService.parseConfig(ZitiHostConfigV1.self, &(cService.pointee)) { + hostConfigV1 = cfg + } } static func parseConfig(_ type: T.Type, _ zs: inout ziti_service) -> T? where T:Decodable, T:ZitiConfig { diff --git a/lib/ZitiTunnelClientConfigV1.swift b/lib/ZitiTunnelClientConfigV1.swift index 90a0cb5..36675bd 100644 --- a/lib/ZitiTunnelClientConfigV1.swift +++ b/lib/ZitiTunnelClientConfigV1.swift @@ -1,5 +1,5 @@ /* -Copyright 2020 NetFoundry, Inc. +Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/ZitiTunnelServerConfigV1.swift b/lib/ZitiTunnelServerConfigV1.swift index e216ac1..3d7528d 100644 --- a/lib/ZitiTunnelServerConfigV1.swift +++ b/lib/ZitiTunnelServerConfigV1.swift @@ -1,5 +1,5 @@ /* -Copyright 2020 NetFoundry, Inc. +Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import Foundation public class ZitiTunnelServerConfigV1 : Codable, ZitiConfig { static var configType = "ziti-tunneler-server.v1" enum CodingKeys: String, CodingKey { - case hostname - case port - case proto = "protocol" - } + case hostname + case port + case proto = "protocol" + } public let hostname:String public let port:Int diff --git a/lib/ZitiUrlClientConfigV1.swift b/lib/ZitiUrlClientConfigV1.swift index cebbb55..d1d89cc 100644 --- a/lib/ZitiUrlClientConfigV1.swift +++ b/lib/ZitiUrlClientConfigV1.swift @@ -1,5 +1,5 @@ /* -Copyright 2020 NetFoundry, Inc. +Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/ZitiUrlProtocol.swift b/lib/ZitiUrlProtocol.swift index 2267a46..187b392 100644 --- a/lib/ZitiUrlProtocol.swift +++ b/lib/ZitiUrlProtocol.swift @@ -1,5 +1,5 @@ /* -Copyright 2020 NetFoundry, Inc. +Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -82,6 +82,7 @@ import Foundation } class func onEvent(_ event:ZitiEvent?, _ idleTime:Int) { + log.debug("Event: \(event.debugDescription)") event?.serviceEvent?.removed.forEach { removeService($0) } event?.serviceEvent?.added.forEach { addOrUpdateService($0, event?.ziti, idleTime) } event?.serviceEvent?.changed.forEach { addOrUpdateService($0, event?.ziti, idleTime) } @@ -102,24 +103,24 @@ import Foundation let hostPort = "\(hostname):\(port)" if let curr = ZitiUrlProtocol.intercepts["http://\(hostPort)"] { - log.info("intercept \"http://\(hostPort)\" changing from \"\(curr.name)\" to \"\(svcName)\"", function:"onService()") + log.info("intercept \"http://\(hostPort)\" changing from \"\(curr.name)\" to \"\(svcName)\"") curr.close() } if let curr = ZitiUrlProtocol.intercepts["https://\(hostPort)"] { - log.info("intercept \"https://\(hostPort)\" changing from \"\(curr.name)\" to \"\(svcName)\"", function:"onService()") + log.info("intercept \"https://\(hostPort)\" changing from \"\(curr.name)\" to \"\(svcName)\"") curr.close() } if let scheme = (port == 80 ? "http" : (port == 443 ? "https" : nil)) { let intercept = ZitiIntercept(ziti, svcName, "\(scheme)://\(hostPort)", idleTime) intercepts[intercept.urlStr] = intercept - log.info("Setting TUN intercept svc \(scheme)://\(hostPort): \(hostPort)", function:"onService()()") + log.info("Setting TUN intercept svc \(scheme)://\(hostPort): \(hostPort)") } else { var intercept = ZitiIntercept(ziti, svcName, "http://\(hostPort)", idleTime) intercepts[intercept.urlStr] = intercept intercept = ZitiIntercept(ziti, svcName, "https://\(hostPort)", idleTime) intercepts[intercept.urlStr] = intercept - log.info("Setting TUN intercept svc \(svcName): \(hostPort)", function:"onService()()") + log.info("Setting TUN intercept svc \(svcName): \(hostPort)") } } @@ -141,7 +142,7 @@ import Foundation interceptsLock.lock() if let curr = ZitiUrlProtocol.intercepts[urlStr] { - log.info("intercept \"\(urlStr)\" changing from \"\(curr.name)\" to \"\(svcName)\"", function:"onService()") + log.info("intercept \"\(urlStr)\" changing from \"\(curr.name)\" to \"\(svcName)\"") curr.close() } let intercept = ZitiIntercept(ziti, svcName, urlStr, idleTime)