vjmuzik / NativeEthernet

Native Ethernet library for Teensy 4.1
http://www.pjrc.com/teensy/td_libs_Ethernet.html
MIT License
62 stars 25 forks source link

Please add example for TLS rootCa verification #17

Open RoSchmi opened 3 years ago

RoSchmi commented 3 years ago

First: Thank you very much for your excellent work! Board: Teensy 4.1 IDE: Platformio Latest version of NativeEthernet library

I successfully followed the example 'WebClientRepeatingTLS' and could read from the page 'pjrc.com/about/contact.html'. However I was not successful to get rootCa verification working. Is it supported? I downloaded the root certificate DST Root CA X3 in the base64 encoded form from pjrc.com.

const char *dst_root_ca = "-----BEGIN CERTIFICATE-----\n" "MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\n" "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" "DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow\n" "PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n" "Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\n" "AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O\n" "rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq\n" "OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b\n" "xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw\n" "7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD\n" "aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n" "HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG\n" "SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69\n" "ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr\n" "AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n" "R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n" "JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n" "Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n" "-----END CERTIFICATE-----";

and entered the certificate through:

 client.setCACert((char *)dst_root_ca, strlen(dst_root_ca));

But I got error messages:

Initialize Ethernet with DHCP: DHCP assigned IP 192.168.1.102 You're connected to the network, IP = 192.168.1.102 TLS ca certificate error. connecting... HTTP/1.1 400 Bad Request Date: Sun, 14 Mar 2021 18:10:08 GMT Server: Apache/2.4.18 (Ubuntu) Strict-Transport-Security: max-age=15552000
Cache-Control: stale-while-revalidate=30 Content-Length: 441 Connection: close Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.


Apache/2.4.18 (Ubuntu) Server at www.pjrc.com Port 443

SockIndex: 0 SockStatus: 17 RecvErr: -26 SockIndex: 0 SockStatus: 17 RecvErr: -26 ...... ...... ...... Thanks in advance