encryption matches
This commit is contained in:
parent
e344defb3b
commit
d45d5c862e
|
@ -8,13 +8,23 @@ pub fn aes_en(plaintext: &&str) -> Vec<u8> {
|
|||
// Encodes string with aes 128 cfb encryption
|
||||
// Return encrypted text
|
||||
// Crypto constants
|
||||
let mut ciphertext = plaintext.as_bytes().to_vec();
|
||||
// Must have padding!!! This was overlooked a while back...
|
||||
let ciphertext = plaintext.as_bytes().to_vec();
|
||||
let key: &[u8] = "0123456789012345".as_bytes();
|
||||
let iv: &[u8] = "0123456789012345".as_bytes();
|
||||
|
||||
// Now we need to pad it TO BAD I HAD TO IMPLEMENT PKCS#7 in here lmao
|
||||
// PKCS#7 padding... too lazy to get a library to do this and the ones I have don't...?
|
||||
let block_size = 16;
|
||||
let padder = block_size - (ciphertext.len() % block_size);
|
||||
let padding = vec![padder as u8; padder];
|
||||
let mut padded_data = Vec::from(ciphertext);
|
||||
padded_data.extend(padding);
|
||||
|
||||
// Encrypt
|
||||
Aes128CfbEnc::new(key.into(), iv.into()).encrypt(&mut ciphertext);
|
||||
ciphertext.into()
|
||||
Aes128CfbEnc::new(key.into(), iv.into()).encrypt(&mut padded_data);
|
||||
padded_data.into()
|
||||
|
||||
}
|
||||
|
||||
pub fn aes_dec(ciphertext: &[u8]) -> String {
|
||||
|
|
|
@ -51,14 +51,44 @@ fn clean_json_string(input: &str) -> String {
|
|||
cleaned_str
|
||||
}
|
||||
|
||||
// {'result':200,'encresponse':{}}
|
||||
fn to_xxd_format(input: &[u8]) {
|
||||
let chunk_size = 16;
|
||||
for (i, chunk) in input.chunks(chunk_size).enumerate() {
|
||||
// Print the offset
|
||||
print!("{:08x}: ", i * chunk_size);
|
||||
|
||||
// Print the hex representation
|
||||
for byte in chunk.iter() {
|
||||
print!("{:02x} ", byte);
|
||||
}
|
||||
|
||||
// Pad the hex representation if the chunk is less than chunk_size
|
||||
if chunk.len() < chunk_size {
|
||||
for _ in 0..(chunk_size - chunk.len()) {
|
||||
print!(" ");
|
||||
}
|
||||
}
|
||||
|
||||
print!(" |");
|
||||
|
||||
// Print the ASCII representation
|
||||
for byte in chunk.iter() {
|
||||
if byte.is_ascii_graphic() || *byte == b' ' {
|
||||
print!("{}", *byte as char);
|
||||
} else {
|
||||
print!(".");
|
||||
}
|
||||
}
|
||||
|
||||
println!("|");
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/game")]
|
||||
pub async fn game_stuff(body: web::Bytes, req: actix_web::HttpRequest) -> HttpResponse {
|
||||
// For getting the game online, we need to give it a json type encrypted!
|
||||
let ct = String::from_utf8_lossy(&body).trim().replace("\n", "").replace("\0", "").replace("\r","").replace("\t","");
|
||||
println!("{}",format!("Ciphertext:").black().on_red());
|
||||
println!("{}", &ct.red());
|
||||
//println!("{}",format!("Ciphertext:").black().on_red());
|
||||
//to_xxd_format(&body);
|
||||
println!("{}",format!("Plaintext:").black().on_green());
|
||||
let pt = aes_dec(&body);
|
||||
let cleaned = clean_json_string(&pt).replace("\n","");
|
||||
|
@ -71,8 +101,8 @@ pub async fn game_stuff(body: web::Bytes, req: actix_web::HttpRequest) -> HttpRe
|
|||
println!("{}",format!("data.protocol -> {}", data.protocol).black().bold().on_magenta());
|
||||
match data.protocol.as_str() {
|
||||
"unlock" => return encresp("{'result':200,'response':{}}"), // 1st
|
||||
"gameconfig" => return encresp("{'result':400,'response':{}}"), // 2nd -> not getting the right data???
|
||||
"information" => return encresp("{'result':400,'response':{}}"), // 3rd
|
||||
"gameconfig" => return encresp("{'result':200,'response':{'version':'2.4.1','season_event_uid':'0','level_cap':200,'skill_level_cap':999,'yell_rank_cap':999,'card_sells_value':100,'music_release_version':99999,'finale_focus_release_version':99999,'stage_release_version':99999,'member_card_release_version':99999,'memorial_card_release_version':99999,'skill_card_release_version':99999,'advertise_movie_status_0':true,'advertise_movie_status_1':false,'advertise_movie_status_2':false,'advertise_movie_status_3':false,'live_demo_table_id':5,'exp_mag':1,'exp_mag_target_level':5,'cheer_enable':false,'achievement_release_version':99999,'travel_pamphlet_release_version':99999,'live_break_max':1,'yell_achieve_mobile_point':100,'yell_point_mag':1,'dice_bonus_credit':100}}"), // 2nd
|
||||
"information" => return encresp("{'result':200,'response':{}}"), // 3rd
|
||||
"ranking" => return encresp("{'result':200,'response':{}}"), // 4th
|
||||
"auth" => return encresp("{'result':200,'response':{}}"),
|
||||
"achievement" => return encresp("{'result':200,'response':{}}"),
|
||||
|
|
|
@ -36,3 +36,6 @@ The python file pads the given protocol string, then openssl encrypts it for the
|
|||
`python pad_plaintext.py '{"game":{"eventcode":"000","version":"2.4.1"},"param":{},"protocol":"unlock"}' | openssl enc -e -aes-128-cfb -K '30313233343536373839303132333435' -iv '30313233343536373839303132333435' | curl -X POST -H "Content-Type: application/octet-stream" --data-binary @- http://10.3.0.141/game | openssl enc -d -aes-128-cfb -K '30313233343536373839303132333435' -iv '30313233343536373839303132333435'`
|
||||
|
||||
`python pad_plaintext.py '{"game":{"eventcode":"000","version":"2.4.1"},"param":{},"protocol":"unlock","terminal":{"tenpo_id":"1337","tenpo_index":1337,"terminal_attrib":0,"terminal_id":"1C1B0D07CDBB"}}' | openssl enc -e -aes-128-cfb -K '30313233343536373839303132333435' -iv '30313233343536373839303132333435' | curl -X POST -H "Content-Type: application/octet-stream" --data-binary @- http://localhost/game | openssl enc -d -aes-128-cfb -K '30313233343536373839303132333435' -iv '30313233343536373839303132333435'`
|
||||
|
||||
Test `unlock`:
|
||||
`python pad_plaintext.py '{"game":{"eventcode":"000","version":"2.4.1"},"param":{},"protocol":"unlock","terminal":{"tenpo_id":"1337","tenpo_index":1337,"terminal_attrib":0,"terminal_id":"1C1B0D07CDBB"}}' | openssl enc -e -aes-128-cfb -K '30313233343536373839303132333435' -iv '30313233343536373839303132333435' | curl -X POST -H "Content-Type: application/octet-stream" --data-binary @- http://localhost/game | openssl enc -d -aes-128-cfb -K '30313233343536373839303132333435' -iv '30313233343536373839303132333435' > mine.xxd && xxd mine.xxd`
|
||||
|
|
Loading…
Reference in New Issue