Skip to content

Commit 3a5854c

Browse files
authored
Merge pull request #63 from junkurihara/develop
0.3.4
2 parents c5e1d32 + 96f33d3 commit 3a5854c

File tree

9 files changed

+110
-134
lines changed

9 files changed

+110
-134
lines changed

.github/workflows/release-docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
needs: docker_build_and_push
8282
steps:
8383
- name: check pull_request title
84-
uses: kaisugi/[email protected].0
84+
uses: kaisugi/[email protected].1
8585
id: regex-match
8686
with:
8787
text: ${{ github.event.pull_request.title }}
@@ -102,7 +102,7 @@ jobs:
102102
103103
- name: release
104104
if: ${{ steps.regex-match.outputs.match != ''}}
105-
uses: softprops/action-gh-release@v1
105+
uses: softprops/action-gh-release@v2
106106
with:
107107
files: /tmp/doh-auth-proxy-x86_64-unknown-linux-gnu.tar.gz
108108
name: ${{ github.event.pull_request.title }}

Cargo.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@
33
members = ["proxy-bin", "proxy-lib"]
44
resolver = "2"
55

6+
[workspace.package]
7+
version = "0.3.4"
8+
authors = ["Jun Kurihara"]
9+
homepage = "https://github.com/junkurihara/doh-auth-proxy"
10+
repository = "https://github.com/junkurihara/doh-auth-proxy"
11+
license = "MIT"
12+
readme = "./README.md"
13+
categories = [
14+
"asynchronous",
15+
"network-programming",
16+
"command-line-utilities",
17+
"web-programming::http-client",
18+
]
19+
keywords = [
20+
"dns",
21+
"https",
22+
"dns-over-https",
23+
"doh",
24+
"oblivious-dns-over-https",
25+
"odoh",
26+
"mutualized-oblivious-dns",
27+
"mutualized-odoh",
28+
"modoh",
29+
"proxy",
30+
"authorization",
31+
]
32+
edition = "2021"
33+
publish = false
34+
635
[profile.release]
736
codegen-units = 1
837
incremental = false

proxy-bin/Cargo.toml

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,38 @@
11
[package]
22
name = "doh-auth-proxy"
33
description = "DNS Proxy for DoH, ODoH and Mutualized ODoH with Authorization"
4-
version = "0.3.3"
5-
authors = ["Jun Kurihara"]
6-
homepage = "https://github.com/junkurihara/doh-auth-proxy"
7-
repository = "https://github.com/junkurihara/doh-auth-proxy"
8-
license = "MIT"
9-
readme = "../README.md"
10-
categories = [
11-
"asynchronous",
12-
"network-programming",
13-
"command-line-utilities",
14-
"web-programming::http-client",
15-
]
16-
keywords = [
17-
"dns",
18-
"https",
19-
"dns-over-https",
20-
"doh",
21-
"oblivious-dns-over-https",
22-
"odoh",
23-
"mutualized-oblivious-dns",
24-
"mutualized-odoh",
25-
"modoh",
26-
"proxy",
27-
"authorization",
28-
]
29-
edition = "2021"
30-
publish = false
4+
version.workspace = true
5+
authors.workspace = true
6+
homepage.workspace = true
7+
repository.workspace = true
8+
license.workspace = true
9+
readme.workspace = true
10+
categories.workspace = true
11+
keywords.workspace = true
12+
edition.workspace = true
13+
publish.workspace = true
3114

3215
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
3316

3417
[dependencies]
3518
doh-auth-proxy-lib = { path = "../proxy-lib/" }
3619

