@onekeyfe/react-native-sni-connect 3.0.81-alpha.7 → 3.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.tsx CHANGED
@@ -1,4 +1,6 @@
1
1
  import NativeSniConnect, {
2
+ type SniConnectDebugSnapshot,
3
+ type SniConnectDebugTarget,
2
4
  type SniConnectRequest,
3
5
  type SniConnectResponse,
4
6
  } from './NativeSniConnect';
@@ -23,12 +25,20 @@ export function clearDNSCache(): Promise<{ success: boolean }> {
23
25
  return NativeSniConnect.clearDNSCache();
24
26
  }
25
27
 
28
+ export function getDebugSnapshot(
29
+ target: SniConnectDebugTarget
30
+ ): Promise<SniConnectDebugSnapshot> {
31
+ return NativeSniConnect.getDebugSnapshot(target);
32
+ }
33
+
26
34
  export function isProxyActiveForUrl(url: string): Promise<boolean> {
27
35
  return NativeSniConnect.isProxyActiveForUrl(url);
28
36
  }
29
37
 
30
38
  export type {
31
39
  SniConnectBodylessMethod,
40
+ SniConnectDebugSnapshot,
41
+ SniConnectDebugTarget,
32
42
  SniConnectMethod,
33
43
  SniConnectOptionalBodyMethod,
34
44
  SniConnectRequest,
@@ -1,58 +0,0 @@
1
- package com.sniconnect
2
-
3
- import java.net.InetAddress
4
- import java.net.Proxy
5
- import java.net.UnknownHostException
6
- import java.util.Locale
7
- import java.util.concurrent.TimeUnit
8
- import okhttp3.ConnectionPool
9
- import okhttp3.Dispatcher
10
- import okhttp3.Dns
11
- import okhttp3.OkHttpClient
12
- import okhttp3.Protocol
13
- import javax.net.ssl.HttpsURLConnection
14
-
15
- object SniPinnedTransport {
16
- @JvmStatic
17
- fun createClient(
18
- ip: String,
19
- hostname: String,
20
- dispatcher: Dispatcher = Dispatcher(),
21
- connectionPool: ConnectionPool = ConnectionPool(),
22
- ): OkHttpClient {
23
- SniConnectValidation.validatePublicIp(ip)
24
- SniConnectValidation.validateHostname(hostname)
25
- val normalizedHostname = hostname.lowercase(Locale.US)
26
- return OkHttpClient.Builder()
27
- .dispatcher(dispatcher)
28
- .connectionPool(connectionPool)
29
- .proxy(Proxy.NO_PROXY)
30
- .protocols(listOf(Protocol.HTTP_1_1))
31
- .connectTimeout(0, TimeUnit.MILLISECONDS)
32
- .readTimeout(0, TimeUnit.MILLISECONDS)
33
- .writeTimeout(0, TimeUnit.MILLISECONDS)
34
- .callTimeout(0, TimeUnit.MILLISECONDS)
35
- .followRedirects(false)
36
- .followSslRedirects(false)
37
- .hostnameVerifier { _, session ->
38
- HttpsURLConnection.getDefaultHostnameVerifier().verify(normalizedHostname, session)
39
- }
40
- .dns(createPinnedDns(ip, normalizedHostname))
41
- .build()
42
- }
43
-
44
- private fun createPinnedDns(ip: String, hostname: String): Dns =
45
- object : Dns {
46
- private val pinnedAddress: InetAddress =
47
- SniConnectValidation.literalToInetAddress(ip)
48
-
49
- override fun lookup(requestedHost: String): List<InetAddress> {
50
- if (requestedHost.lowercase(Locale.US) == hostname) {
51
- return listOf(pinnedAddress)
52
- }
53
- throw UnknownHostException(
54
- "Unexpected host for pinned SNI request: $requestedHost"
55
- )
56
- }
57
- }
58
- }
@@ -1,92 +0,0 @@
1
- import Foundation
2
- import EMASCurl
3
-
4
- struct SniConnectPinnedTransportResources {
5
- let configuration: URLSessionConfiguration
6
- let resolverLease: SniConnectPinnedResolverLease
7
- let delegate: SniConnectSessionInvalidationDelegate
8
- }
9
-
10
- public final class SniConnectPinnedSession {
11
- public let session: URLSession
12
-
13
- init(resources: SniConnectPinnedTransportResources) {
14
- session = URLSession(
15
- configuration: resources.configuration,
16
- delegate: resources.delegate,
17
- delegateQueue: nil
18
- )
19
- }
20
-
21
- public func close() {
22
- session.finishTasksAndInvalidate()
23
- }
24
-
25
- deinit {
26
- close()
27
- }
28
- }
29
-
30
- public enum SniConnectPinnedTransport {
31
- static func makeResources(
32
- hostname: String,
33
- ip: String,
34
- dataDelegate: URLSessionDataDelegate? = nil
35
- ) throws -> SniConnectPinnedTransportResources {
36
- try SniConnectValidation.validateHostname(hostname)
37
- try SniConnectValidation.validatePublicIP(ip)
38
-
39
- let normalizedHostname = hostname.lowercased()
40
- let configuration = URLSessionConfiguration.default
41
- configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
42
- configuration.urlCache = nil
43
- configuration.httpCookieStorage = nil
44
- configuration.httpShouldSetCookies = false
45
- configuration.connectionProxyDictionary = [:]
46
- configuration.shouldUseExtendedBackgroundIdleMode = false
47
-
48
- let curlConfig = EMASCurlConfiguration.default()
49
- curlConfig.httpVersion = .HTTP1
50
- curlConfig.connectTimeoutInterval = 2.5
51
- curlConfig.enableBuiltInGzip = false
52
- curlConfig.enableBuiltInRedirection = false
53
- curlConfig.cacheEnabled = false
54
- curlConfig.certificateValidationEnabled = true
55
- curlConfig.domainNameVerificationEnabled = true
56
- curlConfig.dnsResolver = try PinnedDNSResolverFactory.resolverClass(
57
- hostname: normalizedHostname,
58
- ip: ip
59
- )
60
- EMASCurlProtocol.install(into: configuration, with: curlConfig)
61
-
62
- let resolverLease = SniConnectPinnedResolverLease(
63
- hostname: normalizedHostname,
64
- ip: ip
65
- )
66
- let delegate = SniConnectSessionInvalidationDelegate(
67
- hostname: normalizedHostname,
68
- ip: ip,
69
- resolverLease: resolverLease,
70
- forwardingDataDelegate: dataDelegate
71
- )
72
- return SniConnectPinnedTransportResources(
73
- configuration: configuration,
74
- resolverLease: resolverLease,
75
- delegate: delegate
76
- )
77
- }
78
-
79
- public static func makeSession(
80
- hostname: String,
81
- ip: String,
82
- dataDelegate: URLSessionDataDelegate? = nil
83
- ) throws -> SniConnectPinnedSession {
84
- SniConnectPinnedSession(
85
- resources: try makeResources(
86
- hostname: hostname,
87
- ip: ip,
88
- dataDelegate: dataDelegate
89
- )
90
- )
91
- }
92
- }