Skip to content

Commit

Permalink
Merge branch 'CORE-178' into 'develop'
Browse files Browse the repository at this point in the history
CORE-178: Extract Key IDs

See merge request foundation/planckCoreSequoiaBackend!12
  • Loading branch information
ip-plank-security committed Nov 2, 2023
2 parents 43eebda + 2141e83 commit 1e0885f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,25 @@ impl Keystore {
_ => (),
}
}
} else if pattern.len() >= 16
} else if pattern.len() == 16
&& pattern.chars()
.all(|c| {
match c {
'0' | '1' | '2' | '3' | '4'
| '5' | '6' | '7' | '8' | '9'
| 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
| ' ' => {
true
}
_ => false,
}
})
{
let keyid = KeyID::from_hex(pattern).expect("valid key ID");
let (cert, _private) = self.cert_find_with_key(keyid, private_only)?;
add_key(&cert);
} else if pattern.len() > 16
&& pattern.chars()
.all(|c| {
match c {
Expand Down
44 changes: 44 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ use openpgp::packet::{
use openpgp::parse::{
Parse,
PacketParser,
PacketParserResult,
PacketParserBuilder,
stream::{
DecryptionHelper,
DecryptorBuilder,
Expand Down Expand Up @@ -761,6 +763,48 @@ impl<'a> DecryptionHelper for &mut Helper<'a> {
}
}

ffi!(fn pgp_get_key_ids(session: *mut Session,
ctext: *const c_char, csize: size_t,
keylistp: *mut *mut StringListItem)
-> Result<()>
{
let session = Session::as_mut(session)?;

let mm = session.mm();

let message: &[u8] = unsafe { check_slice!(ctext, csize) };

// Create an empty StringList
let mut list = StringList::empty(mm);

let mut pkesks: Vec<PKESK> = Vec::new(); // Accumulator for PKESKs.

let mut ppr = PacketParserBuilder::from_bytes(message)
.expect("NOT EOF").build().unwrap();

while let PacketParserResult::Some(pp) = ppr {
let (packet, ppr_) = pp.recurse().expect("Parsing message");
ppr = ppr_;
match packet {
Packet::PKESK(p) => pkesks.push(p),
_ => (),
}
}

if let PacketParserResult::EOF(eof) = ppr {
let is_message = eof.is_message();
if is_message.is_ok() {
for pkesk in pkesks.iter() {
list.add(pkesk.recipient().to_hex());
}
}
}

unsafe { *keylistp = list.to_c() };

return Err(Error::StatusOk);
});

// PEP_STATUS pgp_decrypt_and_verify(
// PEP_SESSION session, const char *ctext, size_t csize,
// const char *dsigtext, size_t dsigsize,
Expand Down

0 comments on commit 1e0885f

Please sign in to comment.