baesd ruste crypto?!!?1'1??!?!!?!?

This commit is contained in:
uh wot 2021-08-02 17:26:47 +02:00
parent 6994f35062
commit 30153cfb8a
Signed by: uhwot
GPG key ID: CB2454984587B781
10 changed files with 7234 additions and 69 deletions

68
src/lib.rs Normal file
View file

@ -0,0 +1,68 @@
use wasm_bindgen::prelude::*;
use js_sys::Uint8Array;
use blowfish::Blowfish;
use aes::Aes128;
use block_modes::{BlockMode, Cbc, Ecb};
use block_modes::block_padding::{NoPadding, ZeroPadding};
use md5::{Md5, Digest};
type BfCbc = Cbc<Blowfish, NoPadding>;
type Aes128Ecb = Ecb<Aes128, ZeroPadding>;
const TRACK_CDN_KEY: [u8; 16] = [106, 111, 54, 97, 101, 121, 54, 104, 97, 105, 100, 50, 84, 101, 105, 104];
const BF_SECRET: [u8; 16] = [103, 52, 101, 108, 53, 56, 119, 99, 48, 122, 118, 102, 57, 110, 97, 49];
#[wasm_bindgen]
pub struct Cipher {
cipher: BfCbc
}
#[wasm_bindgen]
impl Cipher {
#[wasm_bindgen(constructor)]
pub fn new(id: &str) -> Self {
let id_md5 = format!("{:x}", Md5::digest(id.as_bytes()));
let id_md5 = id_md5.as_bytes();
let mut key = [0u8; 16];
for i in 0..16 {
key[i] = id_md5[i] ^ id_md5[i+16] ^ BF_SECRET[i]
};
Self { cipher: BfCbc::new_from_slices(&key, &[0, 1, 2, 3, 4, 5, 6, 7]).unwrap() }
}
pub fn decrypt_chunk(&self, chunk: &mut [u8]) -> Uint8Array {
let chunk = self.cipher.clone().decrypt(chunk).unwrap();
unsafe { Uint8Array::view(&chunk) }
}
}
#[wasm_bindgen]
pub fn stream_url(md5_origin: &str, format: &str, id: i32, media_version: u8) -> String {
// md5 origin + format num + id + media version
let metadata = [
md5_origin.as_bytes(),
&[b'\xa4'],
format.as_bytes(),
&[b'\xa4'],
id.to_string().as_bytes(),
&[b'\xa4'],
media_version.to_string().as_bytes(),
].concat();
let hash = format!("{:x}", Md5::digest(&metadata));
// md5 hash + previous metadata
let metadata_hash = [
hash.as_bytes(),
&[b'\xa4'],
&metadata,
&[b'\xa4'],
].concat();
let cipher = Aes128Ecb::new_from_slices(&TRACK_CDN_KEY, Default::default()).unwrap();
let ciphertext = cipher.encrypt_vec(&metadata_hash);
format!("https://cdns-proxy-{}.dzcdn.net/mobile/1/{}", md5_origin.chars().next().unwrap(), hex::encode(ciphertext))
}