Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add dylib downloader and validator#16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 17 commits intomainfromethan/dylib-download
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
3563eb4
chore: add dylib downloader and validator
ethanndicksonJan 7, 2025
48b35f0
fmt
ethanndicksonJan 7, 2025
f602fa1
http test server -> mocked requests
ethanndicksonJan 8, 2025
8b60368
undo entitlements change
ethanndicksonJan 8, 2025
6398b00
fixup tunnel
ethanndicksonJan 8, 2025
fb36b59
fixup tunnel
ethanndicksonJan 8, 2025
9e1a956
fixup tunnel
ethanndicksonJan 8, 2025
e6208e8
fixup downloader
ethanndicksonJan 8, 2025
ce4f0da
flip recv and send
ethanndicksonJan 8, 2025
8453170
remove hardcoded bundle identifiers
ethanndicksonJan 8, 2025
5fb8cdd
review
ethanndicksonJan 9, 2025
bfb98f0
200 resp only
ethanndicksonJan 9, 2025
f48b106
sendable downloader
ethanndicksonJan 9, 2025
ae5b3e2
receiver logger name
ethanndicksonJan 9, 2025
4eac98b
localizederror -> error
ethanndicksonJan 9, 2025
844df27
download and validator to functions
ethanndicksonJan 10, 2025
4d0b3da
improve tunnelhandle
ethanndicksonJan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
379 changes: 304 additions & 75 deletionsCoder Desktop/Coder Desktop.xcodeproj/project.pbxproj
View file
Open in desktop

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,9 +62,20 @@
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "961679D82D030E1D00B2B6DF"
BuildableName = "ProtoTests.xctest"
BlueprintName = "ProtoTests"
BlueprintIdentifier = "AA3B3DA02D2D23860099996A"
BuildableName = "VPNLib.framework"
BlueprintName = "VPNLib"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AA3B3DA72D2D23860099996A"
BuildableName = "VPNLibTests.xctest"
BlueprintName = "VPNLibTests"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</TestableReference>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,26 +6,29 @@
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9616792F2CFF117300B2B6DF"
BuildableName = "com.coder.Coder-Desktop.VPN.systemextension"
BlueprintName = "VPN"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "961679D82D030E1D00B2B6DF"
BuildableName = "ProtoTests.xctest"
BlueprintName = "ProtoTests"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All@@ -37,16 +40,6 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "961678FB2CFF100D00B2B6DF"
BuildableName = "Coder Desktop.app"
BlueprintName = "Coder Desktop"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All@@ -57,9 +50,9 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "961678FB2CFF100D00B2B6DF"
BuildableName = "CoderDesktop.app"
BlueprintName = "Coder Desktop"
BlueprintIdentifier = "9616792F2CFF117300B2B6DF"
BuildableName = "com.coder.Coder-Desktop.VPN.systemextension"
BlueprintName = "VPN"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down
8 changes: 4 additions & 4 deletionsCoder Desktop/Coder Desktop.xctestplan
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,15 +19,15 @@
{
"target" : {
"containerPath" : "container:Coder Desktop.xcodeproj",
"identifier" : "961679D82D030E1D00B2B6DF",
"name" : "ProtoTests"
"identifier" : "9616790E2CFF100E00B2B6DF",
"name" : "Coder DesktopTests"
}
},
{
"target" : {
"containerPath" : "container:Coder Desktop.xcodeproj",
"identifier" : "9616790E2CFF100E00B2B6DF",
"name" : "Coder DesktopTests"
"identifier" : "AA3B3DA72D2D23860099996A",
"name" : "VPNLibTests"
}
},
{
Expand Down
6 changes: 3 additions & 3 deletionsCoder Desktop/Coder Desktop/SDK/Client.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import Alamofire
import Foundation

protocol Client {
protocol Client: Sendable {
init(url: URL, token: String?)
func user(_ ident: String) async throws(ClientError) -> User
}
Expand DownExpand Up@@ -114,10 +114,10 @@ struct APIError: Decodable {
struct Response: Decodable {
let message: String
let detail: String?
let validations: [ValidationError]?
let validations: [FieldValidation]?
}

structValidationError: Decodable {
structFieldValidation: Decodable {
let field: String
let detail: String
}
Expand Down
19 changes: 19 additions & 0 deletionsCoder Desktop/VPN/Manager.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import NetworkExtension
import os
import VPNLib

actor Manager {
let ptp: PacketTunnelProvider

var tunnelHandle: TunnelHandle?
var speaker: Speaker<Vpn_ManagerMessage, Vpn_TunnelMessage>?
// TODO: XPC Speaker

private let dest = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.first!.appending(path: "coder-vpn.dylib")
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "manager")

init(with: PacketTunnelProvider) {
ptp = with
}
}
58 changes: 54 additions & 4 deletionsCoder Desktop/VPN/PacketTunnelProvider.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,62 @@
import NetworkExtension
import os

class PacketTunnelProvider: NEPacketTunnelProvider {
override func startTunnel(options _: [String: NSObject]?, completionHandler _: @escaping (Error?) -> Void) {
// Add code here to start the process of connecting the tunnel.
/* From <sys/kern_control.h> */
let CTLIOCGINFO: UInt = 0xC064_4E03

class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "network-extension")
private var manager: Manager?

private var tunnelFileDescriptor: Int32? {
var ctlInfo = 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")
}
}
for fd: Int32 in 0 ... 1024 {
var addr = sockaddr_ctl()
var ret: Int32 = -1
var len = socklen_t(MemoryLayout.size(ofValue: addr))
withUnsafeMutablePointer(to: &addr) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
ret = getpeername(fd, $0, &len)
}
}
if ret != 0 || addr.sc_family != AF_SYSTEM {
continue
}
if ctlInfo.ctl_id == 0 {
ret = ioctl(fd, CTLIOCGINFO, &ctlInfo)
if ret != 0 {
continue
}
}
if addr.sc_id == ctlInfo.ctl_id {
return fd
}
}
return nil
}

