Print key validation results in verbose mode

This commit is contained in:
Alex Page 2023-06-22 03:39:24 -04:00
parent e001afdaed
commit b95d46293c
3 changed files with 53 additions and 7 deletions

View file

@ -25,6 +25,7 @@ pub fn verify(
base_point: &EcPoint,
public_key: &EcPoint,
p_key: &str,
verbose: bool,
) -> Result<bool> {
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());
}

View file

@ -26,6 +26,7 @@ pub fn verify(
base_point: &EcPoint,
public_key: &EcPoint,
cd_key: &str,
verbose: bool,
) -> Result<bool> {
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());
}
}

View file

@ -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?"));
}