maven-proxy 1.0.1
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 +420 -0
- package/bin/maven-proxy.js +573 -0
- package/package.json +54 -0
- package/scripts/truststore.js +96 -0
- package/src/cache/cache-path.js +50 -0
- package/src/cache/downloader.js +350 -0
- package/src/cert/cert-manager.js +194 -0
- package/src/cert/truststore-utils.js +289 -0
- package/src/common/console-log-file.js +62 -0
- package/src/common/daily-log-file.js +79 -0
- package/src/common/domain-match.js +39 -0
- package/src/common/download-log-writer.js +27 -0
- package/src/common/ecosystem.js +64 -0
- package/src/common/java-home.js +328 -0
- package/src/config/config.js +213 -0
- package/src/index.js +93 -0
- package/src/proxy/proxy-connect-handler.js +173 -0
- package/src/proxy/proxy-http-handler.js +187 -0
- package/src/proxy/proxy-server.js +35 -0
- package/src/proxy/upstream-proxy.js +236 -0
- package/src/repo/repo-server.js +120 -0
package/README.md
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
# Maven Proxy Requirements and Usage
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [中文](README-zh.md)
|
|
4
|
+
|
|
5
|
+
## 1. Project Positioning
|
|
6
|
+
|
|
7
|
+
This project is a Maven proxy service used to improve dependency download speed and stability for Maven and Gradle.
|
|
8
|
+
|
|
9
|
+
Core goals:
|
|
10
|
+
- Expose a proxy port for Maven and Gradle clients.
|
|
11
|
+
- Cache dependency files locally and serve cached files on hits.
|
|
12
|
+
- Support HTTPS proxying, including Root CA based certificate issuance for selected domains.
|
|
13
|
+
- Enable multi-threaded downloading for selected domains.
|
|
14
|
+
- Expose a local Maven repository port so Gradle and Maven can consume cached artifacts directly.
|
|
15
|
+
|
|
16
|
+
## 2. Functional Requirements
|
|
17
|
+
|
|
18
|
+
### 2.1 Proxy Service Port
|
|
19
|
+
- The service must start on a configurable proxy port.
|
|
20
|
+
- Maven and Gradle requests should be processed through this proxy endpoint.
|
|
21
|
+
|
|
22
|
+
### 2.2 HTTPS Proxy and Certificate Issuance
|
|
23
|
+
- Support HTTPS proxy scenarios for Maven and Gradle repositories.
|
|
24
|
+
- Generate and persist a local Root CA certificate/key pair.
|
|
25
|
+
- For matched domains, dynamically issue leaf certificates from the local Root CA.
|
|
26
|
+
- For unmatched HTTPS targets, allow passthrough tunnel behavior based on configuration.
|
|
27
|
+
- Reuse persisted CA files across restarts.
|
|
28
|
+
|
|
29
|
+
### 2.3 Cache Hit and Fallback Download
|
|
30
|
+
When a dependency is requested:
|
|
31
|
+
1. Check the local cache path first.
|
|
32
|
+
2. If found and valid, return the cached file.
|
|
33
|
+
3. If missing, download from upstream.
|
|
34
|
+
4. Download to a temporary file with a .temp suffix first.
|
|
35
|
+
5. Atomically rename .temp to final file only after completion and integrity checks.
|
|
36
|
+
6. Return the final cached file.
|
|
37
|
+
|
|
38
|
+
Failure handling:
|
|
39
|
+
- Never leave partial final files.
|
|
40
|
+
- Clean up temporary files after failures.
|
|
41
|
+
|
|
42
|
+
### 2.4 Multi-thread Download by Domain
|
|
43
|
+
- Domain-based strategy is supported for fallback downloads.
|
|
44
|
+
- Matched domains use multi-threaded download.
|
|
45
|
+
- Unmatched domains use single-threaded download.
|
|
46
|
+
- Thread count and threshold are configurable.
|
|
47
|
+
|
|
48
|
+
### 2.5 Local Repository Port
|
|
49
|
+
- Start an additional configurable repository port.
|
|
50
|
+
- Publish local cache as a Maven repository endpoint.
|
|
51
|
+
- Maven and Gradle can use this endpoint directly.
|
|
52
|
+
- If artifact is missing locally, fetch from configured fallback repositories, cache it, then return it.
|
|
53
|
+
|
|
54
|
+
### 2.6 Java Trust Store Support
|
|
55
|
+
- Provide trust store command templates for Java environments.
|
|
56
|
+
- Cover creating/copying trust store, importing Root CA, and verification.
|
|
57
|
+
- Include executable keytool examples for Windows and macOS.
|
|
58
|
+
|
|
59
|
+
### 2.7 Configurability
|
|
60
|
+
At minimum, these settings are configurable:
|
|
61
|
+
- Proxy service port.
|
|
62
|
+
- HTTPS proxy toggle.
|
|
63
|
+
- MITM domain matching rules.
|
|
64
|
+
- Root CA certificate and key paths.
|
|
65
|
+
- Local repository publish port.
|
|
66
|
+
- Cache directory.
|
|
67
|
+
- Multi-thread downloader options.
|
|
68
|
+
- Multi-thread domain matching rules.
|
|
69
|
+
- Trust store settings (path, alias, password behavior).
|
|
70
|
+
|
|
71
|
+
## 3. Main Flow
|
|
72
|
+
|
|
73
|
+
1. Client requests dependency through proxy port.
|
|
74
|
+
2. If HTTPS and host matches MITM rules, TLS is handled with Root CA issued certificate.
|
|
75
|
+
3. Service checks local cache.
|
|
76
|
+
4. On cache hit, return cached file.
|
|
77
|
+
5. On cache miss, fallback download begins.
|
|
78
|
+
6. Write to .temp first.
|
|
79
|
+
7. Verify integrity and atomically rename to final file.
|
|
80
|
+
8. Return final file.
|
|
81
|
+
9. Cached files are also available through repository port.
|
|
82
|
+
|
|
83
|
+
## 4. Java Trust Store Commands (Windows)
|
|
84
|
+
|
|
85
|
+
1. Copy default JDK cacerts to project trust store:
|
|
86
|
+
|
|
87
|
+
```powershell
|
|
88
|
+
Copy-Item "$env:JAVA_HOME\\lib\\security\\cacerts" ".\\data\\certs\\proxy-truststore.jks"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
2. Import project Root CA:
|
|
92
|
+
|
|
93
|
+
```powershell
|
|
94
|
+
keytool -importcert -noprompt -trustcacerts `
|
|
95
|
+
-alias maven-proxy-root-ca `
|
|
96
|
+
-file .\\data\\certs\\root-ca.crt `
|
|
97
|
+
-keystore .\\data\\certs\\proxy-truststore.jks `
|
|
98
|
+
-storepass changeit
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
3. Verify imported certificate:
|
|
102
|
+
|
|
103
|
+
```powershell
|
|
104
|
+
keytool -list -v `
|
|
105
|
+
-keystore .\\data\\certs\\proxy-truststore.jks `
|
|
106
|
+
-storepass changeit `
|
|
107
|
+
-alias maven-proxy-root-ca
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
4. JVM runtime flags:
|
|
111
|
+
|
|
112
|
+
```powershell
|
|
113
|
+
-Djavax.net.ssl.trustStore=.\\data\\certs\\proxy-truststore.jks
|
|
114
|
+
-Djavax.net.ssl.trustStorePassword=changeit
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 5. Out of Scope
|
|
118
|
+
|
|
119
|
+
- Authentication and authorization.
|
|
120
|
+
- Complex management UI.
|
|
121
|
+
- Cache eviction/TTL/capacity management.
|
|
122
|
+
|
|
123
|
+
## 6. Acceptance Criteria
|
|
124
|
+
|
|
125
|
+
- Proxy and repository ports both start successfully.
|
|
126
|
+
- Maven and Gradle can download via proxy.
|
|
127
|
+
- HTTPS proxy works; matched domains complete Root CA based MITM flow.
|
|
128
|
+
- Repeated dependency requests hit cache.
|
|
129
|
+
- Missing dependencies can be downloaded and cached.
|
|
130
|
+
- .temp files are used for in-progress downloads.
|
|
131
|
+
- Final files are created only through atomic rename.
|
|
132
|
+
- Multi-thread download is applied on configured domains.
|
|
133
|
+
- Repository port can serve cached dependencies to Maven and Gradle.
|
|
134
|
+
- Trust store operations can import Root CA successfully.
|
|
135
|
+
- Key settings are configurable.
|
|
136
|
+
- Repository fallback supports Maven Central, JitPack, Gradle Plugin Portal, and Google Maven by default.
|
|
137
|
+
|
|
138
|
+
## 7. Optional Future Enhancements
|
|
139
|
+
|
|
140
|
+
- Corrupted cache detection and repair.
|
|
141
|
+
- Better retry and circuit-breaker behavior.
|
|
142
|
+
- Access logs, hit-rate metrics, health checks.
|
|
143
|
+
- Cache cleanup and disk quota management.
|
|
144
|
+
|
|
145
|
+
## 8. Current Implementation and Runtime Guide
|
|
146
|
+
|
|
147
|
+
Source code is in src and uses Node.js ESM imports. Utility scripts are in scripts.
|
|
148
|
+
|
|
149
|
+
Suggested structure:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
src/
|
|
153
|
+
index.js
|
|
154
|
+
config/
|
|
155
|
+
config.js
|
|
156
|
+
common/
|
|
157
|
+
domain-match.js
|
|
158
|
+
cache/
|
|
159
|
+
cache-path.js
|
|
160
|
+
downloader.js
|
|
161
|
+
cert/
|
|
162
|
+
cert-manager.js
|
|
163
|
+
truststore-utils.js
|
|
164
|
+
proxy/
|
|
165
|
+
proxy-server.js
|
|
166
|
+
proxy-http-handler.js
|
|
167
|
+
proxy-connect-handler.js
|
|
168
|
+
upstream-proxy.js
|
|
169
|
+
repo/
|
|
170
|
+
repo-server.js
|
|
171
|
+
scripts/
|
|
172
|
+
truststore.js
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 8.1 Start
|
|
176
|
+
|
|
177
|
+
1. Install dependencies:
|
|
178
|
+
|
|
179
|
+
```powershell
|
|
180
|
+
npm install
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
2. Configure environment variables as needed.
|
|
184
|
+
|
|
185
|
+
Notes:
|
|
186
|
+
- Development mode (default): npm start loads .env first, then .evn as fallback alias.
|
|
187
|
+
- User mode (CLI default): npx maven-proxy or global command uses ~/maven-proxy/config.
|
|
188
|
+
- Override mode with MAVEN_PROXY_CONFIG_MODE as development or user.
|
|
189
|
+
- Override config file path with MAVEN_PROXY_CONFIG_FILE.
|
|
190
|
+
- JAVA_HOME supports auto-detection:
|
|
191
|
+
- macOS: /usr/libexec/java_home
|
|
192
|
+
- Windows: where java, then common JDK install paths
|
|
193
|
+
- Linux: which java, then common JDK install directories
|
|
194
|
+
|
|
195
|
+
Useful Java path commands:
|
|
196
|
+
- macOS/Linux: echo $JAVA_HOME, which java, /usr/libexec/java_home (macOS only)
|
|
197
|
+
- Windows cmd: echo %JAVA_HOME%, where java
|
|
198
|
+
- Windows PowerShell: $env:JAVA_HOME, Get-Command java
|
|
199
|
+
|
|
200
|
+
3. Start service:
|
|
201
|
+
|
|
202
|
+
```powershell
|
|
203
|
+
npm start
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Default ports:
|
|
207
|
+
- Proxy: 8080 (override with PROXY_PORT)
|
|
208
|
+
- Repository: 8081 (override with REPO_PORT)
|
|
209
|
+
|
|
210
|
+
### 8.2 Implemented Features
|
|
211
|
+
|
|
212
|
+
- HTTP and HTTPS proxy entry.
|
|
213
|
+
- Domain-based HTTPS MITM with Root CA issued leaf certs.
|
|
214
|
+
- Temporary file download + integrity check + atomic rename.
|
|
215
|
+
- Multi-thread download with thresholds.
|
|
216
|
+
- Upstream proxy support for outbound requests and CONNECT.
|
|
217
|
+
- npm proxy support for registry metadata and tarballs.
|
|
218
|
+
- Ecosystem-separated cache directories: cache/maven, cache/npm, cache/generic.
|
|
219
|
+
- Dedicated daily logs with retention.
|
|
220
|
+
- Local cache published as Maven repository.
|
|
221
|
+
- Trust store scripts and commands:
|
|
222
|
+
- npm run truststore:print
|
|
223
|
+
- npm run truststore:init
|
|
224
|
+
- npm run truststore:merge -- --source <src.jks> --target <dest.jks>
|
|
225
|
+
|
|
226
|
+
### 8.3 Minimal Validation Commands (Windows)
|
|
227
|
+
|
|
228
|
+
1. Proxy download test (first MISS, second HIT):
|
|
229
|
+
|
|
230
|
+
```powershell
|
|
231
|
+
curl.exe -k -sS -D - -o NUL -x http://127.0.0.1:8080 https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.pom
|
|
232
|
+
curl.exe -k -sS -D - -o NUL -x http://127.0.0.1:8080 https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.pom
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
2. Repository port cache access:
|
|
236
|
+
|
|
237
|
+
```powershell
|
|
238
|
+
curl.exe -sS -D - -o NUL http://127.0.0.1:8081/maven2/junit/junit/4.13.2/junit-4.13.2.pom
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
3. Ensure no leftover .temp files:
|
|
242
|
+
|
|
243
|
+
```powershell
|
|
244
|
+
Get-ChildItem -Recurse -File .\data\cache -Filter '*.temp'
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
4. npm proxy validation:
|
|
248
|
+
|
|
249
|
+
```powershell
|
|
250
|
+
curl.exe -k -sS -D - -o NUL -x http://127.0.0.1:8080 https://registry.npmjs.org/lodash
|
|
251
|
+
curl.exe -k -sS -D - -o NUL -x http://127.0.0.1:8080 https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### 8.4 Upstream Proxy Settings
|
|
255
|
+
|
|
256
|
+
Environment variables:
|
|
257
|
+
- UPSTREAM_PROXY_URL: generic upstream proxy URL.
|
|
258
|
+
- UPSTREAM_HTTP_PROXY_URL: upstream proxy for HTTP.
|
|
259
|
+
- UPSTREAM_HTTPS_PROXY_URL: upstream proxy for HTTPS.
|
|
260
|
+
- UPSTREAM_NO_PROXY: domains that bypass upstream proxy.
|
|
261
|
+
- UPSTREAM_IGNORE_DOMAINS: ignored domains, wildcard supported.
|
|
262
|
+
- REPO_FALLBACK_REPOS: repository fallback list.
|
|
263
|
+
- NPM_REGISTRY_DOMAINS: npm domains for ecosystem routing.
|
|
264
|
+
- MAVEN_REPO_DOMAINS: maven domains for ecosystem routing.
|
|
265
|
+
- HTTPS_MITM_DOMAINS: MITM domain list (includes registry.npmjs.org by default).
|
|
266
|
+
- DOWNLOAD_LOG_DIR: log directory.
|
|
267
|
+
- LOG_RETENTION_DAYS: number of days to retain logs.
|
|
268
|
+
- MAVEN_PROXY_CONFIG_MODE: development or user.
|
|
269
|
+
- MAVEN_PROXY_CONFIG_FILE: explicit config file path.
|
|
270
|
+
|
|
271
|
+
Rules:
|
|
272
|
+
- UPSTREAM_NO_PROXY and UPSTREAM_IGNORE_DOMAINS are merged.
|
|
273
|
+
- Exact and wildcard domains are supported.
|
|
274
|
+
|
|
275
|
+
Priority:
|
|
276
|
+
1. HTTP: UPSTREAM_HTTP_PROXY_URL, then UPSTREAM_PROXY_URL.
|
|
277
|
+
2. HTTPS: UPSTREAM_HTTPS_PROXY_URL, then UPSTREAM_PROXY_URL, then UPSTREAM_HTTP_PROXY_URL.
|
|
278
|
+
|
|
279
|
+
### 8.5 Trust Store Merge
|
|
280
|
+
|
|
281
|
+
Use merge command to combine trust stores.
|
|
282
|
+
|
|
283
|
+
Help:
|
|
284
|
+
|
|
285
|
+
```powershell
|
|
286
|
+
npm run truststore:merge -- --help
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Basic merge:
|
|
290
|
+
|
|
291
|
+
```powershell
|
|
292
|
+
npm run truststore:merge -- \
|
|
293
|
+
--source .\data\certs\source-truststore.jks \
|
|
294
|
+
--target .\data\certs\proxy-truststore.jks \
|
|
295
|
+
--source-pass changeit \
|
|
296
|
+
--target-pass changeit
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Overwrite on alias conflict:
|
|
300
|
+
|
|
301
|
+
```powershell
|
|
302
|
+
npm run truststore:merge -- \
|
|
303
|
+
--source .\data\certs\source-truststore.jks \
|
|
304
|
+
--target .\data\certs\proxy-truststore.jks \
|
|
305
|
+
--source-pass changeit \
|
|
306
|
+
--target-pass changeit \
|
|
307
|
+
--on-conflict overwrite
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Dry-run:
|
|
311
|
+
|
|
312
|
+
```powershell
|
|
313
|
+
npm run truststore:merge -- \
|
|
314
|
+
--source .\data\certs\source-truststore.jks \
|
|
315
|
+
--target .\data\certs\proxy-truststore.jks \
|
|
316
|
+
--source-pass changeit \
|
|
317
|
+
--target-pass changeit \
|
|
318
|
+
--dry-run
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Optional flags:
|
|
322
|
+
- --source-type: default JKS.
|
|
323
|
+
- --target-type: default JKS.
|
|
324
|
+
- --on-conflict: fail or overwrite.
|
|
325
|
+
- --dry-run: validation only.
|
|
326
|
+
|
|
327
|
+
### 8.6 Publish as CLI Tool (npx / global)
|
|
328
|
+
|
|
329
|
+
The project provides executable command maven-proxy.
|
|
330
|
+
|
|
331
|
+
Run with npx:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
npx maven-proxy
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Install globally:
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
npm install -g maven-proxy
|
|
341
|
+
maven-proxy
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Default CLI config path:
|
|
345
|
+
- ~/maven-proxy/config
|
|
346
|
+
|
|
347
|
+
Common commands:
|
|
348
|
+
- maven-proxy --config /path/to/config
|
|
349
|
+
- maven-proxy start --mode development
|
|
350
|
+
- maven-proxy start --mode user
|
|
351
|
+
- maven-proxy init-config --force
|
|
352
|
+
- maven-proxy truststore print
|
|
353
|
+
- maven-proxy truststore init
|
|
354
|
+
- maven-proxy truststore merge --source /path/source.jks --target /path/target.jks
|
|
355
|
+
- maven-proxy doctor
|
|
356
|
+
|
|
357
|
+
Doctor command:
|
|
358
|
+
- Checks config loading, port availability, keytool, JAVA_HOME, cert/truststore paths, and writable log/cache directories.
|
|
359
|
+
- Reports PASS/WARN/FAIL.
|
|
360
|
+
- Returns exit code 2 when FAIL exists.
|
|
361
|
+
|
|
362
|
+
## 9. Client Usage
|
|
363
|
+
|
|
364
|
+
Default proxy port in examples: 8080. Replace with your configured value if different.
|
|
365
|
+
|
|
366
|
+
### 9.1 Gradle: Proxy + trust store
|
|
367
|
+
|
|
368
|
+
1. Initialize trust store (if needed):
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
npm run truststore:init
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
2. Update ~/.gradle/gradle.properties:
|
|
375
|
+
|
|
376
|
+
```properties
|
|
377
|
+
systemProp.http.proxyHost=127.0.0.1
|
|
378
|
+
systemProp.http.proxyPort=8080
|
|
379
|
+
systemProp.https.proxyHost=127.0.0.1
|
|
380
|
+
systemProp.https.proxyPort=8080
|
|
381
|
+
org.gradle.jvmargs=-Djavax.net.ssl.trustStore=/Users/yize/projects/maven-proxy/data/certs/proxy-truststore.jks -Djavax.net.ssl.trustStorePassword=changeit
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
3. Validate:
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
./gradlew --refresh-dependencies dependencies
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### 9.2 npm: Proxy + SSL behavior
|
|
391
|
+
|
|
392
|
+
For local troubleshooting only, you can disable strict SSL temporarily. Recommended long-term approach is to import Root CA and keep strict SSL enabled.
|
|
393
|
+
|
|
394
|
+
Set npm proxy:
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
npm config set proxy http://127.0.0.1:8080
|
|
398
|
+
npm config set https-proxy http://127.0.0.1:8080
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Temporary disable strict SSL:
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
npm config set strict-ssl false
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Validate:
|
|
408
|
+
|
|
409
|
+
```bash
|
|
410
|
+
npm ping
|
|
411
|
+
npm view lodash version
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Restore safer defaults:
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
npm config set strict-ssl true
|
|
418
|
+
npm config delete proxy
|
|
419
|
+
npm config delete https-proxy
|
|
420
|
+
```
|