I'm trying to retrieve a password from a keychain with rubyMotion, on OS X
I tried this :
# passsword_data_pointer=Pointer.new(:object) #works but empty password
# password_data_pointer=Pointer.new('^') #makes ruby crash and complain 'Can't find pointer description for type '^'
password_data=NSMutableData.new #works but empty password
password_length = Pointer.new('I')
result=SecKeychainFindGenericPassword (
nil,
"some_service_string".length,
"some_service_string",
"some_username_string".length,
"some_username_string",
password_length,
password_data_pointer,#or password_data.bytes
nil
)
# password_string=NSMutableData.dataWithBytes(password_data.bytes, length:password_length[0])
password_string=NSMutableData.dataWithBytes(password_data_pointer, length:password_length[0])
p password_string
No matter what I do, no way to retrieve the password.
Please help ; searched for ages, the Internet is full of macruby or cocoa or c examples, but nothing for rubymotion on this topic.
I'm not too familiar with SecKeychainFindGenericPassword but I know that you need to set the proper entitlement to use the Keychain as discussed in the RubyMotion Project Management Guide.
So you make sure you have the following line in your Rakefile:
If you'd like a nicer interface to the Keychain, I use the SSKeychain cocoa wrapper which can be pulled in via Cocoapods.
In your Gemfile:
Also in the Rakefile:
Here's a simplified version of the wrapper I use for storing and retrieving sensitive data with SSKeychain:
Let me know if you have any further questions. Good luck!