Skip to content

Commit

Permalink
Option to opt-out the Method Swizzling on WS/WSS Connection (#138)
Browse files Browse the repository at this point in the history
* Able to opt-out the WS/WSS

* Bump 1.23.0
  • Loading branch information
NghiaTranUIT authored Nov 9, 2023
1 parent 4579425 commit 131d757
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 5 additions & 3 deletions Sources/Atlantis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ public final class Atlantis: NSObject {
/// Build version of Atlantis
/// It's essential for Proxyman to known if it's compatible with this version
/// Instead of receving the number from the info.plist, we should hardcode here because the info file doesn't exist in SPM
public static let buildVersion: String = "1.22.0"
public static let buildVersion: String = "1.23.0"

/// Start Swizzle all network functions and monitoring the traffic
/// It also starts looking Bonjour network from Proxyman app.
/// If hostName is nil, Atlantis will find all Proxyman apps in the network. It's useful if we have only one machine for personal usage.
/// If hostName is not nil, Atlantis will try to connect to particular mac machine. It's useful if you have multiple Proxyman.
/// - Parameter hostName: Host name of Mac machine. You can find your current Host Name in Proxyman -> Certificate -> Install on iOS -> By Atlantis -> Show Start Atlantis
@objc public class func start(hostName: String? = nil) {
/// - Parameter shouldCaptureWebSocketTraffic: Determine if Atlantis should perform the Method Swizzling on WS/WSS connection. Default is true.
@objc public class func start(hostName: String? = nil, shouldCaptureWebSocketTraffic: Bool = true) {
// save config
let configuration = Configuration.default(hostName: hostName)

//
Expand All @@ -105,7 +107,7 @@ public final class Atlantis: NSObject {

// Enable the injector
Atlantis.shared.configuration = configuration
Atlantis.shared.injector.injectAllNetworkClasses()
Atlantis.shared.injector.injectAllNetworkClasses(config: NetworkConfiguration(shouldCaptureWebSocketTraffic: shouldCaptureWebSocketTraffic))

// Start transport layer if need
if Atlantis.shared.isEnabledTransportLayer {
Expand Down
24 changes: 19 additions & 5 deletions Sources/NetworkInjector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@

import Foundation

struct NetworkConfiguration {

/// Whether or not Atlantis should perform the Method Swizzling on WS/WSS connection.
let shouldCaptureWebSocketTraffic: Bool

// init
init(shouldCaptureWebSocketTraffic: Bool = true) {
self.shouldCaptureWebSocketTraffic = shouldCaptureWebSocketTraffic
}
}

protocol Injector {

var delegate: InjectorDelegate? { get set }
func injectAllNetworkClasses()
func injectAllNetworkClasses(config: NetworkConfiguration)
}

protocol InjectorDelegate: AnyObject {
Expand All @@ -38,17 +49,17 @@ final class NetworkInjector: Injector {

// MARK: - Internal

func injectAllNetworkClasses() {
func injectAllNetworkClasses(config: NetworkConfiguration = NetworkConfiguration()) {
// Make sure we swizzle *ONCE*
DispatchQueue.once {
injectAllURLSession()
injectAllURLSession(config)
}
}
}

extension NetworkInjector {

private func injectAllURLSession() {
private func injectAllURLSession(_ config: NetworkConfiguration) {

// iOS 8: __NSCFURLSessionConnection
// iOS 9, 10, 11, 12, 13, 14: __NSCFURLLocalSessionConnection
Expand All @@ -66,7 +77,10 @@ extension NetworkInjector {
injectURLSessionUploadTasks()

// Websocket
injectURLSessionWebsocketTasks()
// Able to opt-out the WS/WSS if needed
if config.shouldCaptureWebSocketTraffic {
injectURLSessionWebsocketTasks()
}
}

private func injectIntoURLSessionDelegate(anyClass: AnyClass) {
Expand Down
2 changes: 1 addition & 1 deletion atlantis-proxyman.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "atlantis-proxyman"
spec.version = "1.22.0"
spec.version = "1.23.0"
spec.summary = "A lightweight and powerful iOS framework for intercepting HTTP/HTTPS Traffic"
spec.description = <<-DESC
A lightweight and powerful iOS framework for intercepting HTTP/HTTPS Traffic from your app. No more messing around with proxy, certificate config.
Expand Down

0 comments on commit 131d757

Please sign in to comment.