Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = ["authenticode", "authenticode-tool", "xtask"]
resolver = "2"

[workspace.package]
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/google/authenticode-rs"
rust-version = "1.85"
Expand Down
70 changes: 41 additions & 29 deletions authenticode-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#![forbid(unsafe_code)]

use anyhow::{anyhow, bail, Result};
use anyhow::{Result, anyhow, bail};
use authenticode::{
AttributeCertificateIterator, AuthenticodeSignature, PeTrait,
};
Expand Down Expand Up @@ -162,10 +162,12 @@ mod tests {
#[test]
fn test_action_info() {
// Error: bad path.
assert!(run_action(&Action::Info {
pe_path: "../authenticode/tests/testdata/bad.efi".into(),
})
.is_err());
assert!(
run_action(&Action::Info {
pe_path: "../authenticode/tests/testdata/bad.efi".into(),
})
.is_err()
);

// Success, no signatures.
run_action(&Action::Info {
Expand All @@ -189,36 +191,46 @@ mod tests {
#[test]
fn test_action_get_cert() {
// Error: bad path.
assert!(run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/bad.efi".into(),
sig_index: 0,
cert_index: 0,
}))
.is_err());
assert!(
run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/bad.efi".into(),
sig_index: 0,
cert_index: 0,
}))
.is_err()
);

// Error: no signatures.
assert!(run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/tiny64.efi".into(),
sig_index: 0,
cert_index: 0,
}))
.is_err());
assert!(
run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/tiny64.efi".into(),
sig_index: 0,
cert_index: 0,
}))
.is_err()
);

// Error: invalid signature index.
assert!(run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/tiny64.signed.efi".into(),
sig_index: 1,
cert_index: 0,
}))
.is_err());
assert!(
run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/tiny64.signed.efi"
.into(),
sig_index: 1,
cert_index: 0,
}))
.is_err()
);

// Error: invalid certificate index.
assert!(run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/tiny64.signed.efi".into(),
sig_index: 0,
cert_index: 1,
}))
.is_err());
assert!(
run_action(&Action::GetCert(GetCertAction {
pe_path: "../authenticode/tests/testdata/tiny64.signed.efi"
.into(),
sig_index: 0,
cert_index: 1,
}))
.is_err()
);

// Success, 32-bit.
run_action(&Action::GetCert(GetCertAction {
Expand Down
4 changes: 2 additions & 2 deletions authenticode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub use authenticode_digest::authenticode_digest;
pub use pe::{PeOffsetError, PeOffsets, PeTrait};
pub use signature::{
AuthenticodeSignature, AuthenticodeSignatureParseError, DigestInfo,
SpcAttributeTypeAndOptionalValue, SpcIndirectDataContent,
SPC_INDIRECT_DATA_OBJID,
SPC_INDIRECT_DATA_OBJID, SpcAttributeTypeAndOptionalValue,
SpcIndirectDataContent,
};
pub use win_cert::{
AttributeCertificate, AttributeCertificateAuthenticodeError,
Expand Down
4 changes: 2 additions & 2 deletions authenticode/src/pe_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::pe::{PeOffsetError, PeOffsets, PeTrait};
use crate::usize_from_u32;
use core::mem;
use core::ops::Range;
use object::pe::{ImageDataDirectory, IMAGE_DIRECTORY_ENTRY_SECURITY};
use object::pe::{IMAGE_DIRECTORY_ENTRY_SECURITY, ImageDataDirectory};
use object::read::pe::ImageOptionalHeader;
use object::read::pe::{ImageNtHeaders, PeFile};
use object::{pod, LittleEndian, SectionIndex};
use object::{LittleEndian, SectionIndex, pod};

impl<'data, I> PeTrait for PeFile<'data, I>
where
Expand Down
2 changes: 1 addition & 1 deletion authenticode/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use cms::content_info::CmsVersion;
use cms::content_info::ContentInfo;
use cms::signed_data::{SignedData, SignerInfo};
use core::fmt::{self, Display, Formatter};
use der::asn1::{ObjectIdentifier, OctetString};
use der::Decode;
use der::asn1::{ObjectIdentifier, OctetString};
use der::{Sequence, SliceReader};
use x509_cert::Certificate;

Expand Down
12 changes: 9 additions & 3 deletions authenticode/src/win_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::usize_from_u32;
use crate::PeTrait;
use crate::usize_from_u32;
use crate::{AuthenticodeSignature, AuthenticodeSignatureParseError};
use core::fmt::{self, Display, Formatter};

Expand Down Expand Up @@ -59,10 +59,16 @@ impl Display for AttributeCertificateError {
write!(f, "certificate table range is out of bounds")
}
Self::InvalidSize => {
write!(f, "certificate table size does not match the sum of the certificate entry's aligned sizes")
write!(
f,
"certificate table size does not match the sum of the certificate entry's aligned sizes"
)
}
Self::InvalidCertificateSize { size } => {
write!(f, "certificate table contains an entry with an invalid size: {size}")
write!(
f,
"certificate table contains an entry with an invalid size: {size}"
)
}
}
}
Expand Down
26 changes: 16 additions & 10 deletions authenticode/tests/test_authenticode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use core::slice;
use digest::{Digest, Update};
use object::endian::LittleEndian as LE;
use object::pe::{
ImageDataDirectory, ImageFileHeader, ImageOptionalHeader64,
IMAGE_DIRECTORY_ENTRY_SECURITY,
IMAGE_DIRECTORY_ENTRY_SECURITY, ImageDataDirectory, ImageFileHeader,
ImageOptionalHeader64,
};
use object::read::pe::{PeFile32, PeFile64};
use sha1::Sha1;
Expand Down Expand Up @@ -127,20 +127,26 @@ fn check_exe(pe: &dyn PeTrait, expected: Expected) {
fn test_authenticode32() {
let pe = include_bytes!("testdata/tiny32.signed.efi");
let pe64 = PeFile32::parse(pe.as_slice()).unwrap();
check_exe(&pe64, Expected {
sha1: "49f239f1cd5083912880e03982bb54528f2c358d",
sha256: "4f5b3633fc51d9447beb5c546e9ae6e58d6eb42d1e96d623dc168d97013c08a8",
});
check_exe(
&pe64,
Expected {
sha1: "49f239f1cd5083912880e03982bb54528f2c358d",
sha256: "4f5b3633fc51d9447beb5c546e9ae6e58d6eb42d1e96d623dc168d97013c08a8",
},
);
}

#[test]
fn test_authenticode64() {
let pe = include_bytes!("testdata/tiny64.signed.efi");
let pe64 = PeFile64::parse(pe.as_slice()).unwrap();
check_exe(&pe64, Expected {
sha1: "e9bdfb63bdf687b8d3bf144033fcb09d7a393563",
sha256: "a82d7e4f091c44ec75d97746b3461c8ea9151e2313f8e9a4330432ee5f25b2ae",
});
check_exe(
&pe64,
Expected {
sha1: "e9bdfb63bdf687b8d3bf144033fcb09d7a393563",
sha256: "a82d7e4f091c44ec75d97746b3461c8ea9151e2313f8e9a4330432ee5f25b2ae",
},
);
}

fn modify_image_security_data_dir<F>(f: F) -> Vec<u8>
Expand Down