Skip to content

Commit

Permalink
Support custom password options attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs authored and kornelski committed Dec 18, 2024
1 parent b2189b2 commit 878034e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions security-framework/src/passwords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ pub fn set_generic_password(service: &str, account: &str, password: &[u8]) -> Re
set_password_internal(&mut options, password)
}

/// Set a generic password using the given password options.
/// Creates or updates a keychain entry.
pub fn set_generic_password_options(
password: &[u8],
mut options: PasswordOptions) -> Result<()> {
set_password_internal(&mut options, password)
}

/// Get the generic password for the given service and account. If no matching
/// keychain entry exists, fails with error code `errSecItemNotFound`.
pub fn get_generic_password(service: &str, account: &str) -> Result<Vec<u8>> {
Expand Down
10 changes: 9 additions & 1 deletion security-framework/src/passwords_options.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Support for password options, to be used with the passwords module
use core_foundation::{string::CFString, base::{CFType, TCFType, CFOptionFlags}, number::CFNumber};
use security_framework_sys::{keychain::{SecProtocolType, SecAuthenticationType}, access_control::*};
use security_framework_sys::{access_control::*, item::kSecAttrAccessGroup, keychain::{SecAuthenticationType, SecProtocolType}};
use security_framework_sys::item::{
kSecAttrAccessControl, kSecAttrAccount, kSecAttrAuthenticationType, kSecAttrPath, kSecAttrPort, kSecAttrProtocol,
kSecAttrSecurityDomain, kSecAttrServer, kSecAttrService, kSecClass, kSecClassGenericPassword,
Expand Down Expand Up @@ -127,4 +127,12 @@ impl PasswordOptions {
.into_CFType(),
));
}

/// Add access group to the password
pub fn set_access_group(&mut self, group: &str) {
self.query.push((
unsafe { CFString::wrap_under_get_rule(kSecAttrAccessGroup) },
CFString::from(group).into_CFType(),
));
}
}

0 comments on commit 878034e

Please sign in to comment.