Skip to content

Commit d3536ef

Browse files
committed
bak it
1 parent 48ff671 commit d3536ef

File tree

12 files changed

+1447
-903
lines changed

12 files changed

+1447
-903
lines changed

Cargo.lock

Lines changed: 1323 additions & 808 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99

1010
[workspace.package]
1111
authors = ["timzaak <[email protected]>"]
12-
edition = "2021"
12+
edition = "2024"
1313
version = "2.4.1"
1414

1515
[workspace.dependencies]
@@ -20,32 +20,34 @@ bytes = "1"
2020
chrono = { version = "0.4" }
2121
clap = { version = "4.5.7"}
2222
console = "0.16"
23-
console-subscriber = "0.4"
23+
console-subscriber = "0.5"
2424
dashmap = "6.1"
2525
delay_timer = "0.11.6"
2626
duration-str = "0.17"
2727
flate2 = "1.0"
2828
futures = "0.3"
29-
futures-channel = { version = "0.3.17"}
30-
futures-util = { version = "0.3", default-features = false }
31-
headers = "0.3.5"
32-
http = "0.2"
33-
hyper = { version = "0.14" }
29+
futures-channel = { version = "0.3.17", features = ["sink"] }
30+
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
31+
headers = "0.4"
32+
http = "1"
33+
http-body-util = "0.1.3"
34+
hyper = { version = "1" }
35+
hyper-util = { version = "0.1.12"}
3436
if_chain = "1.0"
3537
indicatif = "0.18"
3638
lazy_static = "1.4"
3739
log = "0.4"
3840
md-5 = "0.10"
3941
mime = "0.3"
4042
mime_guess = "2.0.0"
41-
multer = { version = "2.1.0" }
43+
multer = { version = "3" }
4244
percent-encoding = "2.1"
4345
pin-project = "1.0"
44-
rcgen = "0.12"
46+
rcgen = "0.14"
4547
regex = "1.10"
4648
reqwest = { version = "0.12", default-features = false }
4749
ring = { version = "0.17" }
48-
rustls = { version = "0.22" }
50+
rustls = { version = "0.23" }
4951
rustls-pemfile = "2.0"
5052
rustls-pki-types = "1.1.0"
5153
scoped-tls = "1.0"
@@ -71,6 +73,6 @@ tracing-core = "0.1.32"
7173
#opentelemetry-stdout = { version = "0.4", features = ["trace"] }
7274

7375
tracing-subscriber = { version = "0.3"}
74-
ureq = { version = "2"}
76+
ureq = { version = "3"}
7577
walkdir = "2.5"
76-
x509-parser = "0.16"
78+
x509-parser = "0.18"

server/Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ path = "src/main.rs"
2020
[dependencies]
2121
entity = { path = "../entity" }
2222
# web
23-
hyper = { workspace = true, features = ["stream", "server", "http1", "http2", "tcp"] }
23+
hyper = { workspace = true, features = ["server", "http1", "http2"] }
24+
hyper-util = { workspace = true, features = ["server", "server-graceful", "server-auto", "http1", "http2", "service", "tokio"] }
2425
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "io-std", "sync", "time", "tokio-macros"] }
2526
futures = { workspace = true }
26-
warp = { path = "../warp", features = ["tls"] }
27+
warp = { path = "../warp", features = ["tls", "multipart", "server"] }
2728
socket2 = { workspace = true, features = ["all"] }
2829

2930
# warp inner
@@ -66,7 +67,7 @@ dashmap = { workspace = true }
6667

6768
#s3
6869
small-acme = { path = "../small-acme" }
69-
ureq = { workspace = true, features = ["json", "tls"] }
70+
ureq = { workspace = true, features = ["json"] }
7071
rcgen = { workspace = true }
7172

7273
# util
@@ -81,4 +82,6 @@ walkdir = { workspace = true }
8182
chrono = { workspace = true, features = ["serde"] }
8283
#make if let more easy
8384
if_chain = { workspace = true }
84-
tracing-core = { workspace = true }
85+
tracing-core = { workspace = true }
86+
http-body-util = "0.1.3"
87+
http-body = "1.0.1"

