Skip to content

Commit bfb0330

Browse files
brotskydotcomkornelski
authored andcommitted
Allow item searches to ignore legacy keychains.
Fixes #238.
1 parent 8a66d5e commit bfb0330

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

security-framework/src/item.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub struct ItemSearchOptions {
128128
keychains: Option<CFArray<SecKeychain>>,
129129
#[cfg(not(target_os = "macos"))]
130130
keychains: Option<CFArray<CFType>>,
131+
ignore_legacy_keychains: bool, // defined everywhere, only consulted on macOS
131132
case_insensitive: Option<bool>,
132133
class: Option<ItemClass>,
133134
key_class: Option<KeyClass>,
@@ -157,6 +158,12 @@ impl crate::ItemSearchOptionsInternals for ItemSearchOptions {
157158
self.keychains = Some(CFArray::from_CFTypes(keychains));
158159
self
159160
}
161+
162+
#[inline]
163+
fn ignore_legacy_keychains(&mut self) -> &mut Self {
164+
self.ignore_legacy_keychains = true;
165+
self
166+
}
160167
}
161168

162169
impl ItemSearchOptions {
@@ -340,6 +347,15 @@ impl ItemSearchOptions {
340347
&keychains.as_CFType().to_void(),
341348
);
342349
}
350+
else {
351+
if self.ignore_legacy_keychains {
352+
#[cfg(all(target_os = "macos", feature = "OSX_10_15"))]
353+
params.add(
354+
&kSecUseDataProtectionKeychain.to_void(),
355+
&CFBoolean::true_value().to_void(),
356+
)
357+
}
358+
}
343359

344360
if let Some(class) = self.class {
345361
params.add(&kSecClass.to_void(), &class.0.to_void());

security-framework/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ trait Pkcs12ImportOptionsInternals {
6464
#[cfg(target_os = "macos")]
6565
trait ItemSearchOptionsInternals {
6666
fn keychains(&mut self, keychains: &[SecKeychain]) -> &mut Self;
67+
fn ignore_legacy_keychains(&mut self) -> &mut Self;
6768
}
6869

6970
trait AsInner {

security-framework/src/os/macos/item.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@ pub trait ItemSearchOptionsExt {
1212
///
1313
/// If this is not called, the default keychain will be searched.
1414
fn keychains(&mut self, keychains: &[SecKeychain]) -> &mut Self;
15+
16+
/// Only search the protected data keychains.
17+
///
18+
/// Has no effect if a legacy keychain has been explicitly specified
19+
/// using [keychains](ItemSearchOptionsExt::keychains).
20+
///
21+
/// Has no effect except in sandboxed applications on macOS 10.15 and above
22+
fn ignore_legacy_keychains(&mut self) -> &mut Self;
1523
}
1624

1725
impl ItemSearchOptionsExt for ItemSearchOptions {
1826
#[inline(always)]
1927
fn keychains(&mut self, keychains: &[SecKeychain]) -> &mut Self {
2028
ItemSearchOptionsInternals::keychains(self, keychains)
2129
}
30+
31+
#[inline(always)]
32+
fn ignore_legacy_keychains(&mut self) -> &mut Self {
33+
ItemSearchOptionsInternals::ignore_legacy_keychains(self)
34+
}
2235
}
2336

2437
#[cfg(test)]

0 commit comments

Comments
 (0)