feat: add onion domain ATS exception rule. resolve #338

This commit is contained in:
CMK 2022-03-16 02:02:28 +08:00
parent 08a603c2b3
commit e6ee02b2b9
9 changed files with 75 additions and 12 deletions

View File

@ -7,7 +7,7 @@
<key>AppShared.xcscheme_^#shared#^_</key> <key>AppShared.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>27</integer> <integer>20</integer>
</dict> </dict>
<key>CoreDataStack.xcscheme_^#shared#^_</key> <key>CoreDataStack.xcscheme_^#shared#^_</key>
<dict> <dict>
@ -102,7 +102,7 @@
<key>MastodonIntent.xcscheme_^#shared#^_</key> <key>MastodonIntent.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>28</integer> <integer>21</integer>
</dict> </dict>
<key>MastodonIntents.xcscheme_^#shared#^_</key> <key>MastodonIntents.xcscheme_^#shared#^_</key>
<dict> <dict>
@ -122,7 +122,7 @@
<key>ShareActionExtension.xcscheme_^#shared#^_</key> <key>ShareActionExtension.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>26</integer> <integer>19</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key> <key>SuppressBuildableAutocreation</key>

View File

@ -55,6 +55,15 @@
"version": "1.2.0" "version": "1.2.0"
} }
}, },
{
"package": "FLAnimatedImage",
"repositoryURL": "https://github.com/Flipboard/FLAnimatedImage.git",
"state": {
"branch": null,
"revision": "e7f9fd4681ae41bf6f3056db08af4f401d61da52",
"version": "1.0.16"
}
},
{ {
"package": "FPSIndicator", "package": "FPSIndicator",
"repositoryURL": "https://github.com/MainasuK/FPSIndicator.git", "repositoryURL": "https://github.com/MainasuK/FPSIndicator.git",
@ -207,6 +216,15 @@
"revision": "d0470491f56e734731bbf77991944c0dfdee3e0e", "revision": "d0470491f56e734731bbf77991944c0dfdee3e0e",
"version": "2.6.1" "version": "2.6.1"
} }
},
{
"package": "UITextView+Placeholder",
"repositoryURL": "https://github.com/MainasuK/UITextView-Placeholder.git",
"state": {
"branch": null,
"revision": "20f513ded04a040cdf5467f0891849b1763ede3b",
"version": "1.4.1"
}
} }
] ]
}, },

View File

@ -2,6 +2,19 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>onion</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
<key>CADisableMinimumFrameDurationOnPhone</key> <key>CADisableMinimumFrameDurationOnPhone</key>
<true/> <true/>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>

View File

@ -148,7 +148,7 @@ extension NotificationTimelineViewModel {
guard let authenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { return } guard let authenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
isLoadingLatest = true isLoadingLatest = true
defer{ isLoadingLatest = false } defer { isLoadingLatest = false }
do { do {
_ = try await context.apiService.notifications( _ = try await context.apiService.notifications(

View File

@ -16,7 +16,8 @@ import MastodonSDK
extension APIService { extension APIService {
private static func webFingerEndpointURL(domain: String) -> URL { private static func webFingerEndpointURL(domain: String) -> URL {
return URL(string: "https://\(domain)/")!
return URL(string: "\(URL.httpScheme(domain: domain))://\(domain)/")!
.appendingPathComponent(".well-known") .appendingPathComponent(".well-known")
.appendingPathComponent("webfinger") .appendingPathComponent("webfinger")
} }

View File

@ -74,27 +74,27 @@ extension Mastodon.API {
}() }()
static func oauthEndpointURL(domain: String) -> URL { static func oauthEndpointURL(domain: String) -> URL {
return URL(string: "https://" + domain + "/oauth/")! return URL(string: "\(URL.httpScheme(domain: domain))://" + domain + "/oauth/")!
} }
static func endpointURL(domain: String) -> URL { static func endpointURL(domain: String) -> URL {
return URL(string: "https://" + domain + "/api/v1/")! return URL(string: "\(URL.httpScheme(domain: domain))://" + domain + "/api/v1/")!
} }
static func endpointV2URL(domain: String) -> URL { static func endpointV2URL(domain: String) -> URL {
return URL(string: "https://" + domain + "/api/v2/")! return URL(string: "\(URL.httpScheme(domain: domain))://" + domain + "/api/v2/")!
} }
static let joinMastodonEndpointURL = URL(string: "https://api.joinmastodon.org/")! static let joinMastodonEndpointURL = URL(string: "https://api.joinmastodon.org/")!
public static func resendEmailURL(domain: String) -> URL { public static func resendEmailURL(domain: String) -> URL {
return URL(string: "https://" + domain + "/auth/confirmation/new")! return URL(string: "\(URL.httpScheme(domain: domain))://" + domain + "/auth/confirmation/new")!
} }
public static func serverRulesURL(domain: String) -> URL { public static func serverRulesURL(domain: String) -> URL {
return URL(string: "https://" + domain + "/about/more")! return URL(string: "\(URL.httpScheme(domain: domain))://" + domain + "/about/more")!
} }
public static func privacyURL(domain: String) -> URL { public static func privacyURL(domain: String) -> URL {
return URL(string: "https://" + domain + "/terms")! return URL(string: "\(URL.httpScheme(domain: domain))://" + domain + "/terms")!
} }
} }

View File

@ -0,0 +1,14 @@
//
// URL.swift
//
//
// Created by MainasuK on 2022-3-16.
//
import Foundation
extension URL {
public static func httpScheme(domain: String) -> String {
return domain.hasSuffix(".onion") ? "http" : "https"
}
}

View File

@ -22,7 +22,7 @@ extension MastodonSDKTests {
os_log("%{public}s[%{public}ld], %{public}s: (%s) authorizeURL %s", ((#file as NSString).lastPathComponent), #line, #function, domain, authorizeURL.absoluteString) os_log("%{public}s[%{public}ld], %{public}s: (%s) authorizeURL %s", ((#file as NSString).lastPathComponent), #line, #function, domain, authorizeURL.absoluteString)
XCTAssertEqual( XCTAssertEqual(
authorizeURL.absoluteString, authorizeURL.absoluteString,
"https://\(domain)/oauth/authorize?response_type=code&client_id=StubClientID&redirect_uri=mastodon://joinmastodon.org/oauth&scope=read%20write%20follow%20push" "\(URL.httpScheme(domain: domain))://\(domain)/oauth/authorize?response_type=code&client_id=StubClientID&redirect_uri=mastodon://joinmastodon.org/oauth&scope=read%20write%20follow%20push"
) )
} }

View File

@ -8,6 +8,7 @@
import XCTest import XCTest
@testable import Mastodon @testable import Mastodon
@MainActor
class MastodonTests: XCTestCase { class MastodonTests: XCTestCase {
override func setUpWithError() throws { override func setUpWithError() throws {
@ -43,4 +44,20 @@ extension MastodonTests {
} }
wait(for: [expectation], timeout: 10) wait(for: [expectation], timeout: 10)
} }
@available(iOS 15.0, *)
func testConnectOnion() async throws {
let request = URLRequest(
url: URL(string: "http://a232ncr7jexk2chvubaq2v6qdizbocllqap7mnn7w7vrdutyvu32jeyd.onion/@k0gen")!,
cachePolicy: .reloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 10
)
do {
let data = try await URLSession.shared.data(for: request, delegate: nil)
print(data)
} catch {
debugPrint(error)
assertionFailure(error.localizedDescription)
}
}
} }