Skip to content

Commit 854bbed

Browse files
author
REinject
committed
v0.1.3
- Fix some minor issues.
1 parent 2884930 commit 854bbed

File tree

6 files changed

+43
-18
lines changed

6 files changed

+43
-18
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pe-sign"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2021"
55
authors = ["REinject"]
66
homepage = "https://github.com/0xlane/pe-sign"
@@ -45,3 +45,4 @@ sha1 = { version = "0.10.6", features = ["oid"] }
4545
sha2 = { version = "0.10.8", features = ["oid"] }
4646
x509-cert = { version = "0.2.5", features = ["sct"] }
4747
chrono = "0.4.38"
48+
num-traits = "0.2.19"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Alternatively, if you have `Cargo` installed, you can easily install it by runni
3333
### Usage
3434

3535
```powershell
36-
pe-sign (0.1.2) - REinject
36+
pe-sign (0.1.3) - REinject
3737
A tool for parsing and verifing PE file signatures
3838
3939
Repository: https://github.com/0xlane/pe-sign
@@ -110,11 +110,12 @@ Certificate:
110110
Subject Public Key Info:
111111
Algorithm: RSA
112112
Public-Key: (2048 bit)
113-
Modules:
113+
Modulus:
114114
00:cc:2e:a1:52:49:09:cc:22:ef:34:43:dc:41:a6:98:a0:1f:0f:69:
115115
1a:33:b2:92:a5:73:26:4e:1d:b9:e2:ab:c4:46:e1:3e:f9:24:c2:f6:
116116
...
117117
...
118+
Exponent: 65537 (0x10001)
118119
Extensions:
119120
Authority Key Identifier:
120121
97:48:03:eb:15:08:6b:b9:b2:58:23:cc:94:2e:f1:c6:65:d2:64:8e

README_zh.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
### 使用说明
3434

3535
```powershell
36-
pe-sign (0.1.2) - REinject
36+
pe-sign (0.1.3) - REinject
3737
A tool for parsing and verifing PE file signatures
3838
3939
Repository: https://github.com/0xlane/pe-sign
@@ -110,11 +110,12 @@ Certificate:
110110
Subject Public Key Info:
111111
Algorithm: RSA
112112
Public-Key: (2048 bit)
113-
Modules:
113+
Modulus:
114114
00:cc:2e:a1:52:49:09:cc:22:ef:34:43:dc:41:a6:98:a0:1f:0f:69:
115115
1a:33:b2:92:a5:73:26:4e:1d:b9:e2:ab:c4:46:e1:3e:f9:24:c2:f6:
116116
...
117117
...
118+
Exponent: 65537 (0x10001)
118119
Extensions:
119120
Authority Key Identifier:
120121
97:48:03:eb:15:08:6b:b9:b2:58:23:cc:94:2e:f1:c6:65:d2:64:8e

src/cert/certificate.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use der::{
1010
Decode, Encode,
1111
};
1212
use digest::{Digest, DynDigest};
13+
use num_traits::ToPrimitive;
1314
use rsa::{pkcs1::DecodeRsaPublicKey, traits::PublicKeyParts, Pkcs1v15Sign, RsaPublicKey};
1415
use sha1::Sha1;
1516
use sha2::{Sha224, Sha256, Sha384, Sha512};
@@ -24,7 +25,6 @@ use super::{
2425
name::RdnSequence,
2526
};
2627

27-
2828
/// Parse Certificate.
2929
#[derive(Clone, Debug, Eq, PartialEq)]
3030
pub struct Certificate {
@@ -73,7 +73,11 @@ impl Display for Certificate {
7373
format!("Version: {} (0x{:x})", self.version + 1, self.version).indent(8)
7474
)?;
7575
writeln!(f, "{}", "Serial Number:".indent(8))?;
76-
writeln!(f, "{}", self.serial_number.clone().to_bytes_string().indent(12))?;
76+
writeln!(
77+
f,
78+
"{}",
79+
self.serial_number.clone().to_bytes_string().indent(12)
80+
)?;
7781
writeln!(f, "{}", format!("Issuer: {}", self.issuer).indent(8))?;
7882
writeln!(f, "{}", self.validity.to_string().indent(8))?;
7983
writeln!(f, "{}", format!("Subject: {}", self.subject).indent(8))?;
@@ -91,7 +95,11 @@ impl Display for Certificate {
9195
format!("Signature Algorithm: {}", self.signature_algorithm).indent(4)
9296
)?;
9397
writeln!(f, "{}", "Signature Value:".indent(4))?;
94-
write!(f, "{}", self.signature_value.clone().to_bytes_string().indent(12))
98+
write!(
99+
f,
100+
"{}",
101+
self.signature_value.clone().to_bytes_string().indent(12)
102+
)
95103
}
96104
}
97105

@@ -188,7 +196,7 @@ impl Certificate {
188196
}
189197
}
190198

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

396404
impl Display for SubjectPublicKeyInfo {
397405
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
406+
let mudulus = self.get_public_key_modulus();
407+
let exponent = self.get_public_key_exponent().unwrap_or(0);
408+
398409
writeln!(f, "Subject Public Key Info:")?;
399410
writeln!(
400411
f,
@@ -404,18 +415,20 @@ impl Display for SubjectPublicKeyInfo {
404415
writeln!(
405416
f,
406417
"{}",
407-
format!(
408-
"Public-Key: ({} bit)\nModules:",
409-
(self.get_public_key_modules().len() - 1) * 8
410-
)
411-
.indent(4)
418+
format!("Public-Key: ({} bit)\nModulus:", (mudulus.len() - 1) * 8).indent(4)
412419
)?;
413-
write!(f, "{}", self.get_public_key_modules().to_bytes_string().indent(8))
420+
writeln!(f, "{}", mudulus.to_bytes_string().indent(8))?;
421+
write!(
422+
f,
423+
"{}",
424+
format!("Exponent: {} (0x{:x})", exponent, exponent).indent(4)
425+
)
414426
}
415427
}
416428

417429
impl SubjectPublicKeyInfo {
418-
pub fn get_public_key_modules(self: &Self) -> Vec<u8> {
430+
/// Returns the modulus of the key.
431+
pub fn get_public_key_modulus(self: &Self) -> Vec<u8> {
419432
match &self.__inner_public_key {
420433
Some(rsa_public_key) => {
421434
let mut tmp = rsa_public_key.n().to_bytes_be();
@@ -425,4 +438,12 @@ impl SubjectPublicKeyInfo {
425438
None => self.subject_public_key.clone(),
426439
}
427440
}
441+
442+
/// Returns the public exponent of the key.
443+
pub fn get_public_key_exponent(self: &Self) -> Option<usize> {
444+
match &self.__inner_public_key {
445+
Some(rsa_public_key) => rsa_public_key.e().to_usize(),
446+
None => None,
447+
}
448+
}
428449
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn cli() -> clap::Command {
1313
use clap::{arg, value_parser, Command};
1414

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

0 commit comments

Comments
 (0)