Get Process ID (pid) from NEPacketTunnelFlow & sourceAppAuditToken (Always nil)

61 Views Asked by At

I implemented a per-app vpn with packetTunnelProvider on MacOS, fully functional. I would like to get the PID from sourceAppAuditToken but it is always nil.

This is the code:

self.packetFlow.readPacketObjects { packets in
            for packet in packets {                
                if let auditToken = packet.metadata!.sourceAppAuditToken {
                  log.debug("ok")
                } else {
                  log.debug("No audit Token")
                }
            }
        }

I read a lot of answer about this problem but all solved on NEFilterFlow and they don't actually work on PacketTunnelFlow

1

There are 1 best solutions below

0
Muhammad Ali On

please replace

packet.metadata!.sourceAppAuditToken

with

packet.metadata?.sourceAppUniqueIdentifier 

and verify if it is nil or not.

if packet.metadata?.sourceAppUniqueIdentifier == nil { per App VPN is not implemented properly }