Skip to content

Commit

Permalink
Setup cocoapod
Browse files Browse the repository at this point in the history
  • Loading branch information
tadaskay committed Mar 23, 2023
1 parent 2fec12a commit 338ee5b
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 437 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

.DS_Store
.idea
.vscode

## Build generated
build/
lib
DerivedData

## Various settings
Expand Down
24 changes: 24 additions & 0 deletions Assets/ios/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>en</string>
<key>CFBundleExecutable</key>
<string>libwg-go</string>
<key>CFBundleIdentifier</key>
<string>network.mysterium.wireguardkit.ios</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>libwg-go-ios</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>12.0</string>
</dict>
</plist>
24 changes: 24 additions & 0 deletions Assets/macos/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>en</string>
<key>CFBundleExecutable</key>
<string>libwg-go</string>
<key>CFBundleIdentifier</key>
<string>network.mysterium.wireguardkit.macos</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>libwg-go-macos</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/Logging/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Foundation
import os.log

public class Logger {
class Logger {
enum LoggerError: Error {
case openFailure
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum PacketTunnelProviderError: String, Error {
case couldNotSetNetworkSettings
}

extension NETunnelProviderProtocol {
public extension NETunnelProviderProtocol {
convenience init?(tunnelConfiguration: TunnelConfiguration, previouslyFrom old: NEVPNProtocol? = nil) {
self.init()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import Foundation

extension TunnelConfiguration {
public extension TunnelConfiguration {

enum ParserState {
case inInterfaceSection
Expand Down
4 changes: 2 additions & 2 deletions Sources/WireGuardApp/Tunnel/TunnelsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ private func lastErrorTextFromNetworkExtension(for tunnel: TunnelContainer) -> (
return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFailureMessage"))
}

class TunnelContainer: NSObject {
public class TunnelContainer: NSObject {
@objc dynamic var name: String
@objc dynamic var status: TunnelStatus

Expand Down Expand Up @@ -724,7 +724,7 @@ class TunnelContainer: NSObject {
}
}

extension NETunnelProviderManager {
public extension NETunnelProviderManager {
private static var cachedConfigKey: UInt8 = 0

var tunnelConfiguration: TunnelConfiguration? {
Expand Down
30 changes: 18 additions & 12 deletions Sources/WireGuardNetworkExtension/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@ import Foundation
import NetworkExtension
import os

class PacketTunnelProvider: NEPacketTunnelProvider {
open class WireGuardTunnelProvider: NEPacketTunnelProvider {

private lazy var adapter: WireGuardAdapter = {
return WireGuardAdapter(with: self) { logLevel, message in
wg_log(logLevel.osLogLevel, message: message)
}
}()

override func startTunnel(options: [String: NSObject]?, completionHandler: @escaping (Error?) -> Void) {
open override func startTunnel(options: [String: NSObject]?, completionHandler: @escaping (Error?) -> Void) {
guard let wgcfg = options?["cfg"] as? String else {
wg_log(.error, message: "Could not get wgcfg")
completionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
return
}
let tunnelConfiguration: TunnelConfiguration
do {
tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: wgcfg)
} catch let error {
wg_log(.error, message: "Could not create tunnel configuration: \(error)")
completionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
return
}
let activationAttemptId = options?["activationAttemptId"] as? String
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)

Logger.configureGlobal(tagged: "NET", withFilePath: FileManager.logFileURL?.path)

wg_log(.info, message: "Starting tunnel from the " + (activationAttemptId == nil ? "OS directly, rather than the app" : "app"))

guard let tunnelProviderProtocol = self.protocolConfiguration as? NETunnelProviderProtocol,
let tunnelConfiguration = tunnelProviderProtocol.asTunnelConfiguration() else {
errorNotifier.notify(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
completionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
return
}

// Start the tunnel
adapter.start(tunnelConfiguration: tunnelConfiguration) { adapterError in
guard let adapterError = adapterError else {
Expand Down Expand Up @@ -69,7 +75,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
}

override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
open override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
wg_log(.info, staticMessage: "Stopping tunnel")

adapter.stop { error in
Expand All @@ -89,7 +95,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
}

override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) {
open override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) {
guard let completionHandler = completionHandler else { return }

if messageData.count == 1 && messageData[0] == 0 {
Expand All @@ -106,7 +112,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
}

extension WireGuardLogLevel {
public extension WireGuardLogLevel {
var osLogLevel: OSLogType {
switch self {
case .verbose:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include "../WireGuardKitC/WireGuardKitC.h"
#include "../WireGuardKitGo/wireguard.h"
#include "ringlogger.h"
// #include "WireGuardKitC.h"
// #include "wireguard.h"
// #include "ringlogger.h"
Loading

0 comments on commit 338ee5b

Please sign in to comment.