user1482953
user1482953

Reputation: 181

How to resolve an "Invalid EAP settings - NEHotstConfiguration error" when programmatically connecting to a WPA2 WiFi network

I know that, to connect to a WiFi network manually, I can do these steps:

  1. From Settings in iPhone device 
  2. Used these three parameters: SSID, Username, password
  3. After that it asks to trust the certificate and, after trusting the certificate, the WiFi network gets connected

I am trying to connect programmatically to a WPA2-secured enterprise WiFi network using an iPhone app. Here is my code for this:

NEHotspotEAPSettings *settings = [[NEHotspotEAPSettings alloc]init];
settings.password = self.password.text;
settings.username = self.username.text;
settings.supportedEAPTypes = [NSArray arrayWithObjects:[NSNumber numberWithInteger:NEHotspotConfigurationEAPTypeEAPPEAP], nil];
NEHotspotConfiguration *configuration = [[NEHotspotConfiguration alloc]initWithSSID:self.ssid.text eapSettings:settings];
[[NEHotspotConfigurationManager sharedManager]applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) {
if (error) { 
NSLog(@"Error: %@",error.localizedDescription);
} else {
NSLog(@“Connected”);
}
}];

but it gives me an error:

Invalid EAP settings: NEHotspotConfiguration EAP settings must have either trusted server certificates or trusted server names configured

Since I don’t have any trusted server certificate or trusted server name, what should I set in the below property of NEHotspotEAPSettings (passing nil also gives me same error)?

settings.trustedServerNames 

In my Android app, my code is working fine without any certificate; this is specific to iOS.

Upvotes: 0

Views: 1717

Answers (1)

battlmonstr
battlmonstr

Reputation: 6300

When connecting manually on step 3 (when it asks to trust the certificate) open "more details" and try to find out the "common name" of the certificate. It will usually look like your company domain name, for example "wifi.example.com".

Then initialize NEHotspotEAPSettings with it:

settings.trustedServerNames = @[ "wifi.example.com" ];

If that certificate is not using a well-known trust root installed on iOS, it might not validate it, then you might have to use setTrustedServerCertificates method instead (see docs - https://developer.apple.com/documentation/networkextension/nehotspoteapsettings/2875740-settrustedservercertificates?language=objc )

Upvotes: 1

Related Questions