From cd8e15c91bf590ac901002156b31a0d005b54c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uli=20K=C3=B6hler?= Date: Fri, 31 Dec 2021 02:47:25 +0100 Subject: [PATCH 1/3] Added HTTP over Wireguard example --- examples/http_over_wireguard/Computer.conf | 11 ++++ .../http_over_wireguard.ino | 58 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 examples/http_over_wireguard/Computer.conf create mode 100644 examples/http_over_wireguard/http_over_wireguard.ino diff --git a/examples/http_over_wireguard/Computer.conf b/examples/http_over_wireguard/Computer.conf new file mode 100644 index 0000000..ea8b34d --- /dev/null +++ b/examples/http_over_wireguard/Computer.conf @@ -0,0 +1,11 @@ +[Interface] +# Name = Computer +PrivateKey = ONj6Iefel47uMKtWRCSMLan2UC5eW3Fj9Gsy9bqcyEc= +Address = 10.217.59.1/24 +ListenPort = 19628 + +[Peer] +# Name = ESP32 +PublicKey = H3KaL/X94984cLDNWFsM4Hx6Rs/Ku0bW2ECkDUn7wFw= +AllowedIPs = 10.217.59.2/32 +PersistentKeepalive = 60 \ No newline at end of file diff --git a/examples/http_over_wireguard/http_over_wireguard.ino b/examples/http_over_wireguard/http_over_wireguard.ino new file mode 100644 index 0000000..b7f70e8 --- /dev/null +++ b/examples/http_over_wireguard/http_over_wireguard.ino @@ -0,0 +1,58 @@ +#include +#include +#include + +// WiFi configuration --- UPDATE this configuration for your WiFi AP +char ssid[] = "MyWifiESSID"; +char password[] = "my-wifi-password"; + +// WireGuard configuration --- UPDATE this configuration from JSON +char private_key[] = "gH2YqDa+St6x5eFhomVQDwtV1F0YMQd3HtOElPkZgVY="; +IPAddress local_ip(10, 217, 59, 2); +char public_key[] = "X6NJW+IznvItD3B5TseUasRPjPzF0PkM5+GaLIjdBG4="; +char endpoint_address[] = "192.168.178.133"; // IP of Wireguard endpoint to connect to. +int endpoint_port = 19628; + +static WireGuard wg; +static HTTPClient httpClient; + +void setup() +{ + Serial.begin(115200); + Serial.println("Connecting to the AP..."); + WiFi.begin(ssid, password); + while( !WiFi.isConnected() ) { + delay(100); + } + Serial.println(WiFi.localIP()); + Serial.println("Adjusting system time..."); + configTime(9 * 60 * 60, 0, "ntp.jst.mfeed.ad.jp", "ntp.nict.jp", "time.google.com"); + + Serial.println("Connected. Initializing WireGuard..."); + wg.begin( + local_ip, + private_key, + endpoint_address, + public_key, + endpoint_port); +} + +void loop() +{ + WiFiClient client; + + /** + * Connect to + * python3 -m http.server + */ + if( !client.connect("10.217.59.1", 8000) ) { + Serial.println("Failed to connect..."); + delay(1000); + return; + } else { // Client connected successfully. Send dummy HTTP request. + client.write("GET /wireguard-test HTTP/1.1\r\n"); + client.write("Host: wireguard.test.com\r\n"); + client.write("\r\n\r\n"); + } + +} \ No newline at end of file From fff24b742834966f358a0616b4d80f51367c81e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uli=20K=C3=B6hler?= Date: Fri, 31 Dec 2021 03:00:04 +0100 Subject: [PATCH 2/3] Remove unused import from example --- examples/http_over_wireguard/http_over_wireguard.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/http_over_wireguard/http_over_wireguard.ino b/examples/http_over_wireguard/http_over_wireguard.ino index b7f70e8..3aa8937 100644 --- a/examples/http_over_wireguard/http_over_wireguard.ino +++ b/examples/http_over_wireguard/http_over_wireguard.ino @@ -1,6 +1,5 @@ #include #include -#include // WiFi configuration --- UPDATE this configuration for your WiFi AP char ssid[] = "MyWifiESSID"; @@ -55,4 +54,4 @@ void loop() client.write("\r\n\r\n"); } -} \ No newline at end of file +} From 4cde10a2a9a3a7a597e6b2200446140bcf9f2c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uli=20K=C3=B6hler?= Date: Fri, 31 Dec 2021 03:16:18 +0100 Subject: [PATCH 3/3] Remove HTTP client from old version of the source code --- examples/http_over_wireguard/http_over_wireguard.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/http_over_wireguard/http_over_wireguard.ino b/examples/http_over_wireguard/http_over_wireguard.ino index 3aa8937..70d41ba 100644 --- a/examples/http_over_wireguard/http_over_wireguard.ino +++ b/examples/http_over_wireguard/http_over_wireguard.ino @@ -13,7 +13,6 @@ char endpoint_address[] = "192.168.178.133"; // IP of Wireguard endpoint to conn int endpoint_port = 19628; static WireGuard wg; -static HTTPClient httpClient; void setup() {