Skip to content

WiFiClientSecure self signed cert support? #265

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

Closed
forthlightning opened this issue Mar 15, 2017 · 9 comments
Closed

WiFiClientSecure self signed cert support? #265

forthlightning opened this issue Mar 15, 2017 · 9 comments
Labels
Type: Feature request Feature request for Arduino ESP32

Comments

@forthlightning
Copy link

WiFiClientSecure supported self-signed certs (perhaps accidentally) up until this commit. Is there a way to enable self signed operation?

@rodgergr
Copy link

@forthlightning @copercini
I may have been experiencing a similar problem when I could no longer connect to AzureIoTHub after commit #255 on the WiFiSecure library.

So, I did some digging and found some changes in ssl_client.cpp that seemed to be the cause of the issue.

In commit #255 the while() loop from line 241 onward was changed to return an error code, rather than printing out a handshake code and then breaking from the while loop.

I was not sure of intent of the change (i.e. whether it was an intended feature) , but tried changing this back to the original pre-#255 code as follows and everything began to work again:-)

` DEBUG_PRINT( "Performing the SSL/TLS handshake...\n");

while ((ret = mbedtls_ssl_handshake(&ssl_client->ssl_ctx)) != 0) {
    if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret != -76) {
        //return handle_error(ret);
		printf("mbedtls_ssl_handshake returned -0x%x\n", -ret);
		break;	 
				  
					 
    }
    delay(10);
    vPortYield();`

I realise that the printf statement may need to be upgraded to a DEBUG_PRINT, to match the new style, but did not want to play too much with the code.

As I'm only a newbie, I was not sure of the appropriate way to request a code change, but hope it is of some use.

@me-no-dev
Copy link
Member

Error should be exposed better. @copercini the client should act as any other client. All that is needed as error info for the handshake is to be exposed as some method that you can query on failed connect.
like:

if(!client.conect(...)) Serial.printf("SSL error was: %u\n", client.errorCode());

@copercini
Copy link
Contributor

@me-no-dev Yes, and change the internal debug print to be compatible with ESP debug levels.

@forthlightning @rodgergr
This commit just break the handshake if an error occur (some errors crash the entire board!)

About this issue:
When no CA is used, MbedTLS is returning:

No CA Chain is set, but required to operate.
MbedTLS message code: -30336

Which looks like a mbedtls bug: Mbed-TLS/mbedtls#506

I am not sure what is the best workaround for WiFiClientSecure avoid this.

@me-no-dev
Copy link
Member

@copercini I would rather you use ESP32 Arduino's debug procedures (log_v/log_d/log_i/log_w/log_e)

@forthlightning
Copy link
Author

So is the above hack from @rodgergr the recommended fix so far? Currently I just froze my arduino component at e304474 pending real fix

@me-no-dev me-no-dev added the Type: Feature request Feature request for Arduino ESP32 label Mar 24, 2017
me-no-dev pushed a commit that referenced this issue Mar 30, 2017
* Support self signed certificates

Fix for #265

mbedtls_ssl_conf_authmode was defined before mbedtls_ssl_config_defaults causing several bugs when no CA certificate is defined.

* Implement Arduino's log facility

Replace printf by ESP log handling

* Remove \n from debug messages

log_ doesn't need \n to break line.
@copercini
Copy link
Contributor

@forthlightning @rodgergr
Please check if it is working with last core version...

@rodgergr
Copy link

rodgergr commented Apr 5, 2017

@copercini I downloaded the latest core version and sslclient now works fine with a self-signed certificate😀Thanks for all of your hard work👍

@forthlightning
Copy link
Author

same here, this is great!

@me-no-dev
Copy link
Member

lets close this then :)

akilas1 added a commit to vbadri/ArduCAM_ESP32S_UNO that referenced this issue Aug 1, 2018
Added #undef min and #undef max in
cores/esp32/Arduino.h

Fixed ssl_client.cpp in
libraries/WiFiClientSecure/src

This should be self-signed certs.

Fixed the issue per link below:

espressif/arduino-esp32#265
turmary pushed a commit to Seeed-Studio/Seeed_Arduino_atWiFiClientSecure that referenced this issue Jan 22, 2020
* Support self signed certificates

Fix for espressif/arduino-esp32#265

mbedtls_ssl_conf_authmode was defined before mbedtls_ssl_config_defaults causing several bugs when no CA certificate is defined.

* Implement Arduino's log facility

Replace printf by ESP log handling

* Remove \n from debug messages

log_ doesn't need \n to break line.
blue-2357 pushed a commit to blue-2357/arduino-esp32 that referenced this issue Jul 17, 2024
* Support self signed certificates

Fix for espressif/arduino-esp32#265

mbedtls_ssl_conf_authmode was defined before mbedtls_ssl_config_defaults causing several bugs when no CA certificate is defined.

* Implement Arduino's log facility

Replace printf by ESP log handling

* Remove \n from debug messages

log_ doesn't need \n to break line.
dash0820 added a commit to dash0820/arduino-esp32-stripped that referenced this issue Mar 10, 2025
* Support self signed certificates

Fix for espressif/arduino-esp32#265

mbedtls_ssl_conf_authmode was defined before mbedtls_ssl_config_defaults causing several bugs when no CA certificate is defined.

* Implement Arduino's log facility

Replace printf by ESP log handling

* Remove \n from debug messages

log_ doesn't need \n to break line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature request Feature request for Arduino ESP32
Projects
None yet
Development

No branches or pull requests

4 participants