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

How to fix "MissingEntitlement: SecKeychainItemCopyContent refused to return data"? #22

Open
hktonylee opened this issue Apr 26, 2019 · 3 comments

Comments

@hktonylee
Copy link

hktonylee commented Apr 26, 2019

I tried to run the following program but it panic with: "Error { kind: MissingEntitlement, backtrace: , description: "SecKeychainItemCopyContent refused to return data" }"

extern crate keychain_services;

use keychain_services::{Keychain, keychain};

fn main() {
    println!("Getting keychain...");
    if let Ok(default_keychain) = Keychain::find_default() {
        println!("Getting password...");
        if let Ok(generic_password)
            = keychain::item::GenericPassword::find(&default_keychain, "TestTest", "user") {
            println!("Printing password...");
            println!("Password: {}", generic_password.password().unwrap().as_str())
        }
    }
}

I tried codesign as instructed in the Apple Developer guide. I created a self-signed certificate. Then I used gimmedebugah to inject Info.plist to the binary. Lastly I run the codesign using the self-signed certificate. I can verify the app is correctly signed with the following command

> codesign --verify --deep --strict --verbose=2 my_app
my_app: valid on disk
my_app: satisfies its Designated Requirement

In the Info.plist injection step, I also tried to linker flag -sectcreate __TEXT __info_plist Info.plist -o my_app.out to the .cargo/config.

But the app still cannot retrieve password from keychain. Now I have no clue what to do next. Would you mind sharing any step-by-step guideline? It will be very useful!

@hktonylee
Copy link
Author

It is probably the place where the error is thrown:

Err(Error::new(
ErrorKind::MissingEntitlement,
"SecKeychainItemCopyContent refused to return data",
))

Actually I succeeded to get password without any codesign using another library: https://github.com/kornelski/rust-security-framework. Therefore I think this error is not caused by codesign. I suggest other people not to dig into this problem anymore.

@tarcieri
Copy link
Contributor

@hktonylee now that rust-security-framework is maintained again, it's probably the way to go, especially as it's already working for you

@hktonylee
Copy link
Author

@tarcieri Yes that's true. Although that already spent me several hours :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants