Getting error -108 while setting eap username and password through CoreWLAN

Hello Experts,

I am trying to connect Mac Pro through command line utility using Mac OS API. I am successfully able to connect client though when network goes down and comes up again, on GUI dialog is again asking for username and password even though it was connected earlier. So I tried to use helper method CWKeychainSetWiFiEAPUsernameAndPassword but unfortunately it is giving error code -108 Error: 0xFFFFFF94 -108 Failed to allocate memory.

My little code snippet looks as below,

BOOL result = [a associateToEnterpriseNetwork:network.anyObject identity:nil username:onexuser password:onexpass error:&connecterr];
NSLog(@"Association Result: %d", result);
NSLog(@"Error: %@", connecterr);
NSData *nssid = [network.anyObject ssidData];
CWKeychainDomain d = kCWKeychainDomainUser;
OSStatus er = 
CWKeychainSetWiFiEAPUsernameAndPassword(kCWKeychainDomainUser, nssid, onexuser, onexpass); 
NSLog(@"Status: %d", er);

Now I am not sure what could be the cause of error? Any pointers would be appreciated.

Replies

Error -108 is errSecAllocate [1]. CWKeychainSetWiFiEAPUsernameAndPassword is using it as a catch all error when something goes wrong internally. The most likely cause of that is a bogus value for the ssid parameter.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Based on memFullErr, which dates all the way back to the first Macintosh.

  • NSString * onexuser = [[NSString alloc] initWithUTF8String:cOnexuser]; NSString * onexpass = [[NSString alloc] initWithUTF8String:cOnexpass]; NSData * nssid = [@"Testing" dataUsingEncoding:NSUTF8StringEncoding]; NSLog(@"NSSData: %@", nssid); CWKeychainDomain d = kCWKeychainDomainUser; OSStatus err; err = CWKeychainSetWiFiEAPUsernameAndPassword(d, nssid, onexuser, onexpass); NSLog(@"Status: %d", err); }```
Add a Comment

I am getting same error with very simple below code as well, Also I analysed that hex value of NSLog is having same value. Is there any logs I can refer to further debug this ?

void SetUsernamePassword(char * cOnexuser, char * cOnexpass) {
    NSString * onexuser = [[NSString alloc] initWithUTF8String:cOnexuser];
    NSString * onexpass = [[NSString alloc] initWithUTF8String:cOnexpass];
    NSData * nssid = [@"Testing" dataUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"NSSData: %@", nssid);
    CWKeychainDomain d = kCWKeychainDomainUser;
    OSStatus err;
    err = CWKeychainSetWiFiEAPUsernameAndPassword(d, nssid, onexuser, onexpass);
    NSLog(@"Status: %d", err);
}

I put the following code into a small test project and:

  • It printed 0, indicating success.

  • The Gumbo keychain item showed up in Keychain Access.

@import Foundation;
@import CoreWLAN;

int main(int argc, char **argv) {
    #pragma unused(argc)
    #pragma unused(argv)

    OSStatus err = CWKeychainSetWiFiEAPUsernameAndPassword(
        kCWKeychainDomainUser,
        [@"Gumbo" dataUsingEncoding:NSUTF8StringEncoding],
        @"mrgumby",
        @"opendoor"
    );
    NSLog(@"%d", (int) err);
    return EXIT_SUCCESS;
}

I built this with Xcode 14.3 and tested it on macOS 13.4.1.

Please repeat this test in your environment to confirm that it works. After that you can tweak the arguments to more closely match your real example to see what’s triggering the issue.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

You are perfectly right, even on my Xcode 14.2 above code is building perfectly and working as expected. Key shows up into keychain.

I remembered your earlier answer to my one of post that there is difference between permission when we execute CLI over SSH vs VNC and using Terminal. And that is where my issue was lying.

Thanks a lot for quick help.

  • Ah, SSH, that old chestnut. Thanks for closing the loop here!

Add a Comment