server/src/acme.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use dashmap::DashMap;
1313
use delay_timer::prelude::{DelayTimer, Task, TaskBuilder};
1414
use if_chain::if_chain;
1515
use lazy_static::lazy_static;
16-
use rcgen::{Certificate, CertificateParams, DistinguishedName};
16+
use rcgen::{CertificateParams, DistinguishedName, KeyPair};
1717
use regex::Regex;
18-
use rustls::sign::CertifiedKey;
18+
use tokio_rustls::rustls::sign::CertifiedKey;
1919
use small_acme::{
2020
Account, AccountCredentials, AuthorizationStatus, ChallengeType, Identifier, NewAccount,
2121
NewOrder, OrderStatus,
@@ -24,6 +24,7 @@ use tokio::sync::mpsc::{Receiver, Sender};
2424
use tokio::sync::RwLock;
2525
use tokio::time::sleep;
2626
use tracing::{debug, error, info, warn};
27+
use ureq::tls::{TlsConfig};
2728
use walkdir::WalkDir;
2829

2930
use crate::config::{get_host_path_from_domain, ACMEConfig, ACMEType, Config};
@@ -110,20 +111,14 @@ impl ACMEProvider {
110111
ci_ca_path: Option<&String>,
111112
) -> anyhow::Result<Account> {
112113
let agent = if matches!(acme_type, ACMEType::CI) {
113-
let mut roots = rustls::RootCertStore::empty();
114-
let mut reader = std::io::BufReader::new(File::open(ci_ca_path.unwrap())?);
115-
let cert = rustls_pemfile::certs(&mut reader).map(|v| v.unwrap());
116-
roots.add_parsable_certificates(cert);
117-
let tls_config = rustls::ClientConfig::builder()
118-
.with_root_certificates(roots)
119-
.with_no_client_auth();
120-
ureq::builder()
114+
let tls_config = TlsConfig::builder().disable_verification(true).build();
115+
ureq::Agent::config_builder()
121116
.https_only(true)
122-
.tls_config(Arc::new(tls_config))
117+
.tls_config(tls_config)
123118
.build()
124119
} else {
125-
ureq::builder().https_only(true).build()
126-
};
120+
ureq::Agent::config_builder().https_only(true).build()
121+
}.into();
127122

128123
let account = if path.exists() {
129124
let file = File::open(path)?;
@@ -219,10 +214,11 @@ impl ACMEProvider {
219214
bail!("domain: {domain} order is invalid")
220215
}
221216

222-
let mut params = CertificateParams::new(names);
217+
let mut params = CertificateParams::new(names)?;
223218
params.distinguished_name = DistinguishedName::new();
224-
let cert = Certificate::from_params(params).unwrap();
225-
let csr = cert.serialize_request_der()?;
219+
let p_key = KeyPair::generate()?;
220+
let csr = params.serialize_request(&p_key)?;
221+
let csr = csr.der();
226222
order
227223
.finalize(&csr)
228224
.with_context(|| format!("{domain} csr failure"))?;
@@ -241,7 +237,7 @@ impl ACMEProvider {
241237
};
242238

243239
debug!("domain: {domain} get cert successful, public cert {cert_chain_pem}");
244-
let private_key = cert.serialize_private_key_pem();
240+
let private_key = p_key.serialize_pem();
245241
let (public_cert_path, private_key_path) = self.get_certificate_file_names(&domain);
246242

247243
let mut private_key_file = File::create(&private_key_path)

server/src/admin_server.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use entity::request::{
88
DeleteDomainVersionOption, DomainWithOptVersionOption, DomainWithVersionOption,
99
GetDomainOption, GetDomainPositionOption, UpdateUploadingStatusOption, UploadFileOption,
1010
};
11-
use hyper::{Body, StatusCode};
11+
use hyper::{StatusCode};
1212
use std::collections::HashMap;
1313
use std::convert::Infallible;
1414
use std::net::SocketAddr;
@@ -80,7 +80,7 @@ impl AdminServer {
8080
Ok(())
8181
}
8282

83-
fn auth(&self) -> impl Filter<Extract = (), Error = Rejection> + Clone {
83+
fn auth(&self) -> impl Filter<Extract = (), Error = Rejection> + Clone + 'static {
8484
// this will not trigger memory leak, be careful to use it
8585
warp::header::exact(
8686
"authorization",
@@ -170,9 +170,7 @@ impl AdminServer {
170170
let resp = service::update_file(query, form, storage)
171171
.await
172172
.unwrap_or_else(|e| {
173-
let mut resp = Response::new(Body::from(e.to_string()));
174-
*resp.status_mut() = StatusCode::BAD_REQUEST;
175-
resp
173+
bad_resp(e.to_string())
176174
});
177175
Ok(resp)
178176
}
@@ -236,7 +234,7 @@ pub mod service {
236234
};
237235
use entity::storage::DomainInfo;
238236
use futures_util::{StreamExt, TryStreamExt};
239-
use hyper::Body;
237+
// use hyper::Body;
240238
use std::collections::HashMap;
241239
use std::convert::Infallible;
242240
use std::sync::Arc;
@@ -262,7 +260,9 @@ pub mod service {
262260
_ => Ok(warp::reply::json(&domain_info).into_response()),
263261
},
264262
Err(e) => {
265-
let mut resp = Response::new(Body::from(e.to_string()));
263+
let z = warp::reply();
264+
265+
let mut resp = e.to_string().into_response();
266266
*resp.status_mut() = StatusCode::BAD_REQUEST;
267267
Ok(resp)
268268
}
@@ -310,8 +310,8 @@ pub mod service {
310310
}
311311
}
312312
Err(err) => {
313-
let mut resp = StatusCode::BAD_REQUEST.into_response();
314-
*resp.body_mut() = Body::from(err.to_string());
313+
let mut resp = err.to_string().into_response();
314+
*resp.status_mut() = StatusCode::BAD_REQUEST;
315315
resp
316316
}
317317
}
@@ -330,7 +330,7 @@ pub mod service {
330330
{
331331
Ok(_) => Response::default(),
332332
Err(e) => {
333-
let mut resp = Response::new(Body::from(format!("error:{}", e)));
333+
let mut resp = format!("error:{}", e).into_response();
334334
*resp.status_mut() = StatusCode::BAD_REQUEST;
335335
resp
336336
}
@@ -353,7 +353,7 @@ pub mod service {
353353
{
354354
Ok(_) => Response::default(),
355355
Err(e) => {
356-
let mut resp = Response::new(Body::from(e.to_string()));
356+
let mut resp = e.to_string().into_response();
357357
*resp.status_mut() = StatusCode::BAD_REQUEST;
358358
resp
359359
}
@@ -367,8 +367,8 @@ pub mod service {
367367
storage: Arc<DomainStorage>,
368368
) -> anyhow::Result<Response> {
369369
if let Err(e) = storage.check_if_can_upload(&query.domain) {
370-
let mut resp = StatusCode::BAD_REQUEST.into_response();
371-
*resp.body_mut() = Body::from(e.to_string());
370+
let mut resp= e.to_string().into_response();
371+
*resp.status_mut() = StatusCode::BAD_REQUEST;
372372
return Ok(resp);
373373
}
374374
let mut parts = form.into_stream();
@@ -401,7 +401,7 @@ pub mod service {
401401
match storage.get_files_metadata(query.domain, query.version) {
402402
Ok(data) => warp::reply::json(&data).into_response(),
403403
Err(err) => {
404-
let mut resp = Response::new(Body::from(err.to_string()));
404+
let mut resp = err.to_string().into_response();
405405
*resp.status_mut() = StatusCode::BAD_REQUEST;
406406
resp
407407
}
@@ -458,7 +458,7 @@ pub mod service {
458458
let resp = match acme_manager.get_cert_data(query.domain.as_ref()).await {
459459
Ok(data) => warp::reply::json(&data).into_response(),
460460
Err(err) => {
461-
let mut resp = Response::new(Body::from(err.to_string()));
461+
let mut resp = err.to_string().into_response();
462462
*resp.status_mut() = StatusCode::BAD_REQUEST;
463463
resp
464464
}
@@ -485,8 +485,8 @@ pub mod service {
485485
{
486486
Ok(_) => Response::default(),
487487
Err(e) => {
488-
let mut resp = StatusCode::BAD_REQUEST.into_response();
489-
*resp.body_mut() = Body::from(e.to_string());
488+
let mut resp = e.to_string().into_response();
489+
*resp.status_mut() = StatusCode::BAD_REQUEST;
490490
resp
491491
}
492492
}
@@ -501,8 +501,8 @@ pub mod service {
501501
}
502502

503503
fn bad_resp(text: String) -> Response {
504-
let mut resp = StatusCode::BAD_REQUEST.into_response();
505-
*resp.body_mut() = Body::from(text);
504+
let mut resp = text.into_response();
505+
*resp.status_mut() = StatusCode::BAD_REQUEST;
506506
resp
507507
}
508508

server/src/cors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::service::resp;
22
use futures_util::future::Either;
33
use headers::{AccessControlAllowMethods, HeaderMap, HeaderMapExt};
44
use hyper::http::HeaderValue;
5-
use hyper::{header, Body, Method, Response, StatusCode};
5+
use hyper::{header, Method, Response, StatusCode};
66
use lazy_static::lazy_static;
77
use std::collections::HashSet;
88

@@ -15,7 +15,7 @@ lazy_static! {
1515
HashSet::from([Method::GET, Method::OPTIONS, Method::HEAD]);
1616
}
1717

18-
pub fn cors_resp(mut res: Response<Body>, origin: HeaderValue) -> Response<Body> {
18+
pub fn cors_resp<B:http_body::Body>(mut res: Response<B>, origin: HeaderValue) -> Response<B> {
1919
let headers = res.headers_mut();
2020
headers.insert(
2121
header::ACCESS_CONTROL_ALLOW_CREDENTIALS,
@@ -38,11 +38,11 @@ fn is_origin_allowed(origins: &Option<HashSet<HeaderValue>>, origin: &HeaderValu
3838
}
3939
}
4040
// preflight response
41-
pub fn resp_cors_request(
41+
pub fn resp_cors_request<B:http_body::Body>(
4242
method: &Method,
4343
headers: &HeaderMap,
4444
origins: &Option<HashSet<HeaderValue>>,
45-
) -> Either<Validated, Response<Body>> {
45+
) -> Either<Validated, Response<B>> {
4646
match (headers.get(header::ORIGIN), method) {
4747
(Some(origin), &Method::OPTIONS) => {
4848
if !is_origin_allowed(origins, origin) {

0 commit comments

Comments
 (0)