Auto Handshake certificate ethernet

hello friend
how can I use this function so that it recevies Auto handshake without certificate???
exp : when using class esp8266secure can get data handshake & its dosent need cert.h class or function & gets the certificate automaticaly the same as chrome browser when searching the web site
what library do you use for ssl and ethernet (Auto Handshake) ?
thx..

what library do you use for secure connection over Ethernet? and what board do you use?

My board : esp8266-12F
Ethernet Controller : ENC28j60
Lib : UIPEthernet for ethernet but i can change it if it helps ....
now
EthernetClient sslClient;
BearSSLClient client(sslClient);
.
.
.
client.connect(Link , 443);

but this code can not handshake certificate ssl & need hard code certificate statics

use the new lwIP_enc28j60 bundled with esp8266 arduino. it adds a new network interface and you work with it over the WiFi library same way as with the STA interface and SoftAP interface

do you have an example for this library ?

1 Like

in ESP8266WiFi library examples section in Arduino IDE

I have checked all the libraries none of them handshakes the certificate

if you use the lwIP_enc28j60 then you can use the same code as you used for WiFi

#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <FS.h>
#include "ESP8266httpUpdate.h"
//#include <SSLClient.h>
#include <EthernetENC.h>
//#include <BearSSLClient.h>
//#include <ArduinoBearSSL.h>
//#include <SSLClient.h>