37-
anyhow = "1.0.79"
20+
anyhow = "1.0.81"
3821
mimalloc = { version = "*", default-features = false }
39-
serde = { version = "1.0.196", default-features = false, features = ["derive"] }
40-
derive_builder = "0.13.0"
41-
tokio = { version = "1.35.1", default-features = false, features = [
22+
serde = { version = "1.0.197", default-features = false, features = ["derive"] }
23+
derive_builder = "0.20.0"
24+
tokio = { version = "1.36.0", default-features = false, features = [
4225
"net",
4326
"rt-multi-thread",
4427
"time",
4528
"sync",
4629
"macros",
4730
] }
48-
async-trait = "0.1.77"
31+
async-trait = "0.1.78"
4932

5033
# config
51-
clap = { version = "4.4.18", features = ["std", "cargo", "wrap_help"] }
52-
toml = { version = "0.8.8", default-features = false, features = ["parse"] }
34+
clap = { version = "4.5.3", features = ["std", "cargo", "wrap_help"] }
35+
toml = { version = "0.8.12", default-features = false, features = ["parse"] }
5336
hot_reload = "0.1.5"
5437

5538
# logging

proxy-lib/Cargo.toml

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
[package]
22
name = "doh-auth-proxy-lib"
33
description = "DNS Proxy Library for DoH, ODoH and Mutualized ODoH with Authorization"
4-
version = "0.3.3"
5-
authors = ["Jun Kurihara"]
6-
homepage = "https://github.com/junkurihara/doh-auth-proxy"
7-
repository = "https://github.com/junkurihara/doh-auth-proxy"
8-
license = "MIT"
9-
readme = "../README.md"
10-
categories = [
11-
"asynchronous",
12-
"network-programming",
13-
"command-line-utilities",
14-
"web-programming::http-client",
15-
]
16-
keywords = [
17-
"dns",
18-
"https",
19-
"dns-over-https",
20-
"doh",
21-
"oblivious-dns-over-https",
22-
"odoh",
23-
"mutualized-oblivious-dns",
24-
"mutualized-odoh",
25-
"modoh",
26-
"proxy",
27-
"authorization",
28-
]
29-
edition = "2021"
30-
publish = false
4+
version.workspace = true
5+
authors.workspace = true
6+
homepage.workspace = true
7+
repository.workspace = true
8+
license.workspace = true
9+
readme.workspace = true
10+
categories.workspace = true
11+
keywords.workspace = true
12+
edition.workspace = true
13+
publish.workspace = true
14+
3115

3216
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
3317

3418
[dependencies]
3519
rand = "0.8.5"
36-
tokio = { version = "1.35.1", features = [
20+
tokio = { version = "1.36.0", features = [
3721
"net",
3822
"rt-multi-thread",
3923
"time",
@@ -44,11 +28,11 @@ futures = { version = "0.3.30", default-features = false, features = [
4428
"std",
4529
"async-await",
4630
] }
47-
anyhow = "1.0.79"
31+
anyhow = "1.0.81"
4832
tracing = "0.1.40"
49-
thiserror = "1.0.56"
50-
async-trait = "0.1.77"
51-
serde = { version = "1.0.196", features = ["derive"] }
33+
thiserror = "1.0.58"
34+
async-trait = "0.1.78"
35+
serde = { version = "1.0.197", features = ["derive"] }
5236
itertools = "0.12.1"
5337
rustc-hash = "1.1.0"
5438

@@ -62,13 +46,13 @@ cedarwood = "0.4.6"
6246
regex = "1.10.3"
6347

6448
# network
65-
socket2 = "0.5.5"
49+
socket2 = "0.5.6"
6650

6751
# http client
68-
# TODO: change this to hyper-1.0
69-
reqwest = { version = "0.11.23", default-features = false, features = [
52+
reqwest = { version = "0.12.0", default-features = false, features = [
7053
"json",
71-
"trust-dns",
54+
"http2",
55+
"hickory-dns",
7256
"rustls-tls",
7357
] }
7458
url = "2.5.0"

proxy-lib/src/doh_client/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod tests {
182182

183183
#[tokio::test]
184184
async fn test_cache() {
185-
let (stream, sender) = TcpClientStream::<AsyncIoTokioAsStd<TokioTcpStream>>::new(([8, 8, 8, 8], 53).into());
185+
let (stream, sender) = TcpClientStream::<AsyncIoTokioAsStd<TokioTcpStream>>::new(([1, 1, 1, 1], 53).into());
186186
let client = AsyncClient::new(stream, sender, None);
187187
// await the connection to be established
188188
let (mut client, bg) = client.await.expect("connection failed");

proxy-lib/src/doh_client/doh_client_healthcheck.rs

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use super::{dns_message, path_manage::DoHPath, DoHClient};
22
use crate::{
3-
constants::{
4-
HEALTHCHECK_RETRY_WAITING_SEC, HEALTHCHECK_TARGET_ADDR, HEALTHCHECK_TARGET_FQDN, MAX_ALL_UNHEALTHY_RETRY,
5-
},
3+
constants::{HEALTHCHECK_RETRY_WAITING_SEC, HEALTHCHECK_TARGET_ADDR, HEALTHCHECK_TARGET_FQDN, MAX_ALL_UNHEALTHY_RETRY},
64
error::*,
75
log::*,
86
};
@@ -49,28 +47,15 @@ impl DoHClient {
4947
});
5048

5149
// health check for every path
52-
let futures = self
53-
.path_manager
54-
.paths
55-
.iter()
56-
.flatten()
57-
.flatten()
58-
.map(|path| async move {
59-
if let Err(e) = self.healthcheck(path).await {
60-
warn!("Healthcheck fails for {}: {e}", path.as_url()?)
61-
}
62-
Ok(()) as Result<()>
63-
});
50+
let futures = self.path_manager.paths.iter().flatten().flatten().map(|path| async move {
51+
if let Err(e) = self.healthcheck(path).await {
52+
warn!("Healthcheck fails for {}: {e}", path.as_url()?)
53+
}
54+
Ok(()) as Result<()>
55+
});
6456
let _ = join_all(futures).await;
6557

66-
if !self
67-
.path_manager
68-
.paths
69-
.iter()
70-
.flatten()
71-
.flatten()
72-
.any(|v| v.is_healthy())
73-
{
58+
if !self.path_manager.paths.iter().flatten().flatten().any(|v| v.is_healthy()) {
7459
all_unhealthy_cnt += 1;
7560
error!("All possible paths are unhealthy. Should check the Internet connection");
7661
if all_unhealthy_cnt > MAX_ALL_UNHEALTHY_RETRY {
@@ -88,13 +73,17 @@ impl DoHClient {
8873
let q_msg = dns_message::build_query_a(HEALTHCHECK_TARGET_FQDN)?;
8974
let packet_buf = dns_message::encode(&q_msg)?;
9075

91-
let Ok((_, res_msg)) = self.make_doh_query_inner(&packet_buf, path).await else {
92-
path.make_unhealthy();
93-
warn!(
94-
"Failed to query or invalid response. Path {} is unhealthy",
95-
path.as_url()?
96-
);
97-
return Ok(());
76+
let res_msg = match self.make_doh_query_inner(&packet_buf, path).await {
77+
Ok((_, res_msg)) => res_msg,
78+
Err(e) => {
79+
path.make_unhealthy();
80+
warn!(
81+
"Failed to query or invalid response. Path {} is unhealthy: {}",
82+
path.as_url()?,
83+
e
84+
);
85+
return Ok(());
86+
}
9887
};
9988

10089
if res_msg.header().response_code() != ResponseCode::NoError {

proxy-lib/src/doh_client/doh_client_main.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ impl DoHClient {
9292
headers.insert("Accept", header::HeaderValue::from_str(&ct).unwrap());
9393
headers.insert("Content-Type", header::HeaderValue::from_str(&ct).unwrap());
9494
if let DoHType::Oblivious = doh_type {
95-
headers.insert(
96-
"Cache-Control",
97-
header::HeaderValue::from_str("no-cache, no-store").unwrap(),
98-
);
95+
headers.insert("Cache-Control", header::HeaderValue::from_str("no-cache, no-store").unwrap());
9996
}
10097

10198
// doh method
@@ -120,8 +117,7 @@ impl DoHClient {
120117
let healthcheck_period_sec = globals.proxy_config.healthcheck_period_sec;
121118

122119
// query manipulators
123-
let query_manipulators: Option<QueryManipulators> = if let Some(q) = &globals.proxy_config.query_manipulation_config
124-
{
120+
let query_manipulators: Option<QueryManipulators> = if let Some(q) = &globals.proxy_config.query_manipulation_config {
125121
q.as_ref().try_into().ok()
126122
} else {
127123
None
@@ -198,11 +194,7 @@ impl DoHClient {
198194

199195
/// Make DoH query with a specifically given path.
200196
/// Note cache and plugins are disabled to be used for health check
201-
pub(super) async fn make_doh_query_inner(
202-
&self,
203-
packet_buf: &[u8],
204-
path: &Arc<DoHPath>,
205-
) -> Result<(Vec<u8>, Message)> {
197+
pub(super) async fn make_doh_query_inner(&self, packet_buf: &[u8], path: &Arc<DoHPath>) -> Result<(Vec<u8>, Message)> {
206198
let headers = self.build_headers().await?;
207199
let response_buf = match self.doh_type {
208200
DoHType::Standard => self.serve_doh_query(packet_buf, path, headers).await,
@@ -225,10 +217,7 @@ impl DoHClient {
225217
debug!("build headers with http authorization header");
226218
let token = auth.id_token().await?;
227219
let token_str = format!("Bearer {}", &token);
228-
headers.insert(
229-
header::AUTHORIZATION,
230-
header::HeaderValue::from_str(&token_str).unwrap(),
231-
);
220+
headers.insert(header::AUTHORIZATION, header::HeaderValue::from_str(&token_str).unwrap());
232221
Ok(headers)
233222
}
234223
None => Ok(headers),
@@ -269,12 +258,7 @@ impl DoHClient {
269258
}
270259

271260
/// serve oblivious doh query
272-
async fn serve_oblivious_doh_query(
273-
&self,
274-
packet_buf: &[u8],
275-
odoh_path: &Arc<DoHPath>,
276-
headers: HeaderMap,
277-
) -> Result<Vec<u8>> {
261+
async fn serve_oblivious_doh_query(&self, packet_buf: &[u8], odoh_path: &Arc<DoHPath>, headers: HeaderMap) -> Result<Vec<u8>> {
278262
let target_obj = odoh_path.target();
279263
let path_url = odoh_path.as_url()?;
280264
debug!("[ODoH] target url: {}", path_url.as_str());
@@ -299,23 +283,23 @@ impl DoHClient {
299283
}
300284
DoHMethod::Post => {
301285
let lock = self.http_client.read().await;
302-
lock
303-
.post(path_url)
304-
.headers(headers)
305-
.body(encrypted_query_body)
306-
.send()
307-
.await?
286+
lock.post(path_url).headers(headers).body(encrypted_query_body).send().await?
308287
}
309288
};
310289

311290
// 401 or len=0 when 200, update doh client with renewed public key
312-
let Some(content_length) = response.content_length() else {
291+
// workaround related to reqwest-0.12, which returns always None with response.content_length()
292+
let Some(content_length) = response
293+
.headers()
294+
.get("content-length")
295+
.and_then(|v| v.to_str().map(|s| s.parse::<u16>().ok()).ok().flatten())
296+
else {
313297
return Err(DapError::ODoHInvalidContentLength);
314298
};
315299
if response.status() == reqwest::StatusCode::UNAUTHORIZED
316300
|| (response.status() == reqwest::StatusCode::OK && content_length == 0)
317301
{
318-
warn!("ODoH public key is expired. Refetch.");
302+
warn!("ODoH public key might be expired. Refetch.");
319303
self
320304
.odoh_configs
321305
.as_ref()

0 commit comments

Comments
 (0)