From b95d46293c16f03adfe16beaeb9e74cb03e392bd Mon Sep 17 00:00:00 2001 From: Alex Page Date: Thu, 22 Jun 2023 03:39:24 -0400 Subject: [PATCH] Print key validation results in verbose mode --- src/bink1998.rs | 15 +++++++++++++-- src/bink2002.rs | 13 ++++++++++++- src/cli.rs | 32 ++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/bink1998.rs b/src/bink1998.rs index 1098b55..1c9f12b 100644 --- a/src/bink1998.rs +++ b/src/bink1998.rs @@ -25,6 +25,7 @@ pub fn verify( base_point: &EcPoint, public_key: &EcPoint, p_key: &str, + verbose: bool, ) -> Result { let mut num_context = BigNumContext::new()?; @@ -33,6 +34,15 @@ pub fn verify( let p_data = product_key.serial << 1 | product_key.upgrade as u32; + if verbose { + println!("Validation results:"); + println!(" Upgrade: {}", product_key.upgrade); + println!(" Serial: {}", product_key.serial); + println!(" Hash: {}", product_key.hash); + println!(" Signature: {}", product_key.signature); + println!(); + } + let e = BigNum::from_u32(product_key.hash)?; let s = BigNum::from_slice(&product_key.signature.to_be_bytes())?; let mut x = BigNum::new()?; @@ -211,12 +221,13 @@ mod tests { let (e_curve, gen_point, pub_point) = initialize_elliptic_curve(p, a, b, gx, gy, kx, ky); - assert!(super::verify(&e_curve, &gen_point, &pub_point, product_key).unwrap()); + assert!(super::verify(&e_curve, &gen_point, &pub_point, product_key, true).unwrap()); assert!(!super::verify( &e_curve, &gen_point, &pub_point, - "11111-R6BG2-39J83-RYKHF-W47TT" + "11111-R6BG2-39J83-RYKHF-W47TT", + true ) .unwrap()); } diff --git a/src/bink2002.rs b/src/bink2002.rs index 2f83fca..ce5655c 100644 --- a/src/bink2002.rs +++ b/src/bink2002.rs @@ -26,6 +26,7 @@ pub fn verify( base_point: &EcPoint, public_key: &EcPoint, cd_key: &str, + verbose: bool, ) -> Result { let mut num_context = BigNumContext::new()?; @@ -34,6 +35,16 @@ pub fn verify( let p_data = product_key.channel_id << 1 | product_key.upgrade as u32; + if verbose { + println!("Validation results:"); + println!(" Upgrade: {}", product_key.upgrade); + println!("Channel ID: {}", product_key.channel_id); + println!(" Hash: {}", product_key.hash); + println!(" Signature: {}", product_key.signature); + println!(" AuthInfo: {}", product_key.auth_info); + println!(); + } + let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH]; msg_buffer[0x00] = 0x5D; @@ -295,6 +306,6 @@ mod tests { let (e_curve, gen_point, pub_point) = initialize_elliptic_curve(p, a, b, gx, gy, kx, ky); - assert!(super::verify(&e_curve, &gen_point, &pub_point, product_key).unwrap()); + assert!(super::verify(&e_curve, &gen_point, &pub_point, product_key, true).unwrap()); } } diff --git a/src/cli.rs b/src/cli.rs index ccfca12..a422deb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -239,7 +239,13 @@ impl Cli { )?; Cli::print_key(&p_key); - if bink1998::verify(&self.e_curve, &self.gen_point, &self.pub_point, &p_key)? { + if bink1998::verify( + &self.e_curve, + &self.gen_point, + &self.pub_point, + &p_key, + self.options.verbose, + )? { self.count += 1; } } @@ -276,7 +282,13 @@ impl Cli { Cli::print_key(&p_key); println!("\n"); - if bink2002::verify(&self.e_curve, &self.gen_point, &self.pub_point, &p_key)? { + if bink2002::verify( + &self.e_curve, + &self.gen_point, + &self.pub_point, + &p_key, + self.options.verbose, + )? { self.count += 1; } } @@ -291,7 +303,13 @@ impl Cli { }; Self::print_key(&key); - if !bink1998::verify(&self.e_curve, &self.gen_point, &self.pub_point, &key)? { + if !bink1998::verify( + &self.e_curve, + &self.gen_point, + &self.pub_point, + &key, + self.options.verbose, + )? { return Err(anyhow!("Product key is invalid! Wrong BINK ID?")); } @@ -305,7 +323,13 @@ impl Cli { }; Self::print_key(&key); - if !bink2002::verify(&self.e_curve, &self.gen_point, &self.pub_point, &key)? { + if !bink2002::verify( + &self.e_curve, + &self.gen_point, + &self.pub_point, + &key, + self.options.verbose, + )? { return Err(anyhow!("Product key is invalid! Wrong BINK ID?")); }