void setup() {
//WiFiClientSecure client;
Ethernet.init(15);
delay(500);
EthernetClient sslClient;
// Ethernet sslClient;
// sslClient.setInsecure();
// BearSSLClient sslClient(client);
// sslClient.available();
// sslClient.setClient(client1);
// sslClient.setInsecure();
// BearSSLClient sslClient (client, TAs, (size_t)TAs_NUM);

// EthernetSSLClient sslClient(client, TAs, (size_t)TAs_NUM);
// SSLClient.setInsecure();
//EthernetSSLClient sslClient(client);
// SSLClient sslClient(client, TAs, (size_t)TAs_NUM,1);

sslClient.setTimeout(10000);
// client.setInsecure();
Serial.println("-->connecting to " + String("assess.mmaviot.com") + ":" + String("443"));
const char* Server_hub = "assess.mmaviot.com";
if (sslClient.connect(Server_hub, 443)) {
sslClient.print( String("GET ") + "/gadget/skeleton?serial=swr012108031138&uid=95f916e0-56d6-487f-82dd-da75b14081cb" + " HTTP/1.1\r\n" + "Host: " + Server_hub + "\r\n" + "Connection: close" + "\r\n\r\n");

Serial.println("request sent");

Serial.flush();
char status[20] = {0};
sslClient.readBytesUntil('\r', status, sizeof(status));
Serial.println("Command :");

// Serial.println(command_get);
Serial.println("Status :");
Serial.println(status);
Serial.println("Status Size:");
Serial.println(String(sizeof(status)));
Serial.println(status);

if (strcmp(status + 9, "200 OK") == 0)
{
  Serial.println("Connection Success");

// TLS = true;
while (sslClient.connected()) {
char endOfHeaders = "\r\n\r\n";
if (sslClient.find(endOfHeaders)) {
Serial.println(status);
String Data_Server = sslClient.readString();
// AnsTLS = Data_Server;
Serial.println(Data_Server);
}
}

}
else {
  Serial.println("** Connection Failed **");
  Serial.println(status);
}

sslClient.stop();
sslClient.flush();

}
else
{
char status[20] = {0};
sslClient.readBytesUntil('\r', status, sizeof(status));
Serial.println(status);

// TLS = false;
Serial.println("");
Serial.println("
Connection Failed ");
Serial.println("
");
}

}

void loop() {

}

And i got an error

ets Jan 8 2013,rst cause:2, boot mode:(3,2)

load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00045c40
~ld

why do you use EthermetENC + SSLClient and not the lwIP_enc28j60 library?

do you have a code which works over ESP8266WiFi library?

i haven't used these libraries (sslclient ) & comment this line
i want used lwIP_enc28j60 & ethernetclient

yes my code for ESP8266WiFi :

WiFiClientSecure espClient;
PubSubClient client(espClient);
espClient.setInsecure();

if (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect

if (client.connect("", Orphic.Server_User, Orphic.Server_Pass))
{ //serial //user //pass

.
.
.

i have used these codes for connection with wifi
and it works with out any problems
but i have problems with getting certificate ssl (Handshake) with ethernet (enc28j60)

isnt "lwIP_enc28j60 " library the EthernetENC ?? or are they different ?
the examples for "lwIP_enc28j60 " library are mostly from "EthernetENC" :frowning_face:

totally and completely different libraries.
lwIP_enc28j60 is part of the esp8266 core.
combine following sketch with yours

/*
    This sketch establishes a TCP connection to a "quote of the day" service.
    It sends a "hello" message, and then prints received data.
*/

#include <SPI.h>
#include <ENC28J60lwIP.h>

#include <ESP8266WiFi.h>

const char* host = "djxmmx.net";
const uint16_t port = 17;

#define CSPIN D1

ENC28J60lwIP eth(CSPIN);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server(23, 28, 179, 206);

void setup() {
  Serial.begin(115200);
  delay(500);

  WiFi.mode(WIFI_OFF);

  SPI.begin();
//  if (!eth.config(ip, gw, nm, gw, IPADDR_NONE)) {
//    Serial.println("wrong config");
//  }
  eth.setDefault(); // use ethernet for default route
  if (!eth.begin(mac)) {
    Serial.println("ethernet hardware not found ... sleeping");
    while (1) {
      delay(1000);
    }
  } else {
    Serial.print("connecting ethernet");
    while (!eth.connected()) {
      Serial.print(".");
      delay(1000);
    }
  }
  Serial.println();
  Serial.print("ethernet IP address: ");
  Serial.println(eth.localIP());
  Serial.println(eth.gatewayIP());
  Serial.println(eth.subnetMask());
  Serial.println(WiFi.dnsIP());
}

void loop() {
  static bool wait = true;

  Serial.print("connecting to ");
  Serial.print(host);
  Serial.print(':');
  Serial.println(port);

  WiFiClient client;
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    delay(5000);
    return;
  }

  // This will send a string to the server
  Serial.println("sending data to server");
  if (client.connected()) {
    client.println("hello from ESP8266");
  }

  // wait for data to be available
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      delay(60000);
      return;
    }
  }

  // Read all the lines of the reply from server and print them to Serial
  Serial.println("receiving from remote server");
  // not testing 'client.connected()' since we do not need to send data here
  while (client.available()) {
    char ch = static_cast<char>(client.read());
    Serial.print(ch);
  }

  // Close the connection
  Serial.println();
  Serial.println("closing connection");
  client.stop();

  if (wait) {
    delay(300000); // execute once every 5 minutes, don't flood remote service
  }
  wait = true;
}

Thank you for your immediate response

connecting ethernet...
ethernet IP address: 192.168.1.105
192.168.1.1
255.255.255.0
192.168.1.1
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
sending data to server
receiving from remote server
"Oh the nerves, the nerves; the mysteries of this machine called man!
Oh the little that unhinges it, poor creatures that we are!"
Charles Dickens (1812-70)

i cant connect my server :frowning_face:

connecting to assess.mmaviot.com:443
sending data to server
request sent
Command :
/gadget/skeleton?serial=swr012108031138&uid=95f916e0-56d6-487f-82dd-da75b14081cb
Status :
HTTP/1.1 400 Bad Req
Status Size:
20
HTTP/1.1 400 Bad Req
** Connection Failed **
HTTP/1.1 400 Bad Req
receiving from remote server
Print Data Available
uest
Server: nginx/1.14.2
Date: Fri, 20 Aug 2021 16:49:55 GMT
Content-Type: text/html
Content-Length: 271
Connection: close

400 The plain HTTP request was sent to HTTPS port

400 Bad Request

The plain HTTP request was sent to HTTPS port
nginx/1.14.2

closing connection

Code :

#include <SPI.h>
#include <ENC28J60lwIP.h>

#include <ESP8266WiFi.h>

const char* host = "assess.mmaviot.com";
const uint16_t port = 443;

#define CSPIN 15

ENC28J60lwIP eth(CSPIN);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server(103, 130, 144, 73);

void setup() {
  Serial.begin(115200);
  delay(500);

  WiFi.mode(WIFI_OFF);

  SPI.begin();
  //  if (!eth.config(ip, gw, nm, gw, IPADDR_NONE)) {
  //    Serial.println("wrong config");
  //  }
  eth.setDefault(); // use ethernet for default route
  if (!eth.begin(mac)) {
    Serial.println("ethernet hardware not found ... sleeping");
    while (1) {
      delay(1000);
    }
  } else {
    Serial.print("connecting ethernet");
    while (!eth.connected()) {
      Serial.print(".");
      delay(1000);
    }
  }
  Serial.println();
  Serial.print("ethernet IP address: ");
  Serial.println(eth.localIP());
  Serial.println(eth.gatewayIP());
  Serial.println(eth.subnetMask());
  Serial.println(WiFi.dnsIP());
}

void loop() {
  static bool wait = true;

  Serial.print("connecting to ");
  Serial.print(host);
  Serial.print(':');
  Serial.println(port);

  WiFiClient client;
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    delay(5000);
    return;
  }

  // This will send a string to the server
  Serial.println("sending data to server");
  if (client.connected()) {

    //////////////////////////////////////////////
    String command_get = "/gadget/skeleton?serial=swr012108031138&uid=95f916e0-56d6-487f-82dd-da75b14081cb";
    delay(20);
    client.println( String("GET ") + command_get + " HTTP/1.1\r\n" + "Host: " + "assess.mmaviot.com" + "\r\n" + "Connection: close" + "\r\n\r\n");

    Serial.println("request sent");
    delay(500);
    Serial.flush();
    char status[20] = {0};
    client.readBytesUntil('\r', status, sizeof(status));
    Serial.println("Command :");
    Serial.println(command_get);
    Serial.println("Status :");
    Serial.println(status);
    Serial.println("Status Size:");
    Serial.println(String(sizeof(status)));
    Serial.println(status);

    if (strcmp(status + 9, "200 OK") == 0)
    {
      Serial.println("Connection Success");
      //      TLS = true;
      while (client.connected()) {
        char endOfHeaders[] = "\r\n\r\n";
        if (client.find(endOfHeaders)) {
          Serial.println(status);
          String Data_Server = client.readString();
          //          AnsTLS = Data_Server;
          Serial.println(Data_Server);
        }
      }

    }
    else {
      Serial.println("** Connection Failed **");
      Serial.println(status);
    }



    /////////////////////////////////////////////////


    //
    //
    //    client.println("hello from ESP8266");
  }

  // wait for data to be available
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      delay(60000);
      return;
    }
  }

  // Read all the lines of the reply from server and print them to Serial
  Serial.println("receiving from remote server");
  // not testing 'client.connected()' since we do not need to send data here
  Serial.println("Print Data Available");
  while (client.available()) {

    char ch = static_cast<char>(client.read());
    Serial.print(ch);
  }

  // Close the connection
  Serial.println();
  Serial.println("closing connection");
  client.stop();

  if (wait) {
    delay(300000); // execute once every 5 minutes, don't flood remote service
  }
  wait = true;
}

my url :
https://assess.mmaviot.com/gadget/skeleton?serial=swr012108031138&uid=95f916e0-56d6-487f-82dd-da75b14081cb

you can connect. 400 Bad request is a response from the server telling you that the request doesn't match the HTTP protocol

try to remove all that " + "

yes , i connect to server
but i can't get data from server

i edited my code as you said
GET /gadget/skeleton?serial=swr012108031138&uid=95f916e0-56d6-487f-82dd-da75b14081cb HTTP/1.1 HTTP/1.1\r\nHost: assess.mmaviot.com\r\nConnection: close\r\n\r\n

but this code worked with wifi mode before.
i dont know where the problem is , only the request class has changed & the request method is the one that worked before ...

connected to server but no encryption data !! and i get this error ...

400 The plain HTTP request was sent to HTTPS port
HTTP/1.1 400 Bad Request
** Connection Failed **
receiving from remote server
Print Data Available

Server: nginx/1.14.2
Date: Sun, 22 Aug 2021 15:08:46 GMT
Content-Type: text/html
Content-Length: 271
Connection: close

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.14.2</center>
</body>
</html>

this library sends data in plain text mode & doesnt encrypt data
thats why nginx gives error 400 bad request

do you use your MQTT code with WiFiClientSecure?