Skip to content

Commit

Permalink
Parse PKCS12 using BER encoding rules for compatibility with keystore…
Browse files Browse the repository at this point in the history
…s produced by Java keytool.
  • Loading branch information
ancwrd1 committed Jul 23, 2023
1 parent f2eedd6 commit fe44459
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl PFX {
}

pub fn parse(bytes: &[u8]) -> Result<PFX, ASN1Error> {
yasna::parse_der(bytes, |r| {
yasna::parse_ber(bytes, |r| {
r.read_sequence(|r| {
let version = r.next().read_u8()?;
let auth_safe = ContentInfo::parse(r.next())?;
Expand Down Expand Up @@ -529,15 +529,15 @@ impl PFX {
.data(&password)
.ok_or_else(|| ASN1Error::new(ASN1ErrorKind::Invalid))?;

let contents = yasna::parse_der(&data, |r| r.collect_sequence_of(ContentInfo::parse))?;
let contents = yasna::parse_ber(&data, |r| r.collect_sequence_of(ContentInfo::parse))?;

let mut result = vec![];
for content in contents.iter() {
let data = content
.data(&password)
.ok_or_else(|| ASN1Error::new(ASN1ErrorKind::Invalid))?;

let safe_bags = yasna::parse_der(&data, |r| r.collect_sequence_of(SafeBag::parse))?;
let safe_bags = yasna::parse_ber(&data, |r| r.collect_sequence_of(SafeBag::parse))?;

for safe_bag in safe_bags.iter() {
result.push(safe_bag.to_owned())
Expand Down

0 comments on commit fe44459

Please sign in to comment.