-
Notifications
You must be signed in to change notification settings - Fork 105
Add WPA2 Enterprise APIs and example #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
610fb1d
Add WPA2 Enterprise API support
facchinm f7aa896
Add example of connection via WPA2 Enterprise
facchinm 33ff7d3
[fixup] Apply suggestions from code review
facchinm d8ac9ff
WPA2Ent: explicitely set certificates
facchinm 5f89952
Fix WPA2 Enterprise example
facchinm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
examples/WiFiWebClientWPA2Enterprise/WiFiWebClientWPA2Enterprise.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
Web client using WPA2 Enterprise connection | ||
|
||
This sketch connects to a website (http://www.arduino.cc) | ||
using the WiFi module. | ||
|
||
This example is written for a network using WPA2 Enterprise encryption. | ||
|
||
Circuit: | ||
Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) with firmware > 1.2.4 | ||
|
||
created 13 July 2010 | ||
by dlf (Metodo2 srl) | ||
modified 31 May 2012 | ||
by Tom Igoe | ||
modified 14 Aug 2019 | ||
by Martino Facchin | ||
*/ | ||
|
||
|
||
#include <SPI.h> | ||
#include <WiFiNINA.h> | ||
|
||
#include "arduino_secrets.h" | ||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
char ssid[] = SECRET_SSID; // your network SSID (name) | ||
int keyIndex = 0; // your network key Index number (needed only for WEP) | ||
|
||
int status = WL_IDLE_STATUS; | ||
char server[] = "www.arduino.cc"; // name address for Arduino.cc (using DNS) | ||
|
||
// Initialize the WiFi Client | ||
WiFiClient client; | ||
|
||
// WPA2 Enterprise usage: | ||
|
||
// Certificates and credentials are stored in secret tab to avoid sharing them. | ||
// For some networks (like eduroam) your configuration will simply look like | ||
// | ||
// #define SECRET_SSID "eduroam" | ||
// #define SECRET_USERNAME "[email protected]" | ||
// #define SECRET_PASS "yourpassword" | ||
// | ||
// Call WiFi.beginEnterprise(SECRET_SSID, SECRET_USERNAME, SECRET_PASS) and you should easily connect | ||
// | ||
// In case of more complicated networks (that require a certificate, for example) you can use | ||
// WPA2Enterprise functions | ||
// WPA2Enterprise.addCACertificate() , addClientCertificate(), addIdentity() ... | ||
// and then call WiFi.begin() as usual. | ||
|
||
void setup() { | ||
// Initialize serial and wait for port to open: | ||
Serial.begin(9600); | ||
while (!Serial) { | ||
; // Wait for serial port to connect. Needed for native USB port only | ||
} | ||
|
||
// Configure the wifi module to use provided WPA2 Enterprise parameters (if needed) | ||
Serial.println("Configuring WPA2 Enterprise credentials"); | ||
WPA2Enterprise.addCACertificate(ca_pem); | ||
WPA2Enterprise.addClientCertificate(client_crt, client_key); | ||
|
||
// Check for the WiFi module: | ||
if (WiFi.status() == WL_NO_MODULE) { | ||
Serial.println("Communication with WiFi module failed!"); | ||
// Don't continue | ||
while (true); | ||
} | ||
|
||
String fv = WiFi.firmwareVersion(); | ||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) { | ||
Serial.println("Please upgrade the firmware"); | ||
} | ||
|
||
// Attempt to connect to Wifi network: | ||
while (status != WL_CONNECTED) { | ||
Serial.print("Attempting to connect to SSID: "); | ||
Serial.println(ssid); | ||
// Connect to WPA2 enterptise network (shows as an open network). | ||
status = WiFi.beginEnterprise(ssid, SECRET_USERNAME, SECRET_PASSWORD); | ||
|
||
// Wait 1 second for connection: | ||
delay(1000); | ||
} | ||
Serial.println("Connected to wifi"); | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
printWifiStatus(); | ||
|
||
Serial.println("\nStarting connection to server..."); | ||
// If you get a connection, report back via serial: | ||
if (client.connect(server, 80)) { | ||
Serial.println("connected to server"); | ||
// Make a HTTP request: | ||
client.println("GET /asciilogo.txt HTTP/1.1"); | ||
client.println("Host: www.arduino.cc"); | ||
client.println("Connection: close"); | ||
client.println(); | ||
} | ||
} | ||
|
||
void loop() { | ||
// If there are incoming bytes available | ||
// from the server, read them and print them: | ||
while (client.available()) { | ||
char c = client.read(); | ||
Serial.write(c); | ||
} | ||
|
||
// If the server's disconnected, stop the client: | ||
if (!client.connected()) { | ||
Serial.println(); | ||
Serial.println("disconnecting from server."); | ||
client.stop(); | ||
|
||
// Do nothing forevermore: | ||
while (true); | ||
} | ||
} | ||
|
||
|
||
void printWifiStatus() { | ||
// Print the SSID of the network you're attached to: | ||
Serial.print("SSID: "); | ||
Serial.println(WiFi.SSID()); | ||
|
||
// Print your board's IP address: | ||
IPAddress ip = WiFi.localIP(); | ||
Serial.print("IP Address: "); | ||
Serial.println(ip); | ||
|
||
// Print the received signal strength: | ||
long rssi = WiFi.RSSI(); | ||
Serial.print("signal strength (RSSI):"); | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Serial.print(rssi); | ||
Serial.println(" dBm"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#define SECRET_SSID "" | ||
#define SECRET_USERNAME "" | ||
#define SECRET_PASSWORD "" | ||
|
||
// This certificates are completely bogus, but your own should resemble this format | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// For testing, generate them using the bootstrap script in freeradius-server/raddb repository, then | ||
// * remove the password from client key with using this command | ||
// openssl rsa -in client.key -out client2.key # default password is "whatever" | ||
// * slim down client certificate by just keeping the snippet between BEGI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odHRwOi8v\n" | ||
"d3d3LmV4YW1wbGUub3JnL29jc3AwGwYDVR0RBBQwEoEQdXNlckBleGFtcGxlLm9y\n" | ||
"ZzANBgkqhkiG9w0BAQsFAAOCAQEAVC05K4XqjfjoTgQeB7FtjDUiuQedbNi3z3Sy\n" | ||
"2qZVqgaYa+z9cijrL6Z7Z5BvM+JWUxfPjiXXF6M/j1QeyNLKtieDusO/yUaQTmSz\n" | ||
"fyYbdXNlGBzsMLGMgp+xComZ5ZUQQwsmx8phagWqNlzAnQuLyyRshj+hOYjmysXs\n" | ||
"2V6SUfRMEdgr57hRREHZBjJq/PQZL0Kw7BiXMYhMfFJfe1Z4LBYhRqAPDWVoPI1j\n" | ||
"MNXM6X7R5zSNRbrj9biT4WNLBDooDW4Bzz1cimLock/nCY+TTj8Xoy/0szqkIdps\n" | ||
"G1SM9dB7SdXDW6DewvRK28+9xe6HG4xsLtNNYFWqhPkF5S4BIg==\n" | ||
"-----END CERTIFICATE-----"; | ||
|
||
const char * client_key = "-----BEGIN RSA PRIVATE KEY-----\n" | ||
"MIIEpAIBAAKCAQEAtaiggI1w7wez/DjYM+F1RDUMa73J07+XZM1OxQuRt8hbwh8w\n" | ||
"od1Bmu3iFtsSnzssygeek/9+Vd6gXqW5jBa4sMz0CQM1PkIjBsgjPaKk98c2tyDY\n" | ||
"qA+nz0Wi9JOkAKPQwTTDijsAF3QfgcGvWZJngjHkeKoz1BLJehDO4wOu1z3kB8CQ\n" | ||
"GWQ0hZW2Sjt+qFqDTXt8Q0GF+nehqx7juHw/e6QDNiuHXmf0adJWUzFeMnQewUDD\n" | ||
"5R3EBLUiWzKbRFxoi0qs/tM1IUPQ0fASHcJMwZllCZpa3B9nxAhLScR8RjDU0d0F\n" | ||
"+3hQGNKShJyvvR6dM2Qzie8H2yA7QrLdRX8XywIDAQABAoIBABl0MmEw8HUd0DN0\n" | ||
"R58lZUgUYtQp+MDJ5M3EEth7YYSt92WA91CG7y1lTbvEIJzdLs50ON0l/K7Nj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OTYRMd8Zl\n" | ||
"6ctwAQKBgQDe0tEm8EkIIwHm/yYpkGb3NXA/e+SM8o1Qcpl1N3A9yfU+dPxklLXE\n" | ||
"rFfELDn3vi26KPhoE1d7hOr6Goy/63Mryp+4VKNEKspDnqWvECr/oMeANu0qNRtn\n" | ||
"YVD6e1rWtZe007GVQfM+HJD9AFHSRwdAsrLNDDe8l7S984C/2ua5kg==\n" | ||
"-----END RSA PRIVATE KEY-----"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.