Skip to content

Commit

Permalink
fix signing
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Jan 30, 2023
1 parent 5104137 commit 8545e62
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions bin/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ pub fn cli() -> Command {
.action(ArgAction::Count)
.short('v'),
);
global = global.arg(
clap::Arg::new("version")
.global(false)
.help("Print version")
.action(ArgAction::SetTrue)
.long("version"),
);
global = global.arg(
clap::Arg::new("trace")
.global(true)
.help("Enable trace logging")
.action(ArgAction::SetTrue)
.long("trace"),
);
#[cfg(debug_assertions)]
{
global = global.arg(
clap::Arg::new("in-test")
.global(true)
.help("we are in a test")
.action(ArgAction::SetTrue)
.long("in-test"),
);
}
global
}

Expand All @@ -73,13 +76,10 @@ pub fn cli() -> Command {
/// # Panics
/// If the number passed to `--threads` is not a valid number
pub fn execute(matches: &ArgMatches) -> Result<(), AppError> {
if matches.get_flag("version") {
println!("HEMTT {}", env!("CARGO_PKG_VERSION"));
return Ok(());
if cfg!(not(debug_assertions)) || !matches.get_flag("in-test") {
logging::init(matches.get_count("verbosity"), matches.get_flag("trace"));
}

logging::init(matches.get_count("verbosity"), matches.get_flag("trace"));

trace!("version: {}", env!("CARGO_PKG_VERSION"));
trace!("platform: {}", std::env::consts::OS);

Expand Down
5 changes: 2 additions & 3 deletions bin/app/src/modules/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Module for Sign {
let authority = get_authority(ctx, None)?;
let addons_key = BIPrivateKey::generate(1024, &authority)?;
create_dir_all(ctx.out_folder().join("keys"))?;
addons_key.write(&mut File::create(
addons_key.to_public_key().write(&mut File::create(
ctx.out_folder()
.join("keys")
.join(format!("{authority}.bikey")),
Expand All @@ -57,13 +57,12 @@ impl Module for Sign {
if ctx.config().hemtt().build().optional_mod_folders() {
let authority = get_authority(ctx, Some(&pbo_name))?;
let key = BIPrivateKey::generate(1024, &authority)?;
let pubkey = key.to_public_key();
let mod_root = ctx
.out_folder()
.join("optionals")
.join(format!("@{pbo_name}"));
create_dir_all(mod_root.join("keys"))?;
pubkey.write(&mut File::create(
key.to_public_key().write(&mut File::create(
mod_root.join("keys").join(format!("{authority}.bikey")),
)?)?;
(mod_root.join("addons").join(pbo_name), key, authority)
Expand Down
4 changes: 2 additions & 2 deletions bin/app/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use hemtt::cli;
#[test]
pub fn build() {
std::env::set_current_dir("tests/alpha").unwrap();
hemtt::execute(&cli().get_matches_from(vec!["hemtt", "build"])).unwrap();
hemtt::execute(&cli().get_matches_from(vec!["hemtt", "build", "--in-test"])).unwrap();

std::env::set_current_dir("../bravo").unwrap();
hemtt::execute(&cli().get_matches_from(vec!["hemtt", "release"])).unwrap();
hemtt::execute(&cli().get_matches_from(vec!["hemtt", "release", "--in-test"])).unwrap();
}
8 changes: 8 additions & 0 deletions libs/preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ where
if next.symbol() == &Symbol::Slash {
whitespace::skip_comment(tokenstream);
}
} else {
tokenstream.move_cursor_back().unwrap();
if context.ifstates().reading() {
output.push(tokenstream.next().unwrap());
}
}
}
_ => {
Expand Down Expand Up @@ -705,6 +710,9 @@ where
if next.symbol() == &Symbol::Slash {
whitespace::skip_comment(tokenstream);
}
} else {
tokenstream.move_cursor_back().unwrap();
output.push(tokenstream.next().unwrap());
}
}
_ => output.push(tokenstream.next().unwrap()),
Expand Down
7 changes: 2 additions & 5 deletions libs/signing/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sha1::{Digest, Sha1};
use crate::{error::Error, public::BIPublicKey, signature::BISign};

#[allow(clippy::module_name_repetitions)]
#[derive(Clone)]
#[derive(Debug, Clone)]
/// A private key for signing PBOs
pub struct BIPrivateKey {
authority: String,
Expand All @@ -36,9 +36,6 @@ impl BIPrivateKey {
let mut rng = rand::thread_rng();
let mut rsa = RsaPrivateKey::new(&mut rng, length as usize)?;
rsa.precompute()?;
// let Some(precomputed) = rsa.precomputed() else {
// return Err(Error::Rsa(rsa::errors::Error::Internal));
// };
let primes = rsa.primes();
let Some(qinv) = rsa.qinv().unwrap().to_biguint() else {
return Err(Error::Rsa(rsa::errors::Error::Internal));
Expand Down Expand Up @@ -180,7 +177,7 @@ impl BIPrivateKey {
///
/// # Panics
/// If the qinv sign is not `NoSign`.
pub fn write<O: Write>(&self, output: &mut O) -> Result<(), Error> {
pub fn write_danger<O: Write>(&self, output: &mut O) -> Result<(), Error> {
output.write_cstring(&self.authority)?;
output.write_u32::<LittleEndian>(self.length / 16 * 9 + 20)?;
output.write_all(b"\x07\x02\x00\x00\x00\x24\x00\x00")?;
Expand Down
4 changes: 2 additions & 2 deletions libs/signing/tests/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fs::File;
use std::{fs::File, io::Write};

use hemtt_pbo::ReadablePbo;
use hemtt_signing::BIPrivateKey;
Expand All @@ -15,7 +15,7 @@ fn bootstrap() {
BIPrivateKey::read(&mut File::open(file.path().join("test.biprivatekey")).unwrap())
.unwrap();
let mut buffer = Vec::new();
private.write(&mut buffer).unwrap();
private.write_danger(&mut buffer).unwrap();
assert_eq!(
buffer,
std::fs::read(file.path().join("test.biprivatekey")).unwrap()
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.bikey
Binary file not shown.
Binary file modified libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.biprivatekey
Binary file not shown.

0 comments on commit 8545e62

Please sign in to comment.