1

I am an Iranian guy. And because of my country limitation in use of global server such firebase, ... I can not use these server directly and I need to set up a VPN on my ESP32. I choose wireguard for this purpose and I the require library for that. but my mistake is I do not know how to configure private key, public key,... to connect to another country ISP. I have the configuration file like this:

    [Interface]
    PrivateKey = 8CRo9QpWNsdQoMjFtrKVPqP72ULvHJK32YpmcP5Tr1U=
    Address = 100.64.75.173/32
    DNS = 10.255.255.3
    
    [Peer]
    PublicKey = oeqDhAeoxw1g/6cKq/fo4ubgssbwhO3K2Nkmn6JVhg8=
    AllowedIPs = 0.0.0.0/0
    Endpoint = man-126-wg.whiskergalaxy.com:443
    PresharedKey = CIjpjsmGfthGlz59v7awyGIQGzAEW5sKkt7YYpQVj+4=

can anyone to help me pass parameter to this function according to above configuration file?

wg.begin(local_ip,private_key,endpoint_address,public_key,endpoint_port);

any help appreciated

MMB1999
  • 11
  • 1
  • 3

1 Answers1

0
IPAddress local_ip(100.64.75.173);                                          // [Interface] VPN Address
char private_key[]      = "8CRo9QpWNsdQoMjFtrKVPqP72ULvHJK32YpmcP5Tr1U=";   // [Interface] PrivateKey of esp
char public_key[]       = "oeqDhAeoxw1g/6cKq/fo4ubgssbwhO3K2Nkmn6JVhg8=";   // [Peer] PublicKey of peer
char endpoint_address[] = "man-126-wg.whiskergalaxy.com";                   // [Peer] Endpoint
int endpoint_port       = 443;                                              // [Peer] Endpoint

static WireGuard wg;
static const inline void beginWireGuard(){
  // Must set the correct time
  configTime(9 * 60 * 60, 0, "ntp.jst.mfeed.ad.jp", "ntp.nict.jp", "time.google.com");
  wg.begin(
    local_ip,           // IP address of the local interface
    private_key,        // Private key of the local interface
    endpoint_address,   // Address of the endpoint peer.
    public_key,         // Public key of the endpoint peer.
    endpoint_port);     // Port pf the endpoint peer.
}

Something like this should work. There are comments after the variables. You should call beginWireGuard(); after you connected to a wifi network.

Something like this:

#include "WiFi.h"
 
const char* ssid = "yourNetworkName";
const char* password =  "yourNetworkPass";

    IPAddress local_ip(100.64.75.173);                                          // [Interface] VPN Address
    char private_key[]      = "8CRo9QpWNsdQoMjFtrKVPqP72ULvHJK32YpmcP5Tr1U=";   // [Interface] PrivateKey of esp
    char public_key[]       = "oeqDhAeoxw1g/6cKq/fo4ubgssbwhO3K2Nkmn6JVhg8=";   // [Peer] PublicKey of peer
    char endpoint_address[] = "man-126-wg.whiskergalaxy.com";                   // [Peer] Endpoint
    int endpoint_port       = 443;                                              // [Peer] Endpoint
    
    static WireGuard wg;
    static const inline void beginWireGuard(){
      // Must set the correct time
      configTime(9 * 60 * 60, 0, "ntp.jst.mfeed.ad.jp", "ntp.nict.jp", "time.google.com");
      wg.begin(
        local_ip,           // IP address of the local interface
        private_key,        // Private key of the local interface
        endpoint_address,   // Address of the endpoint peer.
        public_key,         // Public key of the endpoint peer.
        endpoint_port);     // Port pf the endpoint peer.
    }

void setup() {
 
  Serial.begin(115200);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println("Connected to the WiFi network");
  beginWireGuard();
}
 
void loop() {}
Dr.Random
  • 430
  • 3
  • 16