I am porting existing DPL system on to macOS, which have one key feature: ability to inspect the outgoing traffic of the specified applications (possibly all applications) and to skip the traffic of others not included in the list.
To distinguish traffic of required apps I am trying to use system network extension. Catched traffic should be diverted to the our application that acts like regular proxy which can make 2 desicion: block/terminate connection or allow it.
I was tried app-proxy(NEAppProxyProvider on sext side and NETransparentProxyManager on "client" side) type of network extension.
But I stuck with
Code Block @method handleNewFlow:
How can I divert traffic to my proxy? Documentation says call
Code Block -[NEAppProxyFlow openWithLocalEndpoint:completionHandler:]
on the flow and it's all? Will traffic goes through my proxy? For what purposes are exists methods like Code Block -[NEAppProxyTCPFlow readDataWithCompletionHandler:completionHandler:]
or Code Block -[NEAppProxyTCPFlow writeData:withCompletionHandler:]
?My goal is get network extension that acts like transparent proxy for specified apps and diverts catched traffic to my existing proxy app, which allow or disallow connection.
One more: during experimentation with app-proxy NE I noticed that my VPN turned off when NEAppProxyProvider started. It is unacceptably, so I drew attention on content-filter(NEFilterDataProvider on sext side and NEFilterManager on "client" side) type of NE.
It seems that it works "before" all vpns and proxies which is desired functionality.
But again, I stuck: how organize diverting traffic to my proxy to make decision about connection?
As I understood general algorithm looks like:
Code Block handleNewFlow:(return [NEFilterNewFlowVerdict filterDataVerdictWithFilterInbound:NO peekInboundBytes:0 filterOutbound:YES peekOutboundBytes: ChunkBytesSize]; ) --> handleOutboundDataFromFlow:readBytesStartOffset:readBytes:
and here, in this method I should open connection to my proxy and write data. Am I correct?I am sorry for so complex question, but I am really messed up with all these types of NE provides.
So, summarise: how to divert traffic of specified apps to my proxy that makes decision about termination of connection?