HTTPS on ESP32

Posted on
  • So I've been very happy with the level of support and efficiency of Espruino on both a ESP32 and ESP8266. However I get an error when I try to download a HTTPS site.

    This works on an ESP8266 but not an ESP32:

    var http = require("http");
    http.get("https://httpbin.org/ip", function(res) {
      res.on('data', function(data) {
        console.log(data);
      });
    });
    

    The error I get on my ESP32 is:

    Uncaught InternalError: Failed! mbedtls_ssl_handshake returned -0x7780
    

    Per mbed, I believe this relates to:

    MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */
    

    I see a video showing it working and this link: https://github.com/espruino/Espruino/iss­ues/960

    Maybe it broke in the latest release? I have 1v94.

    Any help is very much appreciated. Thanks.

  • Just a note - ESP8266 will likely ignore the https and will attempt a normal http connection, which is probably why it works.

  • Hi, Same issue with the linux version - so does not appear to be ESP32 related:

    root@office-pc:~/esp32/EspruinoBuildTool­s/esp32/build/Espruino# ./espruino
    Interactive mode.
    Size of JsVar is now 32 bytes
    Size of JsVarRef is now 4 bytes
    Added SIGINT hook
    Added SIGHUP hook
    Added SIGTERM hook
    
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v94.22 Copyright 2016 G.Williams
    
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    
    >var http = require("http");
    =function () { [native code] }
    >http.get("https://httpbin.org/ip", function(res) {
    :  res.on('data', function(data) {
    :    console.log(data);
    :  });
    :});
    =httpCRq { "type": 5,
      "#onconnect": function (res) { ... },
      "res": httpCRs {  },
      "opt": {
        "protocol": "https:",
        "method": "GET",
        "host": "httpbin.org",
        "path": "/ip",
        "pathname": "/ip",
        "search": null, "port": null, "query": null },
      "dSnd": "GET /ip HTTP/1.1\r" ... ": httpbin.org\r\n\r\n",
      "sckt": 4 }
    Uncaught InternalError: Failed! mbedtls_ssl_handshake returned -0x7780
    
    
  • Works with https://www.espruino.com or https://google.com so something is related to that site...

    Looks like you are trying to get you public IP - either use http or call something else?

  • Unfortunately I need HTTPS working. The ESP8266 is indeed getting secure pages, I've tested it with a simple nodejs server. Why can't the ESP32? I don't need to get the public IP that was just for example purposes.

    Can someone describe what needs to be enabled in the makefile or other switches so I can make my own build?

    Again, thanks for your help.

  • Sorry, the esp8266 does not have the required libs compiled in. It does not support https requests.

    The esp32 works fetching the google site as a secure page. What secure site is it you want to use?

    If you use your code above and change the request to one of the site in comment #4 you see that it does work with the esp32

  • Of course you guys are right on the ESP8266 HTTPS not working - I was wrongly recalling SSL working when I was writing in C using Espressif libraries.

    Anyway to close this out I have made HTTPS work for what I needed by using the "tls" module on the ESP32. I'm using short messages with a private server.

    However I think there's still something fishy. If I use 1V94 and run this code on an ESP32 I get this partial response from google with an error.

    var http = require("http");
    http.get("https://www.google.com", function(res) {
      res.on('data', function(data) {
        console.log(data);
      });
    });
    
    >reset();
    =undefined
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v94.203 Copyright 2017 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    >
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v94.203 Copyright 2017 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    >
    =undefined
    <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly
    what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/goo­gleg_standard_color_128dp.png" itemprop="image"><title>Google</title><s­cript>(function(){window.google={kEI
    ASSERT(net) FAILED AT libs/network/network.c:315
      #1[r1,l2] Object {
        #2[r1,l2] Name String [1 blocks] "\xFF"      #3[r1,l2] Object {
            #6[r1,l2] Name String [2 blocks] "timers"          #8[r2,l1] Array(0) [ ]
            #9[r1,l2] Name String [2 blocks] "watches"          #11[r2,l1] Array(0) [ ]
            #13[r1,l2] Name String [1 blocks] "net"          #14[r1,l3] String [1 blocks] "\x05\x00\x00\x00\x00\xFF\xFF\xFF"
            #21[r1,l2] Name String [2 blocks] "modules"          #23[r1,l1] Object {
                #20[r1,l2] Name String [1 blocks] "http"              #24[r2,l1] ...
     
              }
            #15[r1,l2] Name String [2 blocks] "history"          #26[r1,l1] Array(2) [
                #27[r1,l2] Name Integer 0              #17[r1,l1] String [3 blocks] "var http=require('http');"
                #34[r1,l2] Name Integer 1              #35[r1,l1] String [8 blocks] "http.get('https://www.google.com',funct­ion(a){a.on('data',function(a){console.l­og(a);});});"
              ]
            #70[r1,l2] Name String [2 blocks] "HttpCC"          #72[r1,l2] Array(1) [
                #100[r1,l3] Name Integer 0              #94[r1,l2] Object {
                    #95[r1,l2] Name String [2 blocks] "__proto__"                  #90[r2,l1] ...
     
                    #98[r1,l2] Name String [1 blocks] "type"= int 5
                    #97[r1,l2] Name String [2 blocks] "#onconnect"                  #30[r1,l1] Function {
                        #29[r1,l2] Name Param "\xFFa"                       undefined
                        #28[r1,l2] Name String [1 blocks] "\xFFcod"                      #43[r1,l1] FlatString [4 blocks] "a.on('data',function(a){console.log(a);­});"
                      }
                    #101[r1,l2] Name String [1 blocks] "res"                  #82[r2,l2] Object {
                        #83[r1,l2] Name String [2 blocks] "__proto__"                      #78[r2,l1] ...
     
                        #3038[r1,l2] Name String [2 blocks] "headers"                      #3037[r1,l1] Object {
                            #2920[r1,l2] Name String [1 blocks] "Date"                          #2917[r1,l1] String [3 blocks] "Thu, 07 Dec 2017 01:57:05 GMT"
                            #2922[r1,l2] Name String [2 blocks] "Expires"                          #2921[r1,l1] String [1 blocks] "-1"
                            #2926[r1,l2] Name String [2 blocks] "Cache-Control"                          #2924[r1,l1] String [2 blocks] "private, max-age=0"
                            #2931[r1,l2] Name String [2 blocks] "Content-Type"                          #2928[r1,l1] String [3 blocks] "text/html; charset=ISO-8859-1"
                            #2961[r1,l2] Name String [1 blocks] "P3P"                          #2955[r1,l1] String [6 blocks] "CP=\"This is not a P3P policy! See g.co/p3phelp for more info.\""
                            #2963[r1,l2] Name String [2 blocks] "Server"                          #2962[r1,l1] String [1 blocks] "gws"
                            #2967[r1,l2] Name String [2 blocks] "X-XSS-Protection"                          #2965[r1,l1] String [2 blocks] "1; mode=block"
                            #2970[r1,l2] Name String [2 blocks] "X-Frame-Options"                          #2969[r1,l1] String [1 blocks] "SAMEORIGIN"
                            #2980[r1,l2] Name String [2 blocks] "Set-Cookie"                          #2972[r1,l1] String [8 blocks] "1P_JAR=2017-12-07-01; expires=Sat, 06-Jan-2018 01:57:05 GMT; path=/; domain=.google.com"
                            #2876[r1,l2] Name String [2 blocks] "Set-Cookie"                          #2982[r1,l1] String [18 blocks] "NID=118=SOhYzUhpSnpGa2cLqJVy7nDq4R6uq1t­QktMfvFlDyeFQB8iwLM9RzMewFSmYIc8nvrPZQYP­0QnhPIkUkVbKxKZeEL-1PjEAa3cIgrkgaeTJRlkE­qUk7u68NvfZq2svvm; expires=Fri, 08-Jun-2018 01:57:05 GMT; path=/; domain=.google.com; HttpOnly"
                            #2890[r1,l2] Name String [2 blocks] "Alt-Svc"                          #2878[r1,l1] String [12 blocks] "hq=\":443\"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=\":443\"; ma=2592000; v=\"41,39,38,37,35\""
                            #2893[r1,l2] Name String [2 blocks] "Accept-Ranges"                          #2892[r1,l1] String [1 blocks] "none"
                            #2897[r1,l2] Name String [1 blocks] "Vary"                          #2895[r1,l1] String [2 blocks] "Accept-Encoding"
                            #2989[r1,l2] Name String [2 blocks] "Connection"                          #2988[r1,l1] String [1 blocks] "close"
                          }
                        #2992[r1,l2] Name String [2 blocks] "httpVersion"                      #2991[r1,l1] String [1 blocks] "1.1"
                        #2996[r1,l2] Name String [2 blocks] "statusCode"                      #2995[r1,l1] String [1 blocks] "200"
                        #2999[r1,l2] Name String [2 blocks] "statusMessage"                      #2998[r1,l1] String [1 blocks] "OK"
                        #3029[r1,l2] Name String [2 blocks] "#ondata"                      #3035[r1,l1] Function {
                            #3034[r1,l2] Name Param "\xFFa"                           undefined
                            #3031[r1,l2] Name String [1 blocks] "\xFFcod"                          #3033[r1,l1] String [2 blocks] "console.log(a);"
                            #3030[r1,l2] Name String [1 blocks] "\xFFsco"                          #2952[r1,l1] Function {
                                #2746[r1,l2] Name Param "a"                               #82[r2,l3] ...
     
                                #2745[r1,l2] Name String [2 blocks] "return"                              undefined
                              }
                          }
                      }
                    #102[r1,l2] Name String [1 blocks] "opt"                  #47[r1,l1] Object {
                        #49[r1,l2] Name String [2 blocks] "protocol"                      #48[r1,l1] String [1 blocks] "https:"
                        #52[r1,l2] Name String [2 blocks] "method"                      #51[r1,l1] String [1 blocks] "GET"
                        #56[r1,l2] Name String [1 blocks] "host"                      #54[r1,l1] String [2 blocks] "http://www.google.com"
                        #58[r1,l2] Name String [1 blocks] "path"                      #57[r1,l1] String [1 blocks] "/"
                        #60[r1,l2] Name String [2 blocks] "pathname"                      #59[r1,l1] String [1 blocks] "/"
                        #63[r1,l2] Name String [2 blocks] "search"                      #62[r1,l1] Unknown 2
                        #66[r1,l2] Name String [1 blocks] "port"                      #65[r1,l1] Unknown 2
                        #68[r1,l2] Name String [2 blocks] "query"                      #67[r1,l1] Unknown 2
                      }
                    #111[r1,l2] Name String [1 blocks] "dSnd"                  #2307[r1,l2] String [1 blocks] ""
                    #2343[r1,l2] Name String [1 blocks] "sckt"= int 3
                    #2951[r1,l2] Name String [1 blocks] "hdrs"                  #2950[r1,l1] Bool true
                  }
              ]
          }
        #16[r1,l2] Name String [1 blocks] "http"      #24[r2,l1] NativeFunction 0x400ea93c (0) { }
        #73[r1,l2] Name String [2 blocks] "httpCRs"      #75[r2,l1] NativeFunction 0x400ea840 (1) {
            #76[r1,l2] Name String [2 blocks] "prototype"          #78[r2,l1] Object {
                #79[r1,l2] Name String [2 blocks] "constructor"              #75[r2,l2] ...
     
              }
          }
        #85[r1,l2] Name String [2 blocks] "httpCRq"      #87[r2,l1] NativeFunction 0x400ea84c (1) {
            #88[r1,l2] Name String [2 blocks] "prototype"          #90[r2,l1] Object {
                #91[r1,l2] Name String [2 blocks] "constructor"              #87[r2,l2] ...
     
              }
          }
        #112[r1,l2] Name String [1 blocks] "ssl"      #113[r1,l1] Object {
            #114[r1,l2] Name Integer 2          #115[r1,l1] FlatString [78 blocks] "\x02\x00\x00\x00\x00\x00\x00\x00\xCD\xC­5E\xC1\xAEXR\xB0U\xDC\xB4\xFB5~\x94|\xD3­\x00\x00\x00\x00\x00\x00\x000\x00\x00\x0­0\x10'\x00\x00\x0E\x00\x00\x00Xp\xFB?\xE­2\xE8\xE0\x85E\xD3\xF6m\x9B4w\x8A\xA3\t\­xECk\x94\xFD\x14\f\x80NT\x97\xABl\xEF\xC­1\xC5@\xA39\xEA\xE2\xF2#\xAF1\x04N4\x05s­\xC4\x97\f\x9F\xAF\x1C\x03\xCFu\x9CM\x9B­\xE27!t#\xF2a\xD7\x1A\a\xECP\xAA\xA8\xDD­T\xE4\x9C\xD8' \x0B\xD4\xB8\x8F7K\xA3\x06\xAB\x068\xE4\­x9C'L\xC7nF\x9B\xDDY\xF8\x915\xF1%\xC5\x­D1m\xFD\xE2\xF1f)Z~\x04\xEE\x1D\xF5\xAF\­xE8%\x113\xCFi\xD6]\x89\xF2\x0B\xF6q\xBA­y\aT\x7F\xA8j\xA9\x9DY\f\x80\xC7'\xFA#\x­DB9U\xCB\xFE(f\x04\x97\xFE;\x8De\xF5\xBB­<\\\x9B\xBCh#3\xD6\xC1\xBEj\xDAAyM\xAD\x­A0m\xDA\xF8k\x93\xF2\x9Eo\x04\f\xA5\xE2a­\xF9\x03\xD3\xC5\x9D\xBF\xBB\xE6\xAEizX\­xC4\xB3;!\x89\xC0B\x90}8)\x03\x8F\xA6F\a­\x83\x03\xA4fz\n\xE0\x1F\xE6\xB5[\xF9H\x­DC!\xA1\x8Co\x1A\x80\x05h\xE0]\x16P\xC9^­\x99\xF6\x8FY\x1A\xF5+?`\x00\x00\x00\x00­\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00­\x00\x00\x10\b\x0F@\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x9Ct\xFB?\x10\x00\x00\x00\x03\x00\x0­0\x00\x03\x00\x00\x00\xDC\n\x0F@0\x0B\x0­F@\x00\x00\x00\x00(p\xFB?\xA8\xF8\xFB?\x­A8\xF8\xFB?\xA8\xF8\xFB?\x00\x00\x00\x00­\x00\x00\x00\x00\xC8\xF7\xFB?\xC8\xF7\xF­B?\xC8\xF7\xFB?\x00\x00\x00\x00\x00\x00\­x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\­bu\xFB?\bu\xFB?\x10u\xFB?\x13u\xFB?\x15u­\xFB?%u\xFB?\x00\x00\x00\x00\x17\x00\x00­\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00­\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00­\x00h\xB6\xFB?h\xB6\xFB?p\xB6\xFB?s\xB6\­xFB?u\xB6\xFB?\x85\xB6\xFB?\x17\x00\x00\­x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\­x00\x00\x00(\xFB\xFB?\x01\x00\x00\x00\xD­8-\xFB?\xD8-\xFB?\xD8-\xFB?\xD8-\xFB?\xE­4G\x16@\x00\x00\x00\x00p\x8A\x0F@0p\xFB?­\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00­\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00­\xDC\xC1@?\x00\x00\x00\x00\xB0r\xFB?\x00­\x00\x00\x00\xA4-\xFB?\x00\x00\x00\x00\x­03\x03\x03\x01\x00\x00\x00\x00"
          }
        #3027[r1,l2] Name String [2 blocks 
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

HTTPS on ESP32

Posted by Avatar for cmo @cmo

Actions