Root CA of webserver has changed, minor changes (#3447)
This commit is contained in:
parent
7d2632c024
commit
547c2d3346
@ -1,40 +1,51 @@
|
|||||||
/*|----------------------------------------------------------|*/
|
/*|-----------------------------------------------------------|*/
|
||||||
/*|WORKING EXAMPLE FOR HTTPS CONNECTION |*/
|
/*|WORKING EXAMPLE FOR HTTPS CONNECTION |*/
|
||||||
/*|TESTED BOARDS: Devkit v1 DOIT, Devkitc v4 |*/
|
/*|Author: Bc. Martin Chlebovec |*/
|
||||||
/*|CORE: June 2018 |*/
|
/*|Technical University of Košice |*/
|
||||||
/*|----------------------------------------------------------|*/
|
/*|TESTED BOARDS: Devkit v1 DOIT, Devkitc v4 |*/
|
||||||
|
/*|CORE: 0.9x, 1.0.0, 1.0.1 tested, working (newer not tested)|*/
|
||||||
|
/*|Supported methods: PEAP + MsCHAPv2, EAP-TTLS + MsCHAPv2 |*/
|
||||||
|
/*|-----------------------------------------------------------|*/
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <WiFiClientSecure.h>
|
#include <WiFiClientSecure.h>
|
||||||
#include "esp_wpa2.h"
|
#include "esp_wpa2.h"
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#define EAP_IDENTITY "identity" //if connecting from another corporation, use identity@organisation.domain in Eduroam
|
#define EAP_ANONYMOUS_IDENTITY "anonymous@example.com" //anonymous identity
|
||||||
#define EAP_PASSWORD "password" //your Eduroam password
|
#define EAP_IDENTITY "id@example.com" //user identity
|
||||||
const char* ssid = "eduroam"; // Eduroam SSID
|
#define EAP_PASSWORD "password" //eduroam user password
|
||||||
const char* host = "arduino.php5.sk"; //external server domain for HTTP connection after authentification
|
const char* ssid = "eduroam"; // eduroam SSID
|
||||||
|
const char* host = "arduino.php5.sk"; //external server domain for HTTPS connection
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
const char* test_root_ca= \
|
const char* test_root_ca = \
|
||||||
"-----BEGIN CERTIFICATE-----\n" \
|
"-----BEGIN C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O0329/CWq2kry\n" \
|
||||||
|
"qv66OSMjwulUz0dXf4OHQasR7CNfIr+4KScc6ABlQ5RDF86PGeE6kdwSQkFiB/cQ\n" \
|
||||||
|
"ysNyq0jEDQTkfa2pjmuWtMCNbBnhFXBYejfubIhaUbEv2FOQB3dCav+FPg5eEveX\n" \
|
||||||
|
"TVyMnGo=\n" \
|
||||||
|
"-----END CERTIFICATE-----\n";
|
||||||
// You can use x.509 client certificates if you want
|
// You can use x.509 client certificates if you want
|
||||||
//const char* test_client_key = ""; //to verify the client
|
//const char* test_client_key = ""; //to verify the client
|
||||||
//const char* test_client_cert = ""; //to verify the client
|
//const char* test_client_cert = ""; //to verify the client
|
||||||
@ -47,42 +58,42 @@ void setup() {
|
|||||||
Serial.println(ssid);
|
Serial.println(ssid);
|
||||||
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
|
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
|
||||||
WiFi.mode(WIFI_STA); //init wifi mode
|
WiFi.mode(WIFI_STA); //init wifi mode
|
||||||
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity
|
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity
|
||||||
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same
|
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username
|
||||||
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
|
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
|
||||||
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config settings to default
|
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
|
||||||
esp_wifi_sta_wpa2_ent_enable(&config); //set config settings to enable function
|
esp_wifi_sta_wpa2_ent_enable(&config);
|
||||||
WiFi.begin(ssid); //connect to wifi
|
WiFi.begin(ssid); //connect to wifi
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
counter++;
|
counter++;
|
||||||
if(counter>=60){ //after 30 seconds timeout - reset board
|
if (counter >= 60) { //after 30 seconds timeout - reset board (on unsucessful connection)
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.setCACert(test_root_ca);
|
client.setCACert(test_root_ca);
|
||||||
//client.setCertificate(test_client_key); // for client verification
|
//client.setCertificate(test_client_key); // for client verification - certificate
|
||||||
//client.setPrivateKey(test_client_cert); // for client verification
|
//client.setPrivateKey(test_client_cert); // for client verification - private key
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println("WiFi connected");
|
Serial.println("WiFi connected");
|
||||||
Serial.println("IP address set: ");
|
Serial.println("IP address set: ");
|
||||||
Serial.println(WiFi.localIP()); //print LAN IP
|
Serial.println(WiFi.localIP()); //print LAN IP
|
||||||
}
|
}
|
||||||
void loop() {
|
void loop() {
|
||||||
if (WiFi.status() == WL_CONNECTED) { //if we are connected to Eduroam network
|
if (WiFi.status() == WL_CONNECTED) { //if we are connected to eduroam network
|
||||||
counter = 0; //reset counter
|
counter = 0; //reset counter
|
||||||
Serial.println("Wifi is still connected with IP: ");
|
Serial.println("Wifi is still connected with IP: ");
|
||||||
Serial.println(WiFi.localIP()); //inform user about his IP address
|
Serial.println(WiFi.localIP()); //inform user about his IP address
|
||||||
}else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry
|
} else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry
|
||||||
WiFi.begin(ssid);
|
WiFi.begin(ssid);
|
||||||
}
|
}
|
||||||
while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots
|
while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
counter++;
|
counter++;
|
||||||
if(counter>=60){ //30 seconds timeout - reset board
|
if (counter >= 60) { //30 seconds timeout - reset board
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.print("Connecting to website: ");
|
Serial.print("Connecting to website: ");
|
||||||
@ -98,9 +109,9 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String line = client.readStringUntil('\n');
|
String line = client.readStringUntil('\n');
|
||||||
Serial.println(line);
|
Serial.println(line);
|
||||||
}else{
|
} else {
|
||||||
Serial.println("Connection unsucessful");
|
Serial.println("Connection unsucessful");
|
||||||
}
|
}
|
||||||
delay(5000);
|
delay(5000);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user