override func startTunnel(options _: [String: NSObject]?, completionHandler: @escaping (Error?) -> Void) {
guard manager == nil else {
logger.error("startTunnel called with non-nil Manager")
completionHandler(nil)
return
}
manager = Manager(with: self)
completionHandler(nil)
}

override func stopTunnel(with _: NEProviderStopReason, completionHandler: @escaping () -> Void) {
// Add code here to start the process of stopping the tunnel.
guard manager == nil else {
logger.error("stopTunnel called with nil Manager")
completionHandler()
return
}
manager = nil
completionHandler()
}

Expand Down
91 changes: 91 additions & 0 deletionsCoder Desktop/VPN/TunnelHandle.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
import Foundation
import os

let startSymbol = "OpenTunnel"

actor TunnelHandle {
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "tunnel-handle")

private let tunnelWritePipe: Pipe
private let tunnelReadPipe: Pipe
private let dylibHandle: UnsafeMutableRawPointer

var writeHandle: FileHandle { tunnelReadPipe.fileHandleForWriting }
var readHandle: FileHandle { tunnelWritePipe.fileHandleForReading }

init(dylibPath: URL) throws(TunnelHandleError) {
guard let dylibHandle = dlopen(dylibPath.path, RTLD_NOW | RTLD_LOCAL) else {
throw .dylib(dlerror().flatMap { String(cString: $0) } ?? "UNKNOWN")
}
self.dylibHandle = dylibHandle

guard let startSym = dlsym(dylibHandle, startSymbol) else {
throw .symbol(startSymbol, dlerror().flatMap { String(cString: $0) } ?? "UNKNOWN")
}
let openTunnelFn = unsafeBitCast(startSym, to: OpenTunnel.self)
tunnelReadPipe = Pipe()
tunnelWritePipe = Pipe()
let res = openTunnelFn(tunnelReadPipe.fileHandleForReading.fileDescriptor,
tunnelWritePipe.fileHandleForWriting.fileDescriptor)
guard res == 0 else {
throw .openTunnel(OpenTunnelError(rawValue: res) ?? .unknown)
}
}

// This could be an isolated deinit in Swift 6.1
func close() throws(TunnelHandleError) {
var errs: [Error] = []
if dlclose(dylibHandle) == 0 {
errs.append(TunnelHandleError.dylib(dlerror().flatMap { String(cString: $0) } ?? "UNKNOWN"))
}
do {
try writeHandle.close()
} catch {
errs.append(error)
}
do {
try readHandle.close()
} catch {
errs.append(error)
}
if !errs.isEmpty {
throw .close(errs)
}
}
}

enum TunnelHandleError: Error {
case dylib(String)
case symbol(String, String)
case openTunnel(OpenTunnelError)
case pipe(any Error)
case close([any Error])

var description: String {
switch self {
case let .pipe(err): return "pipe error: \(err)"
case let .dylib(d): return d
case let .symbol(symbol, message): return "\(symbol): \(message)"
case let .openTunnel(error): return "OpenTunnel: \(error.message)"
case let .close(errs): return "close tunnel: \(errs.map(\.localizedDescription).joined(separator: ", "))"
}
}
}

enum OpenTunnelError: Int32 {
case errDupReadFD = -2
case errDupWriteFD = -3
case errOpenPipe = -4
case errNewTunnel = -5
case unknown = -99

var message: String {
switch self {
case .errDupReadFD: return "Failed to duplicate read file descriptor"
case .errDupWriteFD: return "Failed to duplicate write file descriptor"
case .errOpenPipe: return "Failed to open the pipe"
case .errNewTunnel: return "Failed to create a new tunnel"
case .unknown: return "Unknown error code"
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
#ifndef CoderPacketTunnelProvider_Bridging_Header_h
#define CoderPacketTunnelProvider_Bridging_Header_h

// GoInt32 OpenTunnel(GoInt32 cReadFD, GoInt32 cWriteFD);
typedef int(*OpenTunnel)(int, int);

#endif /* CoderPacketTunnelProvider_Bridging_Header_h */
Loading

[8]ページ先頭

©2009-2025 Movatter.jp