connect enterprise wifi with GTC authentication

sefiroths76
Posts: 2
Joined: Wed Sep 25, 2024 1:32 pm

connect enterprise wifi with GTC authentication

Postby sefiroths76 » Wed Sep 25, 2024 1:38 pm

the code is the code of the example. the problem is the phase2 auth that the server says that is trying to use MSCHAP, but I have a GTC...
there is a way to do it? (I don't need to validate certificate)
thanks

Code: Select all

#include <WiFi.h>                      //Wifi library
#define EAP_IDENTITY "blabla"           //if connecting from another corporation, use identity@organization.domain in Eduroam
#define EAP_USERNAME "blabla"           //oftentimes just a repeat of the identity
#define EAP_PASSWORD "mypass"        //your Eduroam password
const char *ssid = "myssid";          // Eduroam SSID
const char *host = "google.it";  //external server domain for HTTP connection after authentication
int counter = 0;

// NOTE: For some systems, various certification keys are required to connect to the wifi system.
//       Usually you are provided these by the IT department of your organization when certs are required
//       and you can't connect with just an identity and password.
//       Most eduroam setups we have seen do not require this level of authentication, but you should contact
//       your IT department to verify.
//       You should uncomment these and populate with the contents of the files if this is required for your scenario (See Example 2 and Example 3 below).
//const char *ca_pem = "insert your CA cert from your .pem file here";
//const char *client_cert = "insert your client cert from your .crt file here";
//const char *client_key = "insert your client key from your .key file here";

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.print("Connecting to network: ");
  Serial.println(ssid);
  WiFi.disconnect(true);  //disconnect form wifi to set new wifi connection
  WiFi.mode(WIFI_STA);    //init wifi mode

  // Example1 (most common): a cert-file-free eduroam with PEAP (or TTLS)
  WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_IDENTITY, EAP_USERNAME, EAP_PASSWORD);

  // Example 2: a cert-file WPA2 Enterprise with PEAP
  //WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_IDENTITY, EAP_USERNAME, EAP_PASSWORD, ca_pem, client_cert, client_key);

  // Example 3: TLS with cert-files and no password
  //WiFi.begin(ssid, WPA2_AUTH_TLS, EAP_IDENTITY, NULL, NULL, ca_pem, client_cert, client_key);

  while (WiFi.status() != WL_CONNECTED) {
    wl_status_t status = WiFi.status();
        Serial.print(status);
    delay(500);
    Serial.print(".");
    counter++;
    if (counter >= 60) {  //after 30 seconds timeout - reset board
      ESP.restart();
    }
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address set: ");
  Serial.println(WiFi.localIP());  //print LAN IP
}
void loop() {
  if (WiFi.status() == WL_CONNECTED) {  //if we are connected to Eduroam network
    counter = 0;                        //reset counter
    Serial.println("Wifi is still connected with IP: ");
    Serial.println(WiFi.localIP());            //inform user about his IP address
  } else if (WiFi.status() != WL_CONNECTED) {  //if we lost connection, retry
    WiFi.begin(ssid);
  }
  while (WiFi.status() != WL_CONNECTED) {  //during lost connection, print dots
    delay(2500);
    Serial.print(".");
    counter++;
    if (counter >= 60) {  //30 seconds timeout - reset board
      ESP.restart();
    }
  }
  Serial.print("Connecting to website: ");
  Serial.println(host);
  NetworkClient client;
  if (client.connect(host, 80)) {
    String url = "/rele/rele1.txt";
    client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: ESP32\r\n" + "Connection: close\r\n\r\n");

    while (client.connected()) {
      String line = client.readStringUntil('\n');
      if (line == "\r") {
        break;
      }
    }
    String line = client.readStringUntil('\n');
    Serial.println(line);
  } else {
    Serial.println("Connection unsuccessful");
  }
}


sefiroths76
Posts: 2
Joined: Wed Sep 25, 2024 1:32 pm

Re: connect enterprise wifi with GTC authentication

Postby sefiroths76 » Fri Sep 27, 2024 8:06 am

I have tried another way but give compile error perhaps the problem is old lib?
/Users/noidue/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-
downloaded esp-idf-v5.2.3.zip and try istalling with arduino ide but says invalid lib

Code: Select all

#include <WiFi.h>
#include "esp_wpa2.h"  // Include esp_wpa2.h per WPA2 Enterprise

// Credenziali della rete WPA2 Enterprise
const char* ssid = "myssid";  // Nome SSID della rete aziendale o Eduroam
const char* identity = "myid";  // Identità (username)
const char* username = "myid";  // Username
const char* password = "mypass";  // Password

