mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
Swift
62 lines
2.0 KiB
Swift
2 years ago
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||
2 years ago
|
//
|
||
|
// stringlint:disable
|
||
5 years ago
|
|
||
|
import Foundation
|
||
|
|
||
2 years ago
|
public enum ContentProxy {
|
||
5 years ago
|
|
||
2 years ago
|
public static func sessionConfiguration() -> URLSessionConfiguration {
|
||
5 years ago
|
let configuration = URLSessionConfiguration.ephemeral
|
||
|
let proxyHost = "contentproxy.signal.org"
|
||
|
let proxyPort = 443
|
||
|
configuration.connectionProxyDictionary = [
|
||
|
"HTTPEnable": 1,
|
||
|
"HTTPProxy": proxyHost,
|
||
|
"HTTPPort": proxyPort,
|
||
|
"HTTPSEnable": 1,
|
||
|
"HTTPSProxy": proxyHost,
|
||
|
"HTTPSPort": proxyPort
|
||
|
]
|
||
|
return configuration
|
||
|
}
|
||
|
|
||
|
static let userAgent = "Signal iOS (+https://signal.org/download)"
|
||
|
|
||
2 years ago
|
public static func configureProxiedRequest(request: inout URLRequest) -> Bool {
|
||
5 years ago
|
request.addValue(userAgent, forHTTPHeaderField: "User-Agent")
|
||
|
|
||
|
padRequestSize(request: &request)
|
||
|
|
||
|
guard let url = request.url,
|
||
|
let scheme = url.scheme,
|
||
|
scheme.lowercased() == "https" else {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
2 years ago
|
public static func padRequestSize(request: inout URLRequest) {
|
||
5 years ago
|
// Generate 1-64 chars of padding.
|
||
|
let paddingLength: Int = 1 + Int(arc4random_uniform(64))
|
||
|
let padding = self.padding(withLength: paddingLength)
|
||
|
assert(padding.count == paddingLength)
|
||
|
request.addValue(padding, forHTTPHeaderField: "X-SignalPadding")
|
||
|
}
|
||
|
|
||
2 years ago
|
private static func padding(withLength length: Int) -> String {
|
||
5 years ago
|
// Pick a random ASCII char in the range 48-122
|
||
|
var result = ""
|
||
|
// Min and max values, inclusive.
|
||
|
let minValue: UInt32 = 48
|
||
|
let maxValue: UInt32 = 122
|
||
|
for _ in 1...length {
|
||
|
let value = minValue + arc4random_uniform(maxValue - minValue + 1)
|
||
|
assert(value >= minValue)
|
||
|
assert(value <= maxValue)
|
||
|
result += String(UnicodeScalar(UInt8(value)))
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
}
|