[MacRuby-devel] retrieving password from keychain

Laurent Sansonetti lsansonetti at apple.com
Mon Apr 20 13:44:17 PDT 2009


Hi Karl,

On Apr 19, 2009, at 8:17 PM, Karl Varga wrote:

> Hi there,
>
> I am having a strange problem that other people don't seem to be
> having because I can't find any references to in google searches.  I
> am using MacRuby 0.4 installed from the binary available on the
> macruby binary releases page (MacRuby version 0.4 (ruby 1.9.1)
> [universal-darwin9.5, x86_64])
>
> I have an application which stores username/passwords in the keychain.
> I can add items to the keychain (so I can call
> SecKeychainAddGenericPassword() fine and therefore I think my setup
> must be OK), but I cannot retrieve them.  When I call:
>
>    status, *data = SecKeychainFindGenericPassword(
>        nil, service.length, service, username.length, username)
>
> I get an error:
>
> Configuration.app/Contents/Resources/Controller.rb:99:in
> `SecKeychainFindGenericPassword': wrong number of arguments (5 for 8)
> (ArgumentError)
>
> The method signature is this:
>
> OSStatus SecKeychainFindGenericPassword (
>   CFTypeRef keychainOrArray,
>   UInt32 serviceNameLength,
>   const char *serviceName,
>   UInt32 accountNameLength,
>   const char *accountName,
>   UInt32 *passwordLength,
>   void **passwordData,
>   SecKeychainItemRef *itemRef
> );
>
>
> All the examples I've read suggest that this method in macruby should
> only take 5 args and return the status, password length, password
> string and item reference (the last 3 extracted from *data) instead of
> passing in pointers (which I don't know how to do BTW).
>
> What gives?  Anyone have any idea or had the same problem?

I am surprised you were able to call SecKeychainFindGenericPassword()  
from MacRuby, did you generate a BridgeSupport file for the Security  
framework?

As for your question, MacRuby currently doesn't support the RubyCocoa  
way of dealing with returned-by-reference arguments (which is what  
you're trying to do I think), so you must allocate Pointer objects  
instead. In the case of this call it may be painful, so I would  
recommend to wrap this in an Objective-C class in the interim and use  
that class from MacRuby.

HTH,
Laurent


More information about the MacRuby-devel mailing list