Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user-defined generic password options/attributes. #220

Merged
merged 1 commit into from
Dec 18, 2024
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
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(),
));
}
}
Loading