add support for cucked urls

This commit is contained in:
lolcat committed 2026-11-30 17:19:39 -05:00
1 parent e03c582f74
commit ffb1fc00f3
8 files changed
+223 -318

No files matched your search

+85
View File
@@ -334,4 +334,89 @@ class backend{
return false;
}
//
// SIGNATURES
//
public function hmac_sign(int $purpose, string $payload){
if(config::HMAC_SECRET === null){
return "";
}
$header = pack("CN", $purpose, intdiv(time(), 60));
$hash = hash_hmac("sha256", $header . $payload, config::HMAC_SECRET, true);
return rtrim(strtr(base64_encode(
$header . $hash
), "+/", "-_"), "=");
}
public function hmac_verify(int $expected_purpose, string $payload, string $signature){
if(config::HMAC_SECRET === null){
return [
"valid" => true
];
}
$decoded = base64_decode(strtr($signature, "-_", "+/"));
if(strlen($decoded) !== 37){
return [
"valid" => false,
"reason" => "Invalid signature size"
];
}
// extract bullshit
$purpose = unpack("C", $decoded)[1];
$timestamp = unpack("N", substr($decoded, 1, 4))[1];
$signature = substr($decoded, 5);
// check purpose
if($purpose !== $expected_purpose){
return [
"valid" => false,
"reason" => "This signature is used for something else"
];
}
// check expiration
$now = intdiv(time(), 60);
if(
$timestamp > $now ||
$now > $timestamp + config::HMAC_TTL
){
return [
"valid" => false,
"reason" => "Signature expired"
];
}
// check hmac
$r_header = pack("CN", $expected_purpose, $timestamp);
$r_hash = hash_hmac("sha256", $r_header . $payload, config::HMAC_SECRET, true);
if(!hash_equals($signature, $r_hash)){
return [
"valid" => false,
"reason" => "Signature mismatch"
];
}
return [
"valid" => true,
"timestamp" => $timestamp,
"signature" => $signature
];
}
}
+4 -5
View File
@@ -1148,7 +1148,7 @@ class frontend{
"ddg" => "DuckDuckGo",
"yandex" => "Yandex",
"brave" => "Brave",
"google" => "Google",
//"google" => "Google",
"google_api" => "Google API",
"google_cse" => "Google CSE",
"yahoo_japan" => "Yahoo! JAPAN",
@@ -1183,7 +1183,7 @@ class frontend{
"ddg" => "DuckDuckGo",
"brave" => "Brave",
"yandex" => "Yandex",
"google" => "Google",
//"google" => "Google",
"yahoo_japan" => "Yahoo! JAPAN",
"startpage" => "Startpage",
"naver" => "Naver",
@@ -1201,7 +1201,7 @@ class frontend{
"option" => [
"ddg" => "DuckDuckGo",
"brave" => "Brave",
"google" => "Google",
//"google" => "Google",
"yahoo_japan" => "Yahoo! JAPAN",
"startpage" => "Startpage",
//"mojeek" => "Mojeek",
@@ -1214,8 +1214,7 @@ class frontend{
$filters["scraper"] = [
"display" => "Scraper",
"option" => [
"sc" => "SoundCloud",
"swisscows" => "Swisscows (SoundCloud)"
"sc" => "SoundCloud"
//"spotify" => "Spotify"
]
];