void setup() {
  Serial.begin(115200);
  delay(1000);
  
  WiFi.disconnect(true);  // Disconnette da eventuali connessioni precedenti
  WiFi.mode(WIFI_STA);    // Imposta il Wi-Fi in modalità client (station)

  // Configura WPA2 Enterprise con PEAP (EAP-PEAP)
  esp_eth_config_t config = WPA2_CONFIG_INIT_DEFAULT();  // Inizializza configurazione WPA2 Enterprise
  esp_wifi_sta_wpa2_ent_enable(&config);  // Abilita WPA2 Enterprise
  
  // Imposta identità e password
  esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)identity, strlen(identity));  // Imposta l'identità
  esp_wifi_sta_wpa2_ent_set_username((uint8_t *)username, strlen(username));  // Imposta l'username
  esp_wifi_sta_wpa2_ent_set_password((uint8_t *)password, strlen(password));  // Imposta la password

  // **Opzione Fase 2 con GTC**
  // Se vuoi usare GTC al posto di MSCHAPv2, abilita la riga seguente
  esp_wifi_sta_wpa2_ent_set_phase2_method(ESP_EAP_PHASE2_METHOD_GTC);  // Fase 2: GTC
  
  WiFi.begin(ssid);  // Avvia la connessione alla rete

  Serial.println("Connessione alla rete Wi-Fi con WPA2 Enterprise...");
  
  // Attendere fino a quando il dispositivo non è connesso alla rete
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("Connesso alla rete Wi-Fi!");
  Serial.print("Indirizzo IP: ");
  Serial.println(WiFi.localIP());  // Stampa l'indirizzo IP ottenuto
}

void loop() {
  // Il tuo codice principale va qui
}

In file included from /Users/noidue/Documents/Arduino/sketch_gtc/sketch_gtc.ino:2:
/Users/noidue/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-33fbade6/esp32/include/wpa_supplicant/esp_supplicant/include/esp_wpa2.h:10:74: note: '#pragma message: esp_wpa2.h is deprecated. Use esp_eap_client.h instead.'
10 | #pragma message("esp_wpa2.h is deprecated. Use esp_eap_client.h instead.")
| ^
/Users/noidue/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-33fbade6/esp32/include/wpa_supplicant/esp_supplicant/include/esp_wpa2.h:327:1: error: expected declaration before '}' token
327 | }
| ^
/Users/noidue/Documents/Arduino/sketch_gtc/sketch_gtc.ino: In function 'void setup()':
/Users/noidue/Documents/Arduino/sketch_gtc/sketch_gtc.ino:18:29: error: 'WPA2_CONFIG_INIT_DEFAULT' was not declared in this scope
18 | esp_eth_config_t config = WPA2_CONFIG_INIT_DEFAULT(); // Inizializza configurazione WPA2 Enterprise
| ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/noidue/Documents/Arduino/sketch_gtc/sketch_gtc.ino:19:31: error: too many arguments to function 'esp_err_t esp_wifi_sta_wpa2_ent_enable()'
19 | esp_wifi_sta_wpa2_ent_enable(&config); // Abilita WPA2 Enterprise
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/Users/noidue/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-33fbade6/esp32/include/wpa_supplicant/esp_supplicant/include/esp_wpa2.h:28:11: note: declared here
28 | esp_err_t esp_wifi_sta_wpa2_ent_enable(void);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/noidue/Documents/Arduino/sketch_gtc/sketch_gtc.ino:28:43: error: 'ESP_EAP_PHASE2_METHOD_GTC' was not declared in this scope
28 | esp_wifi_sta_wpa2_ent_set_phase2_method(ESP_EAP_PHASE2_METHOD_GTC); // Fase 2: GTC
| ^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/noidue/Documents/Arduino/sketch_gtc/sketch_gtc.ino:28:3: error: 'esp_wifi_sta_wpa2_ent_set_phase2_method' was not declared in this scope; did you mean 'esp_wifi_sta_wpa2_ent_set_ttls_phase2_method'?
28 | esp_wifi_sta_wpa2_ent_set_phase2_method(ESP_EAP_PHASE2_METHOD_GTC); // Fase 2: GTC
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| esp_wifi_sta_wpa2_ent_set_ttls_phase2_method

exit status 1

Compilation error: 'WPA2_CONFIG_INIT_DEFAULT' was not declared in this scope

Who is online

Users browsing this forum: stdenits and 322 guests