You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
validating the expected version can help mitigate an attacker maliciously forcing downgrade to an old version to exploit a vulnerability we’ve since patched
After verifying the digital signature, the NetworkExtension creates a pair of pipes to communicate with the CoderVPN library (via #1 ), and opens the library via dlopen. Then it starts the VPN, passing the pipes.
Over the CoderVPN Protocol it receives
Peer status updates, which it sends to the user application
Logs, which it sends to the system log via native APIs
Network Settings (IP and DNS config) which it uses to configure networking via setTunnelNetworkSettings()
importNetworkExtensionimportos
/* From <sys/kern_control.h> */
letCTLIOCGINFO:UInt=0xc0644e03classPacketTunnelProvider:NEPacketTunnelProvider{privateletlogger=Logger(subsystem:"com.coder.Coder.CoderPacketTunnelProvider",category:"network-extension")privatevardaemon:CoderDaemon?enumTunnelError:Error{caseNoTunnelFileDescriptorcaseFileActionscaseMissingOption(String)caseMissingProtocolConfiguration}privatevartunnelFileDescriptor:Int32?{varctlInfo=ctl_info()withUnsafeMutablePointer(to:&ctlInfo.ctl_name){$0.withMemoryRebound(to:CChar.self,capacity:MemoryLayout.size(ofValue:$0.pointee)){_=strcpy($0,"com.apple.net.utun_control")}}forfd:Int32in0...1024{varaddr=sockaddr_ctl()varret:Int32=-1varlen=socklen_t(MemoryLayout.size(ofValue:addr))withUnsafeMutablePointer(to:&addr){$0.withMemoryRebound(to:sockaddr.self,capacity:1){ret=getpeername(fd,$0,&len)}}ifret!=0||addr.sc_family!=AF_SYSTEM{continue}ifctlInfo.ctl_id==0{ret=ioctl(fd,CTLIOCGINFO,&ctlInfo)ifret!=0{continue}}ifaddr.sc_id==ctlInfo.ctl_id{returnfd}}returnnil}overridefuncstartTunnel(options:[String:NSObject]?,completionHandler:@escaping(Error?)->Void){logger.debug("startTunnel called")letuid=getuid()logger.debug("UID: \(uid)")letnetworkSettings=NEPacketTunnelNetworkSettings(tunnelRemoteAddress:"127.0.0.1")networkSettings.mtu=1280letipv6Settings=NEIPv6Settings(addresses:["fd7a:115c:a1e0::2"],networkPrefixLengths:[48])networkSettings.ipv6Settings=ipv6SettingsletdnsSettings=NEDNSSettings(servers:["fd7a:115c:a1e0::53"])dnsSettings.matchDomains=["coderlan."]networkSettings.dnsSettings=dnsSettingsself.setTunnelNetworkSettings(networkSettings,completionHandler:{_inself.logger.debug("setTunnelNetworkSettings complete")})guardlettunnelFD=tunnelFileDescriptorelse{logger.error("failed to get tunnel file descriptor")completionHandler(TunnelError.NoTunnelFileDescriptor)return}do{guardletproto=self.protocolConfigurationas?NETunnelProviderProtocol,letproviderConfig=proto.providerConfigurationelse{completionHandler(TunnelError.MissingProtocolConfiguration)return}
//let u = providerConfig[kCoderURL] as! String
//self.pingURL(url: u)
letcfg=tryPacketTunnelProvider.optionsToConfig(options:providerConfig)trydaemon=CoderDaemon(tunnelFD:tunnelFD,config:cfg)}catchleterror{completionHandler(error)return}completionHandler(nil)}overridefuncstopTunnel(withreason:NEProviderStopReason,completionHandler:@escaping()->Void){
// Add code here to start the process of stopping the tunnel.
logger.debug("stopTunnel called")daemon?.stop()completionHandler()}overridefunchandleAppMessage(_messageData:Data,completionHandler:((Data?)->Void)?){
// Add code here to handle the message.
iflethandler=completionHandler{handler(messageData)}}overridefuncsleep(completionHandler:@escaping()->Void){
// Add code here to get ready to sleep.
completionHandler()}overridefuncwake(){
// Add code here to wake up.
}staticfuncoptionsToConfig(options:[String:Any])throws->CoderDaemon.Config{guardleturl=options[kCoderURL]as?Stringelse{throwTunnelError.MissingOption(kCoderURL)}guardlettoken=options[kCoderAPIToken]as?Stringelse{throwTunnelError.MissingOption(kCoderAPIToken)}guardletworkspace=options[kCoderWorkspace]as?Stringelse{throwTunnelError.MissingOption(kCoderWorkspace)}returnCoderDaemon.Config(URL:url,APIToken:token,Workspace:workspace)}}
Activity
spikecurtis commentedon Dec 13, 2024
@ethanndickson here is the code from my prototype that opens the dylib and calls functions
With the following bridging header
coder_darwin_arm64.his the header generated bycgofor our dylib.spikecurtis commentedon Dec 13, 2024
And, this is my prototype Packet Tunnel Provider:
chore: embed `Info.plist` in dylib (#15907)
chore: add dylib downloader and validator (#16)
chore: add network extension manager (#18)