mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
use gocamo
This commit is contained in:
parent
6aad14b806
commit
35a227e938
3 changed files with 6 additions and 14 deletions
8
native/philomena/Cargo.lock
generated
8
native/philomena/Cargo.lock
generated
|
@ -43,12 +43,6 @@ version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base16"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d27c3610c36aee21ce8ac510e6224498de4228ad772a171ed65643a24693a5a8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
@ -489,7 +483,7 @@ dependencies = [
|
||||||
name = "philomena"
|
name = "philomena"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base16",
|
"base64",
|
||||||
"comrak",
|
"comrak",
|
||||||
"jemallocator",
|
"jemallocator",
|
||||||
"ring",
|
"ring",
|
||||||
|
|
|
@ -14,7 +14,7 @@ comrak = { git = "https://github.com/philomena-dev/comrak", branch = "main" }
|
||||||
rustler = "0.22"
|
rustler = "0.22"
|
||||||
jemallocator = "0.3.2"
|
jemallocator = "0.3.2"
|
||||||
ring = "0.16"
|
ring = "0.16"
|
||||||
base16 = "0.2"
|
base64 = "0.13"
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -13,16 +13,14 @@ fn untrusted_host(url: Url, camo_host: String, camo_key: String) -> Option<Strin
|
||||||
let camo_url = format!("https://{}", camo_host);
|
let camo_url = format!("https://{}", camo_host);
|
||||||
let key = hmac::Key::new(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY, camo_key.as_ref());
|
let key = hmac::Key::new(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY, camo_key.as_ref());
|
||||||
let tag = hmac::sign(&key, url.to_string().as_bytes());
|
let tag = hmac::sign(&key, url.to_string().as_bytes());
|
||||||
let encoded = base16::encode_lower(tag.as_ref());
|
let encoded = base64::encode_config(tag.as_ref(), base64::URL_SAFE_NO_PAD);
|
||||||
|
let encoded_url = base64::encode_config(url.as_ref(), base64::URL_SAFE_NO_PAD);
|
||||||
|
let path = format!("{}/{}", encoded, encoded_url);
|
||||||
|
|
||||||
let mut camo_uri = Url::parse(&camo_url).ok()?;
|
let mut camo_uri = Url::parse(&camo_url).ok()?;
|
||||||
camo_uri.set_path(&encoded);
|
camo_uri.set_path(&path);
|
||||||
camo_uri.set_port(Some(443)).ok()?;
|
camo_uri.set_port(Some(443)).ok()?;
|
||||||
camo_uri.set_scheme("https").ok()?;
|
camo_uri.set_scheme("https").ok()?;
|
||||||
camo_uri
|
|
||||||
.query_pairs_mut()
|
|
||||||
.clear()
|
|
||||||
.append_pair("url", &url.to_string());
|
|
||||||
|
|
||||||
Some(camo_uri.to_string())
|
Some(camo_uri.to_string())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue