From 8545e628401a1f143595c213a23d384c30892a89 Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Sun, 29 Jan 2023 23:46:29 -0600 Subject: [PATCH] fix signing --- Cargo.lock | 4 +-- bin/app/src/lib.rs | 24 +++++++++--------- bin/app/src/modules/sign.rs | 5 ++-- bin/app/tests/build.rs | 4 +-- libs/preprocessor/src/lib.rs | 8 ++++++ libs/signing/src/private.rs | 7 ++--- libs/signing/tests/bootstrap.rs | 4 +-- .../ace_ai_3.15.2.69/source.pbo.test.bisign | Bin 557 -> 557 bytes .../source.pbo.test.bisign.test | Bin 557 -> 0 bytes .../bootstrap/ace_ai_3.15.2.69/test.bikey | Bin 157 -> 157 bytes .../ace_ai_3.15.2.69/test.biprivatekey | Bin 605 -> 605 bytes 11 files changed, 30 insertions(+), 26 deletions(-) delete mode 100644 libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign.test diff --git a/Cargo.lock b/Cargo.lock index e8ef23e6..084bec67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,9 +142,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", ] diff --git a/bin/app/src/lib.rs b/bin/app/src/lib.rs index 1e2bf0d1..1b823345 100644 --- a/bin/app/src/lib.rs +++ b/bin/app/src/lib.rs @@ -48,13 +48,6 @@ 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) @@ -62,6 +55,16 @@ pub fn cli() -> Command { .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 } @@ -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); diff --git a/bin/app/src/modules/sign.rs b/bin/app/src/modules/sign.rs index cd0dcea8..03c01d7a 100644 --- a/bin/app/src/modules/sign.rs +++ b/bin/app/src/modules/sign.rs @@ -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")), @@ -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) diff --git a/bin/app/tests/build.rs b/bin/app/tests/build.rs index b48ed2c0..74732b4e 100644 --- a/bin/app/tests/build.rs +++ b/bin/app/tests/build.rs @@ -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(); } diff --git a/libs/preprocessor/src/lib.rs b/libs/preprocessor/src/lib.rs index b94bf05e..932620e7 100644 --- a/libs/preprocessor/src/lib.rs +++ b/libs/preprocessor/src/lib.rs @@ -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()); + } } } _ => { @@ -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()), diff --git a/libs/signing/src/private.rs b/libs/signing/src/private.rs index 7e424fa3..3b41bef9 100644 --- a/libs/signing/src/private.rs +++ b/libs/signing/src/private.rs @@ -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, @@ -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)); @@ -180,7 +177,7 @@ impl BIPrivateKey { /// /// # Panics /// If the qinv sign is not `NoSign`. - pub fn write(&self, output: &mut O) -> Result<(), Error> { + pub fn write_danger(&self, output: &mut O) -> Result<(), Error> { output.write_cstring(&self.authority)?; output.write_u32::(self.length / 16 * 9 + 20)?; output.write_all(b"\x07\x02\x00\x00\x00\x24\x00\x00")?; diff --git a/libs/signing/tests/bootstrap.rs b/libs/signing/tests/bootstrap.rs index 91978969..fcec1e18 100644 --- a/libs/signing/tests/bootstrap.rs +++ b/libs/signing/tests/bootstrap.rs @@ -1,4 +1,4 @@ -use std::fs::File; +use std::{fs::File, io::Write}; use hemtt_pbo::ReadablePbo; use hemtt_signing::BIPrivateKey; @@ -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() diff --git a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign index 77d8985c0516f2d26dcf40454ddda2507f84bb22..32c820b39e8012bf4a026e6e621b65888bffbbc4 100644 GIT binary patch delta 539 zcmV+$0_6Rz1g!*+9e?rq9Oq@}@-DH(WvAMD?*cPkN*(-dU9*LXpc@5HZb0u(h)CN^ z8MQx$!YR3;08ue(!s!69<@;|K~>(dlxB0{{R3fB*mhb}H&3yr9Ow_A+{-tTC$gfNNt|B|+(kPKiFq z)JVYexoHIH`}6aXTiIM6vXEri`=yw%M{!Kt3iduBS&cpv;VI|9I^TOrirJxzvp9(e z2v@^<>W~xFn~YYit4Q7hPB&o0mgtEg@n#B*89xVh$bVx?jg9^g_%XZT^fI=+K!5-M z09R$&x>R|{bTZ{ce(m!glIl67zeNoAc7pJ)|7-&A;X+mq#sYbcM*sD*7wy4hI+DPK zQw79)>$^&?Fd-hscj%UyzKq>mc3%*c#8G!LcDj!ahIB+6``dz4yo5EJIhL~Ep5TZf)}}R*aE?{5*Ik8f}CFibf)ss&~}_%UvFkhf~oU-26& zlQ*p0s=DhYo`00FW+dP+0{{R3fB*mh>)PA`?CRk?59=$;mqnflAlh+DHq$sBAP>n( z?yohCT!CzjPjNHYO3qC9(3MwJM7`k9?QW#zgKqRiaXu-pqEwKfVTr{6B+n~fF{))4 zp(*n2w4%2FTI2zI(vWFsR<%6aSg3n>1Wnm>Z2A>RJ3N8Yf6)S~#o8v7_bfq*-Ftr9qud#>A(MyT^ d;Gsxc;uNt=<7hzB)sJGXMqmTC=haiLFNu4i4Kn}$ diff --git a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign.test b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign.test deleted file mode 100644 index 77d8985c0516f2d26dcf40454ddda2507f84bb22..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 557 zcmV+|0@D3-Wpi`@lmGw#1_A&803-kaQd2=O00aO40RRC2&A5UWxpLS7!L$+=IHrP} zUjuZe^3u?DnoaDrUAF$T2gS?=>+?7cChDSSlrGdCN}I!83L{E*%WAS^G%gA0C(|(J zog@Knva#s;4N}7eYnSx^qCn3tMit7UH7Wd-{tJV!Yn>stu%Q6pgd7DjaB7})tB>aJ zd2D#UgWqw@fB*mhT-Z^J*>o{oCivsH%qEim8&r9j(gu7xP6q1_!j!VH@{WL@+9`73 zWOhA}u!*NI+wxIyBf2F;gGI=ka(Rg?!<^pm!enm_aSlhGn(%u8XI-45jrGxQHihw7 zn)w2)PA`?CRk? z59=$;mqnflAlh+DHq$sBAP>n(?yohCT!CzjPjNHYO3qC9(3MwJM7`k9?QW#zgKqRi zaXu-pqEwKfVTr{6B+n~fF{))4p(*n2w4%2FTI2zI(vWFsR<%6aSpMYrTAVow>_1G;kOjUqGr*8&talvVI?;PpA2CNE&`bqD}{NR v<1I~er8G`3wFXG9v4_jiONsp8p-5Zeu}tG=K-1NaVy;GD1GneZQ?4(G$Q2B+ diff --git a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.bikey b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.bikey index 670d066a2bcfe893551e2c47b79dab73362fbc90..d8c40a7bb0c1c5c6ea55c55cd4c4f19eaa551e0c 100644 GIT binary patch delta 136 zcmV;30C)eL0i6Mm9e?rq9Oq@}@-DH(WvAMD?*cPkN*(-dU9*LXpc@5HZb0u(h)CN^ z8MQx$!YR3;08ue(!s!69<@;|KTZf)}}R*aE?{5*Ik8f}CFibf)ss&~})py`l_gVBU+-5oF|>dGLa!FQlmXp+z{LXI+clQ$`*W}?Wk zjo_o|giU`@(3Vr${1-2~;RuQ(>fZ%AOp?)k%^0>c}D^p&2a_{8b7 zrV#+h_AC~kOn=1b!LW~lFo@9-qxS-aVhbTg>t3zWp%4Ij0lTkI;sGD#NS{0Dy7eDK zrevUd4xc)0r}xDf=ahJ+3^Iq@=F-{>p=~TdWI(v@oT$qk$bmqR1@md5NT$D3NS_S0 z0Q}Rt{ixXils?gK`9REHSLm0-ns=mGX@Thu2;ICAOn>Id zs3@%x{-;c2$sSwbgRKTgf9=bBS1+!|WdQrZ7iGX4^|b$X^eao-ieqH9jQumWRFmRI z1j&3L7)00MJ=a&~YMLC+1xB{fev3ugK?5m|-ji>|C8CWjhYP!?puhntpy&Wu_6S;> ZkUlcUKfB&i<0ez^m&B`MCBcKr2mwY(DwY5M delta 587 zcmV-R0<`_z1lTZf)}}R*aE?{5*Ik8f}CFibf)ss&~}JQpubiu~4oA?_M3sw=!!E6^?K`N0?xdPc!Jr zRDW}Rknus7aAhFJ0ACUoR@hY#_UB!PLvzv-@7zR?9e?uhOU&L)?|dI4h<8Xtp`B&u zPc)2rraQ0{hJS$KJ)>T+V?f#eOV)SszOv34i9KgE2~$C2#3a0KG1&4o?`mDswyQbV zW(-C_iWbni>ORd`h`>7n+fg*yKW*SZ!O(tz?Q`pxpuP1LjRsfglYsx0nPd^VSCxD;O&s0idR{5 z)6-6Em~F9dXmwbq#30LH$k)x}_q4>;mnuj@O!w8Kyr@GTA9~6HH-vPmwU3%#EMWuh z)L7y8s@jb}yN9s2SU(QqtEg4t2S_^Bo@Ej+(&2iHWQ*SY5J70M`rM%tyJLZF+!7^) zxPGCzkwo`aukNT|DH`_T)`yjdo$`xRJHGocM(MdHyUJev5QIzu@v-