@onekeyfe/react-native-sni-connect 6.7.0-46 → 6.7.0-47
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/README.md +111 -73
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
IP address while preserving the original TLS SNI / `Host` of a hostname, so certificate
|
|
5
|
-
chain and hostname verification are still enforced against the real hostname (not the IP).
|
|
3
|
+
# @onekeyfe/react-native-sni-connect
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
**HTTPS requests to a caller-supplied IP while TLS still validates the real hostname.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-sni-connect)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
Connects to a literal IP address you already resolved while preserving the real
|
|
16
|
+
hostname's TLS SNI, `Host` header and certificate validation, so the certificate
|
|
17
|
+
chain is checked against the hostname rather than the IP. Requests are text-only:
|
|
18
|
+
send a UTF-8 body or stream an app-sandbox file through `uploadFile()`. The
|
|
19
|
+
transport is EMASCurl (libcurl) on iOS and OkHttp on Android; there is no Web
|
|
20
|
+
implementation, every request is `https` on port 443, and each connection is
|
|
21
|
+
pinned to a validated public destination.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Pinned destination, real TLS identity** — SNI, `Host` and certificate
|
|
26
|
+
verification use `hostname`; `ip` only chooses the socket target.
|
|
27
|
+
- **Strict request validation** — public IP literals only, relative paths only,
|
|
28
|
+
control characters and module-owned routing headers rejected before I/O.
|
|
29
|
+
- **Bounded concurrency** — 64 active requests per process, 16 per
|
|
30
|
+
`(hostname, ip)` pair, a 256-request queue and `SNI_RESOURCE_LIMIT` on overflow.
|
|
31
|
+
- **Request-id cancellation** — cancel one in-flight request or every request
|
|
32
|
+
owned by the current runtime.
|
|
33
|
+
- **Binary uploads** — `uploadFile()` streams a local file up to 20 MiB;
|
|
34
|
+
`isUploadFileSupported()` feature-detects older native binaries.
|
|
35
|
+
- **Operational hooks** — `clearDNSCache()`, per-pair `getDebugSnapshot()` and a
|
|
36
|
+
`isProxyActiveForUrl()` preflight for adapters.
|
|
8
37
|
|
|
9
38
|
## Installation
|
|
10
39
|
|
|
11
|
-
This package is published as part of the OneKey `app-modules` workspace:
|
|
12
|
-
|
|
13
40
|
```sh
|
|
14
41
|
yarn add @onekeyfe/react-native-sni-connect
|
|
15
42
|
```
|
|
16
43
|
|
|
17
|
-
|
|
18
|
-
|
|
44
|
+
Rebuild the native application after installing; the TurboModule is resolved at
|
|
45
|
+
import time and throws a linking error when the pods or Android native build are
|
|
46
|
+
missing. Android links through autolinking.
|
|
47
|
+
|
|
48
|
+
**iOS.** The pod depends on `EMASCurl`, which lives in Aliyun's spec repo. Add that source
|
|
49
|
+
and keep `EMASCurl` modular in the `Podfile`, then run `pod install`:
|
|
19
50
|
|
|
20
51
|
```ruby
|
|
21
52
|
source 'https://github.com/CocoaPods/Specs.git'
|
|
@@ -28,7 +59,11 @@ target 'YourApp' do
|
|
|
28
59
|
end
|
|
29
60
|
```
|
|
30
61
|
|
|
31
|
-
Android
|
|
62
|
+
**Android.** The application must declare the normal `INTERNET` permission:
|
|
63
|
+
|
|
64
|
+
```xml
|
|
65
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
66
|
+
```
|
|
32
67
|
|
|
33
68
|
## Usage
|
|
34
69
|
|
|
@@ -36,85 +71,88 @@ Android autolinks.
|
|
|
36
71
|
import {
|
|
37
72
|
request,
|
|
38
73
|
cancelRequest,
|
|
39
|
-
cancelAllRequests,
|
|
40
|
-
clearDNSCache,
|
|
41
|
-
getDebugSnapshot,
|
|
42
74
|
isProxyActiveForUrl,
|
|
43
|
-
uploadFile,
|
|
44
|
-
isUploadFileSupported,
|
|
45
75
|
} from '@onekeyfe/react-native-sni-connect';
|
|
46
76
|
|
|
47
77
|
const proxyActive = await isProxyActiveForUrl('https://example.com/api/v1/ping');
|
|
48
|
-
|
|
49
|
-
// Product adapters should avoid entering SNI mode when a per-URL/system proxy
|
|
50
|
-
// is active. Low-level SNI requests still bypass proxies directly.
|
|
51
|
-
}
|
|
78
|
+
// Adapters should avoid SNI mode while a per-URL/system proxy is active.
|
|
52
79
|
|
|
53
80
|
const res = await request({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
hostname: 'example.com', // used for SNI, Host header and certificate validation
|
|
81
|
+
requestId: 'health-check-1', // required only if you want to cancel it
|
|
82
|
+
ip: '93.184.216.34', // public IP literal; private/loopback/metadata are rejected
|
|
83
|
+
hostname: 'example.com', // SNI, Host header and certificate validation
|
|
58
84
|
method: 'GET',
|
|
59
|
-
path: '/api/v1/ping', // relative path only
|
|
85
|
+
path: '/api/v1/ping', // relative path only; absolute URLs are rejected
|
|
60
86
|
headers: { 'Content-Type': 'application/json' },
|
|
61
87
|
timeout: 30_000,
|
|
62
88
|
});
|
|
63
89
|
|
|
64
90
|
console.log(res.status, res.headers, res.data);
|
|
65
91
|
|
|
66
|
-
// Cancellation (requires requestId on the request)
|
|
67
92
|
await cancelRequest('health-check-1');
|
|
68
|
-
await cancelAllRequests();
|
|
69
|
-
|
|
70
|
-
// Drop pinned-IP connections / cached clients
|
|
71
|
-
await clearDNSCache();
|
|
72
|
-
|
|
73
|
-
// Diagnostics for one validated hostname/IP pair
|
|
74
|
-
const snapshot = await getDebugSnapshot({
|
|
75
|
-
hostname: 'example.com',
|
|
76
|
-
ip: '93.184.216.34',
|
|
77
|
-
});
|
|
78
93
|
```
|
|
79
94
|
|
|
80
|
-
`
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
95
|
+
HTTP `4xx` and `5xx` resolve as normal responses; inspect `status`. The caller
|
|
96
|
+
owns the target IP, the request id lifecycle and higher-level retry policy.
|
|
97
|
+
|
|
98
|
+
## API
|
|
99
|
+
|
|
100
|
+
| Export | Signature | Platforms | Description |
|
|
101
|
+
| --- | --- | :-: | --- |
|
|
102
|
+
| `request` | `(config: SniConnectRequest) => Promise<SniConnectResponse>` | iOS, Android | Sends one HTTPS request over the pinned SNI transport. |
|
|
103
|
+
| `uploadFile` | `(config: SniConnectUploadFileRequest) => Promise<SniConnectResponse>` | iOS, Android | Sends a local file body (`POST`/`PUT`, 1 byte–20 MiB). |
|
|
104
|
+
| `isUploadFileSupported` | `() => boolean` | iOS, Android | Reports whether the loaded native module exposes `uploadFile`. |
|
|
105
|
+
| `cancelRequest` | `(requestId: string) => Promise<{ success: boolean }>` | iOS, Android | Cancels the active request with that id. |
|
|
106
|
+
| `cancelAllRequests` | `() => Promise<{ success: boolean }>` | iOS, Android | Cancels every request owned by the current runtime. |
|
|
107
|
+
| `clearDNSCache` | `() => Promise<{ success: boolean }>` | iOS, Android | Evicts cached pinned destinations, clients and idle connections. |
|
|
108
|
+
| `getDebugSnapshot` | `({ hostname, ip }) => Promise<SniConnectDebugSnapshot>` | iOS, Android | Reads active/pending counters and request ids for one pair. |
|
|
109
|
+
| `isProxyActiveForUrl` | `(url: string) => Promise<boolean>` | iOS, Android | Preflight proxy probe; does not enable proxying for SNI requests. |
|
|
110
|
+
|
|
111
|
+
`SniConnectResponse` contains `data` (string), `status`, `statusText`, `headers`
|
|
112
|
+
and an optional `multiValueHeaders`. Limits: 1 MiB body, 8 KiB path/query, 64
|
|
113
|
+
headers / 32 KiB total, 10 MiB response. Exported types include
|
|
114
|
+
`SniConnectRequest`, `SniConnectResponse` and `SniConnectUploadFileRequest`; see
|
|
115
|
+
[`src/NativeSniConnect.ts`](src/NativeSniConnect.ts).
|
|
116
|
+
|
|
117
|
+
## Platform support
|
|
118
|
+
|
|
119
|
+
| Capability | iOS | Android | Web |
|
|
120
|
+
| --- | :-: | :-: | :-: |
|
|
121
|
+
| Pinned-IP request with hostname TLS | ✅ | ✅ | — |
|
|
122
|
+
| String request body | ✅ | ✅ | — |
|
|
123
|
+
| Binary file upload (`uploadFile`) | ✅ | ✅ | — |
|
|
124
|
+
| Per-request and bulk cancellation | ✅ | ✅ | — |
|
|
125
|
+
| Cache clear and debug snapshot | ✅ | ✅ | — |
|
|
126
|
+
| Proxy preflight | ✅ | ✅ | — |
|
|
127
|
+
| Repeated response headers (`multiValueHeaders`) | ⚠️ may collapse | ✅ | — |
|
|
128
|
+
|
|
129
|
+
## Caveats
|
|
130
|
+
|
|
131
|
+
> [!IMPORTANT]
|
|
132
|
+
> `ip` must be a public IP literal — loopback, private, link-local (including
|
|
133
|
+
> cloud metadata), CGNAT, multicast and reserved ranges are rejected. `path`
|
|
134
|
+
> cannot carry a scheme, host or port, and `Host` / `Content-Length` stay
|
|
135
|
+
> module-owned.
|
|
136
|
+
|
|
137
|
+
> [!WARNING]
|
|
138
|
+
> This is a text-response API with a 10 MiB response cap; binary response
|
|
139
|
+
> transport is out of scope. Send binary request bodies with `uploadFile()` and
|
|
140
|
+
> feature-detect it with `isUploadFileSupported()` before use.
|
|
141
|
+
|
|
142
|
+
> [!NOTE]
|
|
143
|
+
> On iOS the EMASCurl version used here exposes response headers as a dictionary
|
|
144
|
+
> view, so repeated headers may already be collapsed before `multiValueHeaders`
|
|
145
|
+
> is built. `isProxyActiveForUrl()` only reports proxy state; SNI transport
|
|
146
|
+
> always bypasses system proxy configuration.
|
|
147
|
+
|
|
148
|
+
## References
|
|
149
|
+
|
|
150
|
+
- [OSCS standard](SPEC.md)
|
|
151
|
+
- [Native upload contract](docs/SPEC.md)
|
|
152
|
+
- [Native interface](src/NativeSniConnect.ts)
|
|
153
|
+
- [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-sni-connect)
|
|
154
|
+
- [Changelog](../../CHANGELOG.md)
|
|
117
155
|
|
|
118
156
|
## License
|
|
119
157
|
|
|
120
|
-
MIT
|
|
158
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-sni-connect",
|
|
3
|
-
"version": "6.7.0-
|
|
3
|
+
"version": "6.7.0-47",
|
|
4
4
|
"description": "A React Native library for SNI-based HTTP requests with DNS caching and request management",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|