Skip to content

Commit 7ca4654

Browse files
committed
feat: 1.3.0
1 parent 92f703e commit 7ca4654

7 files changed

Lines changed: 52 additions & 16 deletions

File tree

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ LOCAL_USERNAME = user
1111
LOCAL_PASSWORD = passw0rd
1212
LOCAL_HOST = 127.0.0.1
1313
LOCAL_PORT = 8080
14+
SSLKEYLOGFILE = ./keys.log

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.3.0
2+
3+
- Add support for `SSLKEYLOGFILE`.
4+
- Fix internal auth leak to remote server.
5+
16
# 1.2.1
27

38
- Fix HTTP_PROXY variable.

ReadMe.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ It will help you to keep private credentials out of build artifacts.
55

66
## Features
77

8-
* Remote server authentication
9-
* Local server authentication
10-
* Referrer spoofing (pretend that request came from target origin)
11-
* CORS bypass
12-
* HTTP proxy support
8+
* Remote server authentication.
9+
* Local server authentication.
10+
* Referrer spoofing (pretend that request came from target origin).
11+
* CORS bypass.
12+
* HTTP proxy support.
1313
* Adds `Access-Control-Expose-Headers` to allow browser inspect headers.
14+
* Debug TLS connections via `SSLKEYLOGFILE`.
1415

1516
## Usage
1617

bin/main.dart

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ void main(List<String> arguments) async {
9696
..badCertificateCallback = (cert, host, port) =>
9797
trustedRoots.contains(String.fromCharCodes(cert.sha1));
9898

99+
// Allow SSL debugging
100+
if (config.sslKeyLogFile case final path?) {
101+
final keyLog = File(path)
102+
..createSync(recursive: true);
103+
client.keyLog = (line) =>
104+
keyLog.writeAsStringSync(line, mode: FileMode.append);
105+
}
106+
99107
// Apply HTTP proxy
100108
if (config.proxy case final Uri proxy) {
101109
final credentials = proxy.httpClientCredentials;
@@ -127,7 +135,8 @@ void main(List<String> arguments) async {
127135
response
128136
..contentLength = 0
129137
..statusCode = HttpStatus.ok
130-
..close();
138+
..close()
139+
.ignore();
131140
return;
132141
}
133142

@@ -141,7 +150,8 @@ void main(List<String> arguments) async {
141150
..headers.add(HttpHeaders.wwwAuthenticateHeader, 'Basic realm=Protected')
142151
..headers.contentType = ContentType.text
143152
..write('PROXY///ERROR///UNAUTHORIZED')
144-
..close();
153+
..close()
154+
.ignore();
145155
return;
146156
}
147157
}
@@ -159,11 +169,6 @@ void main(List<String> arguments) async {
159169
.then((requestToRemote) async {
160170
requestToRemote.followRedirects = false;
161171

162-
// Remote server auth
163-
final remoteBasicAuth = config.remote.basicAuth;
164-
if (remoteBasicAuth != null)
165-
requestToRemote.headers.add(HttpHeaders.authorizationHeader, remoteBasicAuth);
166-
167172
request.headers.forEach((headerName, headerValues) {
168173
// Filter out headers
169174
if (!headersNotToForwardToRemote.contains(headerName)) {
@@ -181,14 +186,19 @@ void main(List<String> arguments) async {
181186
}
182187
});
183188

189+
// Remote server auth
190+
final remoteBasicAuth = config.remote.basicAuth;
191+
if (remoteBasicAuth != null)
192+
requestToRemote.headers.set(HttpHeaders.authorizationHeader, remoteBasicAuth);
193+
184194
// If there's content pipe request body
185195
if (request.contentLength > 0)
186196
await requestToRemote.addStream(request);
187197

188198
return requestToRemote.close();
189199
})
190200
.then(
191-
(remoteResponse) async {
201+
(remoteResponse) {
192202
stdout.writeln('[$requestId] Remote response: ${remoteResponse.statusCode}');
193203
remoteResponse.headers.forEach((headerName, headerValues) {
194204
// Filter out headers
@@ -240,8 +250,10 @@ void main(List<String> arguments) async {
240250
..headers.contentType = ContentType.text
241251
..writeln('PROXY///ERROR///INTERNAL')
242252
..write(error)
243-
..close();
253+
..close()
254+
.ignore();
244255
},
245-
);
256+
)
257+
.ignore();
246258
});
247259
}

lib/config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ class Config {
77
required this.local,
88
required this.remote,
99
this.proxy,
10+
this.sslKeyLogFile,
1011
});
1112

1213
factory Config.load(String? path) {
1314
if (path != null && File(path).existsSync())
1415
dotenv.load([ path, ]);
1516

1617
final proxy = getUri('HTTP_PROXY', true);
18+
19+
final sslKeyLogFile = getString('SSLKEYLOGFILE');
20+
1721
final local = getUri('LOCAL')
1822
?? Uri.http('127.0.0.1:8080');
1923

@@ -22,12 +26,14 @@ class Config {
2226

2327
return Config._(
2428
proxy: proxy,
29+
sslKeyLogFile: sslKeyLogFile,
2530
local: local,
2631
remote: remote,
2732
);
2833
}
2934

3035
final Uri? proxy;
36+
final String? sslKeyLogFile;
3137
final Uri local;
3238
final Uri remote;
3339

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ publish_to: none
22

33
name: dev_mirror
44
description: Development proxy for accessing private APIs.
5-
version: 1.2.1
5+
version: 1.3.0
66
homepage: https://github.com/Zekfad/dev-mirror
77

88
environment:

workspace.code-workspace

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@
99
"dart-code.dart-code",
1010
],
1111
},
12+
"launch": {
13+
"version": "0.2.0",
14+
"configurations": [
15+
{
16+
"name": "Dart",
17+
"type": "dart",
18+
"request": "launch",
19+
"program": "bin/main.dart",
20+
},
21+
],
22+
},
1223
}

0 commit comments

Comments
 (0)