Skip to content

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
- Fix some minor issues.
  • Loading branch information
REinject committed Sep 11, 2024
1 parent 2884930 commit 854bbed
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pe-sign"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["REinject"]
homepage = "https://github.com/0xlane/pe-sign"
Expand Down Expand Up @@ -45,3 +45,4 @@ sha1 = { version = "0.10.6", features = ["oid"] }
sha2 = { version = "0.10.8", features = ["oid"] }
x509-cert = { version = "0.2.5", features = ["sct"] }
chrono = "0.4.38"
num-traits = "0.2.19"
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Alternatively, if you have `Cargo` installed, you can easily install it by runni
### Usage

```powershell
pe-sign (0.1.2) - REinject
pe-sign (0.1.3) - REinject
A tool for parsing and verifing PE file signatures
Repository: https://github.com/0xlane/pe-sign
Expand Down Expand Up @@ -110,11 +110,12 @@ Certificate:
Subject Public Key Info:
Algorithm: RSA
Public-Key: (2048 bit)
Modules:
Modulus:
00:cc:2e:a1:52:49:09:cc:22:ef:34:43:dc:41:a6:98:a0:1f:0f:69:
1a:33:b2:92:a5:73:26:4e:1d:b9:e2:ab:c4:46:e1:3e:f9:24:c2:f6:
...
...
Exponent: 65537 (0x10001)
Extensions:
Authority Key Identifier:
97:48:03:eb:15:08:6b:b9:b2:58:23:cc:94:2e:f1:c6:65:d2:64:8e
Expand Down
5 changes: 3 additions & 2 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
### 使用说明

```powershell
pe-sign (0.1.2) - REinject
pe-sign (0.1.3) - REinject
A tool for parsing and verifing PE file signatures
Repository: https://github.com/0xlane/pe-sign
Expand Down Expand Up @@ -110,11 +110,12 @@ Certificate:
Subject Public Key Info:
Algorithm: RSA
Public-Key: (2048 bit)
Modules:
Modulus:
00:cc:2e:a1:52:49:09:cc:22:ef:34:43:dc:41:a6:98:a0:1f:0f:69:
1a:33:b2:92:a5:73:26:4e:1d:b9:e2:ab:c4:46:e1:3e:f9:24:c2:f6:
...
...
Exponent: 65537 (0x10001)
Extensions:
Authority Key Identifier:
97:48:03:eb:15:08:6b:b9:b2:58:23:cc:94:2e:f1:c6:65:d2:64:8e
Expand Down
43 changes: 32 additions & 11 deletions src/cert/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use der::{
Decode, Encode,
};
use digest::{Digest, DynDigest};
use num_traits::ToPrimitive;
use rsa::{pkcs1::DecodeRsaPublicKey, traits::PublicKeyParts, Pkcs1v15Sign, RsaPublicKey};
use sha1::Sha1;
use sha2::{Sha224, Sha256, Sha384, Sha512};
Expand All @@ -24,7 +25,6 @@ use super::{
name::RdnSequence,
};


/// Parse Certificate.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Certificate {
Expand Down Expand Up @@ -73,7 +73,11 @@ impl Display for Certificate {
format!("Version: {} (0x{:x})", self.version + 1, self.version).indent(8)
)?;
writeln!(f, "{}", "Serial Number:".indent(8))?;
writeln!(f, "{}", self.serial_number.clone().to_bytes_string().indent(12))?;
writeln!(
f,
"{}",
self.serial_number.clone().to_bytes_string().indent(12)
)?;
writeln!(f, "{}", format!("Issuer: {}", self.issuer).indent(8))?;
writeln!(f, "{}", self.validity.to_string().indent(8))?;
writeln!(f, "{}", format!("Subject: {}", self.subject).indent(8))?;
Expand All @@ -91,7 +95,11 @@ impl Display for Certificate {
format!("Signature Algorithm: {}", self.signature_algorithm).indent(4)
)?;
writeln!(f, "{}", "Signature Value:".indent(4))?;
write!(f, "{}", self.signature_value.clone().to_bytes_string().indent(12))
write!(
f,
"{}",
self.signature_value.clone().to_bytes_string().indent(12)
)
}
}

Expand Down Expand Up @@ -188,7 +196,7 @@ impl Certificate {
}
}

/// Get the tbs_certificate binary data for validating its trustworthiness,
/// Get the tbs_certificate binary data for validating its trustworthiness,
/// and the decrypted signature is the hash of tbs_certificate.
pub fn get_tbs_certificate_bytes(self: &Self) -> Vec<u8> {
self.__inner.tbs_certificate.to_der().unwrap()
Expand Down Expand Up @@ -395,6 +403,9 @@ impl TryFrom<x509_cert::spki::SubjectPublicKeyInfoOwned> for SubjectPublicKeyInf

impl Display for SubjectPublicKeyInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mudulus = self.get_public_key_modulus();
let exponent = self.get_public_key_exponent().unwrap_or(0);

writeln!(f, "Subject Public Key Info:")?;
writeln!(
f,
Expand All @@ -404,18 +415,20 @@ impl Display for SubjectPublicKeyInfo {
writeln!(
f,
"{}",
format!(
"Public-Key: ({} bit)\nModules:",
(self.get_public_key_modules().len() - 1) * 8
)
.indent(4)
format!("Public-Key: ({} bit)\nModulus:", (mudulus.len() - 1) * 8).indent(4)
)?;
write!(f, "{}", self.get_public_key_modules().to_bytes_string().indent(8))
writeln!(f, "{}", mudulus.to_bytes_string().indent(8))?;
write!(
f,
"{}",
format!("Exponent: {} (0x{:x})", exponent, exponent).indent(4)
)
}
}

impl SubjectPublicKeyInfo {
pub fn get_public_key_modules(self: &Self) -> Vec<u8> {
/// Returns the modulus of the key.
pub fn get_public_key_modulus(self: &Self) -> Vec<u8> {
match &self.__inner_public_key {
Some(rsa_public_key) => {
let mut tmp = rsa_public_key.n().to_bytes_be();
Expand All @@ -425,4 +438,12 @@ impl SubjectPublicKeyInfo {
None => self.subject_public_key.clone(),
}
}

/// Returns the public exponent of the key.
pub fn get_public_key_exponent(self: &Self) -> Option<usize> {
match &self.__inner_public_key {
Some(rsa_public_key) => rsa_public_key.e().to_usize(),
None => None,
}
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn cli() -> clap::Command {
use clap::{arg, value_parser, Command};

Command::new("pe-sign")
.version("0.1.2")
.version("0.1.3")
.about("A tool for parsing and verifing PE file signatures\n\nRepository: https://github.com/0xlane/pe-sign\n")
.author("REinject")
.help_template("{name} ({version}) - {author}\n{about}\n{all-args}")
Expand Down

0 comments on commit 854bbed

Please sign in to comment.