Print key validation results in verbose mode
This commit is contained in:
parent
e001afdaed
commit
b95d46293c
3 changed files with 53 additions and 7 deletions
|
@ -25,6 +25,7 @@ pub fn verify(
|
||||||
base_point: &EcPoint,
|
base_point: &EcPoint,
|
||||||
public_key: &EcPoint,
|
public_key: &EcPoint,
|
||||||
p_key: &str,
|
p_key: &str,
|
||||||
|
verbose: bool,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut num_context = BigNumContext::new()?;
|
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;
|
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 e = BigNum::from_u32(product_key.hash)?;
|
||||||
let s = BigNum::from_slice(&product_key.signature.to_be_bytes())?;
|
let s = BigNum::from_slice(&product_key.signature.to_be_bytes())?;
|
||||||
let mut x = BigNum::new()?;
|
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);
|
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(
|
assert!(!super::verify(
|
||||||
&e_curve,
|
&e_curve,
|
||||||
&gen_point,
|
&gen_point,
|
||||||
&pub_point,
|
&pub_point,
|
||||||
"11111-R6BG2-39J83-RYKHF-W47TT"
|
"11111-R6BG2-39J83-RYKHF-W47TT",
|
||||||
|
true
|
||||||
)
|
)
|
||||||
.unwrap());
|
.unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub fn verify(
|
||||||
base_point: &EcPoint,
|
base_point: &EcPoint,
|
||||||
public_key: &EcPoint,
|
public_key: &EcPoint,
|
||||||
cd_key: &str,
|
cd_key: &str,
|
||||||
|
verbose: bool,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut num_context = BigNumContext::new()?;
|
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;
|
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];
|
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
||||||
|
|
||||||
msg_buffer[0x00] = 0x5D;
|
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);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
src/cli.rs
32
src/cli.rs
|
@ -239,7 +239,13 @@ impl Cli {
|
||||||
)?;
|
)?;
|
||||||
Cli::print_key(&p_key);
|
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;
|
self.count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,7 +282,13 @@ impl Cli {
|
||||||
Cli::print_key(&p_key);
|
Cli::print_key(&p_key);
|
||||||
println!("\n");
|
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;
|
self.count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,7 +303,13 @@ impl Cli {
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::print_key(&key);
|
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?"));
|
return Err(anyhow!("Product key is invalid! Wrong BINK ID?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +323,13 @@ impl Cli {
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::print_key(&key);
|
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?"));
|
return Err(anyhow!("Product key is invalid! Wrong BINK ID?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue