Skip to content

Commit 6a205d9

Browse files
author
REinject
committed
v0.1.7
- Fix the display for RDNs with unknown OIDs. Changelog: v0.1.6...v0.1.7
1 parent 0c17952 commit 6a205d9

File tree

6 files changed

+50
-24
lines changed

6 files changed

+50
-24
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pe-sign"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55
authors = ["REinject"]
66
homepage = "https://github.com/0xlane/pe-sign"

README.md

Lines changed: 1 addition & 1 deletion
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.6) - REinject
36+
pe-sign (0.1.7) - REinject
3737
A tool for parsing and verifing PE file signatures
3838
3939
Repository: https://github.com/0xlane/pe-sign

README_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
### 使用说明
3434

3535
```powershell
36-
pe-sign (0.1.6) - REinject
36+
pe-sign (0.1.7) - REinject
3737
A tool for parsing and verifing PE file signatures
3838
3939
Repository: https://github.com/0xlane/pe-sign

src/cert/name.rs

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl From<x509_cert::name::RelativeDistinguishedName> for RelativeDistinguishedN
8282
.0
8383
.iter()
8484
.map(|tv| {
85-
let mut ss;
8685
let val = match tv.value.tag() {
8786
Tag::PrintableString => PrintableStringRef::try_from(&tv.value)
8887
.ok()
@@ -119,31 +118,46 @@ impl From<x509_cert::name::RelativeDistinguishedName> for RelativeDistinguishedN
119118
best_match
120119
};
121120

122-
if let (Some(key), Some(val)) = (key, val) {
123-
ss = format!("{}=", key.to_ascii_uppercase());
121+
let key_ss = match key {
122+
Some(key) => key.to_ascii_uppercase(),
123+
None => tv.oid.to_string(),
124+
};
124125

125-
let mut iter = val.char_indices().peekable();
126-
while let Some((i, c)) = iter.next() {
127-
match c {
128-
'#' if i == 0 => ss.push_str("\\#"),
129-
' ' if i == 0 || iter.peek().is_none() => ss.push_str("\\ "),
130-
'"' | '+' | ',' | ';' | '<' | '>' | '\\' => {
131-
ss = format!("{}\\{}", ss, c)
126+
let val_ss = match val {
127+
Some(val) => {
128+
let mut val_ss = String::new();
129+
let mut iter = val.char_indices().peekable();
130+
while let Some((i, c)) = iter.next() {
131+
match c {
132+
'#' if i == 0 => val_ss.push_str("\\#"),
133+
' ' if i == 0 || iter.peek().is_none() => {
134+
val_ss.push_str("\\ ")
135+
}
136+
'"' | '+' | ',' | ';' | '<' | '>' | '\\' => {
137+
val_ss = val_ss + &format!("\\{}", c);
138+
}
139+
'\x00'..='\x1f' | '\x7f' => {
140+
val_ss = val_ss + &format!("\\{:02x}", c as u8)
141+
}
142+
_ => val_ss.push(c),
132143
}
133-
'\x00'..='\x1f' | '\x7f' => ss = format!("{}\\{:02x}", ss, c as u8),
134-
_ => ss.push(c),
135144
}
145+
146+
val_ss
136147
}
137-
} else {
138-
let value = tv.value.to_der().unwrap();
148+
None => {
149+
let mut val_ss = "#".to_owned();
150+
let value = tv.value.to_der().unwrap();
151+
152+
for c in value {
153+
val_ss = val_ss + &format!("{:02x}", c);
154+
}
139155

140-
ss = format!("{}=#", tv.oid);
141-
for c in value {
142-
ss = format!("{}{:02x}", ss, c);
156+
val_ss
143157
}
144-
}
158+
};
145159

146-
ss
160+
format!("{}={}", key_ss, val_ss)
147161
})
148162
.collect(),
149163
)
@@ -183,4 +197,16 @@ mod tests {
183197

184198
assert_eq!(rdn.to_string(), "CN=晓羽");
185199
}
200+
201+
#[test]
202+
fn test_unkown_rdn_oid() {
203+
let der_rdn = x509_cert::name::RelativeDistinguishedName::from_der(
204+
b"\x31\x13\x30\x11\x06\x0b\x2b\x06\x01\x04\x01\x82\x37\x3c\x02\x01\x03\x13\x02\x43\x4e",
205+
)
206+
.unwrap();
207+
208+
let rdn = RelativeDistinguishedName::from(der_rdn);
209+
210+
assert_eq!(rdn.to_string(), "1.3.6.1.4.1.311.60.2.1.3=CN");
211+
}
186212
}

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.6")
16+
.version("0.1.7")
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)