Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Add setInsecure for esp32 #18

Merged
merged 2 commits into from
May 5, 2021
Merged

Add setInsecure for esp32 #18

merged 2 commits into from
May 5, 2021

Conversation

LioRei
Copy link

@LioRei LioRei commented May 4, 2021

I've added the setInsecure fonction to be able to work with self signed certificate, it's really usefull in dev ;)

Usage example in Secured ESP32 Websockets Client:
replace client.setCACert(echo_org_ssl_ca_cert); by client.setInsecure(); and voila, it's working

@khoih-prog
Copy link
Owner

Hi

Thanks for your PR. I prefer you change the PR as follows to not using an extra variable _use_insecure (similar to ESP8266 solution) and setInsecure is only optional whenever we don't need, don't have or don't use CA Certs

  1. client.hpp: no change by deleting
bool _use_insecure;
  1. WebSockets2_Generic_Client.hpp

Don't need this:

this->_use_insecure = true;

and change to

if ( this->_optional_ssl_ca_cert || this->_optional_ssl_client_ca || this->_optional_ssl_private_key )
{
  if (this->_optional_ssl_ca_cert)
  {
    client->setCACert(this->_optional_ssl_ca_cert);
  }

  if (this->_optional_ssl_client_ca)
  {
    client->setCertificate(this->_optional_ssl_client_ca);
  }

  if (this->_optional_ssl_private_key)
  {
    client->setPrivateKey(this->_optional_ssl_private_key);
  }
}  
else
{
  client->setInsecure();
}
  1. esp32_tcp.hpp : OK with your change

Usage:

Just keep these CA Certs as nullptr, and the client->setInsecure() will be called automatically

const char* _optional_ssl_ca_cert = nullptr;
const char* _optional_ssl_client_ca = nullptr;
const char* _optional_ssl_private_key = nullptr;

@khoih-prog khoih-prog requested review from khoih-prog and removed request for khoih-prog May 4, 2021 18:34
Copy link
Owner

@khoih-prog khoih-prog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change according to reply.
I'll add 2 more examples to demonstrate the new feature.

@LioRei LioRei requested a review from khoih-prog May 5, 2021 12:02
@khoih-prog khoih-prog merged commit 8e1c480 into khoih-prog:master May 5, 2021
@khoih-prog
Copy link
Owner

Thanks Lionel,

The PR has been merged and I'll add some more mods before publishing a new Release.

Regards,

@khoih-prog
Copy link
Owner

Hi Lionel,

Just added 2 new InSecure-mode examples. Please retest to be sure everything is OK. Thanks.

  1. InSecured-Esp32-Client
  2. InSecured-Esp8266-Client

@LioRei
Copy link
Author

LioRei commented May 5, 2021

I have tested the example with an ESP32-PICO-KIT (esp32-pico-d4) and an ESP32-S2 SAOLA, it's working for the 2 boards ;)

I don't own an ESP8266 so I can't test it

@khoih-prog
Copy link
Owner

Thanks. I'll published new release soon.

@khoih-prog khoih-prog changed the title added setInsecure for esp32 Add setInsecure for esp32 May 5, 2021
khoih-prog added a commit that referenced this pull request May 5, 2021
### Release v1.2.4

1. Add InSecure mode for ESP32. For more info, check [**Add setInsecure for esp32** #18](#18)
2. Add InSecude-mode examples for ESP32/ESP8266
khoih-prog added a commit that referenced this pull request May 5, 2021
### Release v1.2.4

1. Add InSecure mode for ESP32. For more info, check [**Add setInsecure for esp32** #18](#18)
2. Add InSecude-mode examples for ESP32/ESP8266
@khoih-prog
Copy link
Owner

HI Lionel,

Just published the new WebSockets2_Generic releases v1.2.4 with a note about your contribution in Contributions and Thanks.

Hoping to get more from you.

Regards,


Release v1.2.4

  1. Add InSecure mode for ESP32. For more info, check Add setInsecure for esp32 #18
  2. Add InSecude-mode examples for ESP32/ESP8266

@emanavas
Copy link

I update from Arduino ide to Release v1.2.4 and produce a error
D:\DC100\FW\arduino-1.8.13\portable\sketchbook\libraries\WebSockets2_Generic\src/Tiny_Websockets_Generic/network/esp32/esp32_tcp.hpp:71:24: error: 'class WiFiClientSecure' has no member named 'setInsecure'
this->client.setInsecure();

@LioRei
Copy link
Author

LioRei commented May 20, 2021

In the board manager, wich version of esp32 do you use ? Personnaly, I use 2.0.0-alpha1 because I'm using an ESP32S2 board.

@khoih-prog
Copy link
Owner

@emanavas

You have to install ESP32 core, at least the version v1.0.5.
The setInsecure() has been defined in WiFiClientSecure.h#L66

Next time, it's better to create a new issue, not post in the closed PR like this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants