-
Notifications
You must be signed in to change notification settings - Fork 108
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
Changes from 2 commits
610fb1d
f7aa896
33ff7d3
d8ac9ff
5f89952
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
|
||
/* | ||
Web client | ||
|
||
This sketch connects to a website (http://www.google.com) | ||
using the WiFi module. | ||
|
||
This example is written for a network using WPA encryption. For | ||
WEP or WPA, change the Wifi.begin() call accordingly. | ||
|
||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This example is written for a network using WPA encryption. For | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
WEP or WPA, change the Wifi.begin() call accordingly. | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Circuit: | ||
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) | ||
|
||
created 13 July 2010 | ||
by dlf (Metodo2 srl) | ||
modified 31 May 2012 | ||
by Tom Igoe | ||
*/ | ||
|
||
|
||
#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) | ||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) | ||
int keyIndex = 0; // your network key Index number (needed only for WEP) | ||
|
||
int status = WL_IDLE_STATUS; | ||
// if you don't want to use DNS (and reduce your sketch size) | ||
// use the numeric IP instead of the name for the server: | ||
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) | ||
char server[] = "www.google.com"; // name address for Google (using DNS) | ||
|
||
// Initialize the Ethernet client library | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the best text would be, but certainly this comment and the two following lines are wrong. Perhaps:
|
||
// with the IP address and port of the server | ||
// that you want to connect to (port 80 is default for HTTP): | ||
WiFiClient client; | ||
|
||
// Initialize the WPA2 Enterprise object | ||
// Just fill the fields you need | ||
// eg. if you are given only an identity and a certificate, initialize it as | ||
// WPA2Enterprise data("myidentity", ca_pem); | ||
// Certificates are stored in secret tab to avoid sharing them. | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
WPA2Enterprise data(EAP_TLS, "myidentity", "username", "password", ca_pem, client_crt, client_key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tigoe do you have any suggestions on the API for WPA2 enterprise support? The way the underlying SDK on the NINA module works is it will accept all the configs (identity, username, password, CA, cert, key), then figure out what to use. @facchinm has made a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd make the default interface simple, like the macos login: begin(ssid, userid, password). Use defaults for the other properties. Then I'd add functions to set the rest of the properties. Here's a typical wpa_supplicant record from linux:
So if you want to be thorough: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Tom, I'm setting up a test network to test how the ESP firmware performs in the various cases. My concert in that, if username (identity) + password is not covering the 99% of use cases, you'll need to add other information anyway, making the whole process split into 2 (or N) places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. I would add the settings for eduroam in the examples then, since it's likely to be a popular use of this feature. Worth putting some notes in the documentation on how to find out these details as well, might want to pass that along to Simone. |
||
|
||
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 | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
WiFi.config(data); | ||
|
||
// 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: | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while (status != WL_CONNECTED) { | ||
Serial.print("Attempting to connect to SSID: "); | ||
Serial.println(ssid); | ||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network: | ||
status = WiFi.begin(ssid, pass); | ||
|
||
// wait 10 seconds for connection: | ||
delay(10000); | ||
} | ||
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 /search?q=arduino HTTP/1.1"); | ||
client.println("Host: www.google.com"); | ||
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"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#define SECRET_SSID "" | ||
#define SECRET_PASS "" | ||
|
||
// This certificates are completely bogus, but your own should resemble this format | ||
facchinm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const char * ca_pem = "-----BEGIN CERTIFICATE-----\n" | ||
"MIID3DCCA0WgAwIBAgIJANe5ZSCKoB8fMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD\n" | ||
"VQQGEwJGUjEPMA0GA1UECAwGUmFkaXVzMRIwEAYDVQQHDAlTb21ld2hlcmUxFTAT\n" | ||
"BgNVBAoMDEV4YW1wbGUgSW5jLjEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBs\n" | ||
"ZS5jb20xJjAkBgNVBAMMHUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MB4X\n" | ||
"DTE2MTEyMzAyNTUwN1oXDTE3MDEyMjAyNTUwN1owgZMxCzAJBgNVBAYTAkZSMQ8w\n" | ||
"DQYDVQQIDAZSYWRpdXMxEjAQBgNVBAcMCVNvbWV3aGVyZTEVMBMGA1UECgwMRXhh\n" | ||
"bXBsZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQG\n" | ||
"A1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwgZ8wDQYJKoZIhvcN\n" | ||
"AQEBBQADgY0AMIGJAoGBAL03y7N2GvNDO9BN8fVtdNonp0bMiqpj1D0He5+OTM+9\n" | ||
"3ZTIsJCNrbzhLQrRI3vMW7UDy8U7GeWORN9W4dWYlYiy/NFRp3hNMrbePhVmNIOV\n" | ||
"ww4ovGzbD+Xo31gPVkhzQ8I5/jbOIQBmgKMAMZyOMlG9VD6yMmAeYqnZYz68WHKt\n" | ||
"AgMBAAGjggE0MIIBMDAdBgNVHQ4EFgQUf1MLQIzAEZcRsgZlS8sosfmVI+UwgcgG\n" | ||
"A1UdIwSBwDCBvYAUf1MLQIzAEZcRsgZlS8sosfmVI+WhgZmkgZYwgZMxCzAJBgNV\n" | ||
"BAYTAkZSMQ8wDQYDVQQIDAZSYWRpdXMxEjAQBgNVBAcMCVNvbWV3aGVyZTEVMBMG\n" | ||
"A1UECgwMRXhhbXBsZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxl\n" | ||
"LmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHmCCQDX\n" | ||
"uWUgiqAfHzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6ApoCeGJWh0dHA6Ly93\n" | ||
"d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZIhvcNAQELBQADgYEA\n" | ||
"GepHc7TE/P+5t/cZPn5TTQkWQ/4/1lgQd82lF36RYWSIW3BdAc0zwYWYZaWixxyp\n" | ||
"s0YOqwz6PZAGRV+SlYO2f8Kf+C3aZs4YHB0GsmksmFOb8r9d7xcDuOKHoA+QV0Zw\n" | ||
"RaK6pttsBAxy7rw3kX/CgTp0Y2puaLdMXv/v9FisCP8=\n" | ||
"-----END CERTIFICATE-----"; | ||
|
||
const char * client_crt = "Certificate:\n" | ||
" Data:\n" | ||
" Version: 3 (0x2)\n" | ||
" Serial Number: 44 (0x2c)\n" | ||
" Signature Algorithm: sha1WithRSAEncryption\n" | ||
" Issuer: C=FR, ST=Radius, L=Somewhere, O=Example Inc./[email protected], CN=Example Certificate Authority\n" | ||
" Validity\n" | ||
" Not Before: Nov 23 02:55:07 2016 GMT\n" | ||
" Not After : Jan 22 02:55:07 2017 GMT\n" | ||
" Subject: C=FR, ST=Radius, O=Example Inc., [email protected]/[email protected]\n" | ||
" Subject Public Key Info:\n" | ||
" Public Key Algorithm: rsaEncryption\n" | ||
" Public-Key: (2048 bit)\n" | ||
" Modulus:\n" | ||
" 00:ac:41:d4:a2:46:0c:dc:67:1d:7b:89:36:7c:15:\n" | ||
" be:a2:c1:fe:4c:f2:fa:af:5d:76:0e:ee:b5:ca:d4:\n" | ||
" d3:01:c8:6b:30:50:df:2d:57:17:f4:43:47:97:ca:\n" | ||
" f1:8d:f7:c0:9d:56:b3:e7:17:7c:58:59:de:f3:be:\n" | ||
" b5:08:5d:f8:3a:ad:83:44:0d:31:c9:f1:3d:f1:9a:\n" | ||
" cf:84:0c:ad:d3:be:5c:bd:3d:58:b5:1d:2c:fe:70:\n" | ||
" 8d:c5:b0:17:87:d4:8e:85:f7:51:4c:0f:d1:e0:8c:\n" | ||
" 7b:a0:25:ab:91:7c:7f:eb:47:73:c9:4b:6c:8b:e6:\n" | ||
" c1:06:d5:94:30:63:ec:45:1a:f5:7f:46:2f:b3:84:\n" | ||
" 78:5d:1c:37:1a:fa:57:ea:45:5e:45:40:ab:14:c7:\n" | ||
" 81:b0:26:3d:7e:cf:da:db:f0:f1:40:a7:a1:4b:54:\n" | ||
" f3:96:1b:c9:30:3c:3c:d8:19:ba:c7:df:b1:ad:a2:\n" | ||
" d6:17:0a:d6:ed:31:b5:cb:12:39:f5:6e:92:6b:85:\n" | ||
" f2:9e:c7:06:6b:bb:89:ed:a7:5f:ec:56:12:46:fd:\n" | ||
" 3a:74:d1:d2:31:30:1d:58:19:25:33:ff:11:ea:3a:\n" | ||
" 52:33:b1:fb:d3:75:8d:1f:5e:36:a5:35:e0:11:5a:\n" | ||
" 4a:2d:97:58:2c:3d:62:3c:32:af:83:69:a9:1a:32:\n" | ||
" 1b:b7\n" | ||
" Exponent: 65537 (0x10001)\n" | ||
" X509v3 extensions:\n" | ||
" X509v3 Extended Key Usage: \n" | ||
" TLS Web Client Authentication\n" | ||
" X509v3 CRL Distribution Points: \n" | ||
"\n" | ||
" Full Name:\n" | ||
" URI:http://www.example.com/example_ca.crl\n" | ||
"\n" | ||
" Signature Algorithm: sha1WithRSAEncryption\n" | ||
" 8b:8d:b6:19:ce:6f:6b:9e:1d:03:8b:6b:10:fc:99:d0:7a:2f:\n" | ||
" e0:37:ce:b8:a4:e4:b9:a1:c2:36:ff:76:b2:ad:d7:d0:df:d1:\n" | ||
" 03:27:93:a7:4e:1e:bf:ed:d2:b7:65:2a:c9:c3:ab:20:aa:e3:\n" | ||
" 10:4c:75:3b:c4:02:ab:34:08:6e:61:91:cf:e3:02:35:6a:e5:\n" | ||
" f3:25:96:51:92:82:6e:52:81:c1:f1:7b:68:02:b0:ce:f4:ba:\n" | ||
" fd:6e:68:35:b3:7e:77:cb:a0:1e:11:5e:58:bf:f3:2a:ed:b3:\n" | ||
" 4c:82:21:5e:1b:47:b6:2f:f3:f5:c9:1b:6a:70:44:6d:ff:ad:\n" | ||
" a6:e3\n" | ||
"-----BEGIN CERTIFICATE-----\n" | ||
"MIIDTjCCAregAwIBAgIBLDANBgkqhkiG9w0BAQUFADCBkzELMAkGA1UEBhMCRlIx\n" | ||
"DzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRUwEwYDVQQKDAxF\n" | ||
"eGFtcGxlIEluYy4xIDAeBgkqhkiG9w0BCQEWEWFkbWluQGV4YW1wbGUuY29tMSYw\n" | ||
"JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjExMjMw\n" | ||
"MjU1MDdaFw0xNzAxMjIwMjU1MDdaMHExCzAJBgNVBAYTAkZSMQ8wDQYDVQQIDAZS\n" | ||
"YWRpdXMxFTATBgNVBAoMDEV4YW1wbGUgSW5jLjEZMBcGA1UEAwwQdXNlckBleGFt\n" | ||
"cGxlLmNvbTEfMB0GCSqGSIb3DQEJARYQdXNlckBleGFtcGxlLmNvbTCCASIwDQYJ\n" | ||
"KoZIhvcNAQEBBQADggEPADCCAQoCggEBAKxB1KJGDNxnHXuJNnwVvqLB/kzy+q9d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IBVclkeUftEK2m6Kfd\n" | ||
"2hR774u5wzLXgYuk+TrcckfNAoGBAJ9X8hacjH0lnr8aIe7I8HLoxbZOcnuz+b4B\n" | ||
"kbiW8M8++W6uNCw2G9b1THnJEG6fqRGJXPASdH8P8eQTTIUHtY2BOOCM+dqNK1xc\n" | ||
"FrW9NJXAF+WcmmTgoEaTG9tGBirafV+JjK/1/b+fqJ6sVRzDHDcbBU9ThhQTY6XG\n" | ||
"VSZz4H8hAoGBAMeQQjiUlKBnpGt1oTgKDZo58b7ui61yftg+dEAwIKs6eb5X20vZ\n" | ||
"Ca4v/zg06k9lKTzyspQjJZuzpMjFUvDK4ReamEvmwQTIc+oYVJm9Af1HUytzrHJH\n" | ||
"u0/dDt0eYpZpzrFqxlP+0oXxlegD8REMVvwNCy+4isyCvjogDaYRfJqi\n" | ||
"-----END RSA PRIVATE KEY-----"; |
Uh oh!
There was an error while loading. Please reload this page.