Initial project setup - Phases 1-3 complete
This commit is contained in:
14
PacketTunnel/Entitlements/PacketTunnel.entitlements
Normal file
14
PacketTunnel/Entitlements/PacketTunnel.entitlements
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.com.treyt.proxyapp</string>
|
||||
</array>
|
||||
<key>com.apple.developer.networking.networkextension</key>
|
||||
<array>
|
||||
<string>packet-tunnel-provider</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
29
PacketTunnel/Info.plist
Normal file
29
PacketTunnel/Info.plist
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.networkextension.packet-tunnel</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
50
PacketTunnel/PacketTunnelProvider.swift
Normal file
50
PacketTunnel/PacketTunnelProvider.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
import NetworkExtension
|
||||
import ProxyCore
|
||||
|
||||
class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
|
||||
private var proxyServer: ProxyServer?
|
||||
|
||||
override func startTunnel(options: [String: NSObject]? = nil) async throws {
|
||||
// Start the local proxy server
|
||||
let server = ProxyServer()
|
||||
try await server.start()
|
||||
proxyServer = server
|
||||
|
||||
// Configure tunnel to redirect HTTP/HTTPS to our local proxy
|
||||
let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "127.0.0.1")
|
||||
|
||||
let proxySettings = NEProxySettings()
|
||||
proxySettings.httpServer = NEProxyServer(
|
||||
address: ProxyConstants.proxyHost,
|
||||
port: ProxyConstants.proxyPort
|
||||
)
|
||||
proxySettings.httpsServer = NEProxyServer(
|
||||
address: ProxyConstants.proxyHost,
|
||||
port: ProxyConstants.proxyPort
|
||||
)
|
||||
proxySettings.httpEnabled = true
|
||||
proxySettings.httpsEnabled = true
|
||||
proxySettings.matchDomains = [""] // Match all domains
|
||||
settings.proxySettings = proxySettings
|
||||
|
||||
// DNS settings to ensure proper resolution
|
||||
let dnsSettings = NEDNSSettings(servers: ["8.8.8.8", "8.8.4.4"])
|
||||
dnsSettings.matchDomains = [""] // Match all
|
||||
settings.dnsSettings = dnsSettings
|
||||
|
||||
try await setTunnelNetworkSettings(settings)
|
||||
|
||||
IPCManager.shared.post(.extensionStarted)
|
||||
}
|
||||
|
||||
override func stopTunnel(with reason: NEProviderStopReason) async {
|
||||
await proxyServer?.stop()
|
||||
proxyServer = nil
|
||||
IPCManager.shared.post(.extensionStopped)
|
||||
}
|
||||
|
||||
override func handleAppMessage(_ messageData: Data) async -> Data? {
|
||||
// Handle IPC messages from the main app
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user