NEHotspotHelper does not receive Authenification / Evaulate NetworkExtension commands

I have included NEHotspotHelper in my application that manages a hidden network, but I have a lot of problems. I do not receive an authentication command (kNEHotspotHelperCommandTypeAuthenticate) after my network, established with a high level of trust, is in an evaluation state. In addition, my WISPr network never receives the Evaluate command (kNEHotspotHelperCommandTypeEvaluate) when the SSID is selected in the Wi-Fi list in the settings. My goal for WISPr Hotspot is to send a UINotification that requires user action. Does anyone know what I am missing if I have not received kNEHotspotHelperCommandTypeAuthenticate and kNEHotspotHelperCommandTypeEvaluate in two situations?

I installed HotspotHelper registerWithOptions in my application as such:

 NSMutableDictionary* options = [[NSMutableDictionary alloc] init];  
  [options setObject:@"Hotspot" forKey:kNEHotspotHelperOptionDisplayName];/  

  dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", 0);  
  BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {  
  NEHotspotNetwork* network;  
  NSLog(@"COMMAND TYPE:   %ld", (long)cmd.commandType);

     if (cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType ==kNEHotspotHelperCommandTypeFilterScanList) {  
       for (network  in cmd.networkList) {  

            NSLog(@"COMMAND TYPE After:   %ld", (long)cmd.commandType);

            if ([network.SSID isEqualToString:@"test-WPA-2"]|| [network.SSID isEqualToString:@"WISPr Hotspot"]) {  

              double signalStrength = network.signalStrength;  
              NSLog(@"Signal Strength: %f", signalStrength);  

              [network setConfidence:kNEHotspotHelperConfidenceHigh];  
              [network setPassword:@"myPassword"];  

              NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];  
              NSLog(@"Response CMD %@", response);  

              [response setNetworkList:@[network]];  
              [response setNetwork:network];  
              [response deliver];  
          }    
     }       
}  

}];  
+4
source share
1 answer

The first mistake I made in the above code: I was expecting the type of the Evaluate command to list through a list of networks. However, the Evaluate team actually wants to deliver the connected network. I get the current network with the following code:

                NSArray *array = [NEHotspotHelper supportedNetworkInterfaces];

                NEHotspotNetwork *connectedNetwork = [array lastObject];

                NSLog(@"supported Network Interface: %@", connectedNetwork);

Then check if the connected list matches my SSID, so I set the trust level of this network and brought the response to Evaluate:

                        [connectedNetwork setConfidence:kNEHotspotHelperConfidenceLow];

                        //[response setNetworkList:@[network]];
                        [response setNetwork:connectedNetwork];

                        [response deliver];

The next command that the handler is given to is Authenticate. My complete code is as follows: I am still working on processing commands after authentication. Full line of code:

              BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {

              NEHotspotNetwork* network;

              if (cmd.commandType ==kNEHotspotHelperCommandTypeFilterScanList) {

                for (network in cmd.networkList) {

                    //need to check against list of directories

                        if ([network.SSID isEqualToString:@"test-WPA-2"]) {

                            NSLog(@"%@", network.SSID);
                            NSLog(@"SSID is in Directory: %@", network.SSID);

                            double signalStrength = network.signalStrength;
                            NSLog(@"Signal Strength: %f", signalStrength);

                            [network setConfidence:kNEHotspotHelperConfidenceLow];
                            [network setPassword:@"password"];


                            NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
                            NSLog(@"Response CMD %@", response);

                            [response setNetworkList:@[network]];
                            [response setNetwork:network];
                            [response deliver];

                            }
                    }
            }
            if (cmd.commandType == kNEHotspotHelperCommandTypeEvaluate) {

                /* *   When a network is joined initially, the state machine enters
                 *   the Evaluating state. In that state, each HotspotHelper receives a
                 *   command of type Evaluate. If one or more helpers indicates that it
                 *   is able to handle the network, the one with the highest confidence
                 *   level is chosen before entering the Authenticating state. As an
                 *   optimization, the first helper to assert a high confidence wins and
                 *   the state machine ignores the other helpers.
                 *
                 *   If no helpers claim the network, the state machine enters the
                 *   Authenticated state.
                 */

                NSArray *array = [NEHotspotHelper supportedNetworkInterfaces];

                NEHotspotNetwork *connectedNetwork = [array lastObject];

                NSLog(@"supported Network Interface: %@", connectedNetwork);

                NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];

                NSLog(@"Response CMD %@", response);

                [connectedNetwork setConfidence:kNEHotspotHelperConfidenceLow];

                //[response setNetworkList:@[network]];
                [response setNetwork:connectedNetwork];

                [response deliver];


           }

           if (cmd.commandType == kNEHotspotHelperCommandTypeAuthenticate) {

            NSLog(@"COMMAND TYPE In Auth ***********:   %ld \n\n\n\n\n\n", (long)cmd.commandType);

            /*
            *   In the Authenticating state, the chosen helper is given a command of type
            *   Authenticate. The helper is expected to perform whatever network
            *   processing is required to make the network available for general
                *   network traffic. If the authentication is successful, the helper
                *   indicates that with a Success result. The state machine enters the
                *   Authenticated state.
                *
                *   On a network that has been authenticated by a helper, the state machine
                *   enters the Maintaining state when the network is joined again, and also
                *   periodically while the system remains associated with the network. In the
                    *   Maintaining state, the helper is expected to perform whatever network
                    *   operations are required to determine if the network is still able to
                        *   carry general network traffic. If that is the case, the helper returns
                        *   Success. If not, and authentication is again required, it returns
                        *   AuthenticationRequired to cause the state machine to re-enter the
                        *   Authenticating state.
                        *
                        *   In the Authenticating state, if the helper determines that it requires
                            *   user interaction to proceed, the helper first arranges to alert
                            *   the user via a UserLocalNotification, then returns a result of
                            *   UIRequired. The state machine enters the PresentingUI state.*/

        }
        if (cmd.commandType == kNEHotspotHelperCommandTypePresentUI) {

            NSLog(@"COMMAND TYPE In Present UI ***********:   %ld \n\n\n\n\n\n", (long)cmd.commandType);

        }

    }]; 
+3
source

Source: https://habr.com/ru/post/1610462/


All Articles