Skip to content

Commit

Permalink
Merge pull request #81 from openziti/dev
Browse files Browse the repository at this point in the history
Completion of intercet.v1 and host.v1 config type support
  • Loading branch information
smilindave26 authored Feb 11, 2021
2 parents 8f8bc5c + 8c6ce73 commit 2203bac
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CZiti.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -221,6 +223,7 @@
5AB830C9247489C70089AF93 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5AB830CC247489C70089AF93 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
5AB830CE247489C70089AF93 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5AD1FBC225D4A8A10035CE6C /* ZitiHostConfigV1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZitiHostConfigV1.swift; sourceTree = "<group>"; };
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 = "<group>"; };
5AF0C4102489987500CD4DAE /* ZitiClaims.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZitiClaims.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
50 changes: 50 additions & 0 deletions lib/ZitiHostConfigV1.swift
Original file line number Diff line number Diff line change
@@ -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?
}
10 changes: 9 additions & 1 deletion lib/ZitiInterceptConfigV1.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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?
}
8 changes: 7 additions & 1 deletion lib/ZitiService.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<ziti_service>?
Expand All @@ -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<ziti_service>) {
self.cService = cService
Expand All @@ -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<T>(_ type: T.Type, _ zs: inout ziti_service) -> T? where T:Decodable, T:ZitiConfig {
Expand Down
2 changes: 1 addition & 1 deletion lib/ZitiTunnelClientConfigV1.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 5 additions & 5 deletions lib/ZitiTunnelServerConfigV1.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ZitiUrlClientConfigV1.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
13 changes: 7 additions & 6 deletions lib/ZitiUrlProtocol.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) }
Expand All @@ -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)")
}
}

Expand All @@ -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)
Expand Down

0 comments on commit 2203bac

Please sign in to comment.