Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

SSL support

Open anteph opened this issue 11 years ago • 155 comments

Hi! I would like to know if you plan to include SSL support in the libraries. I've tryed to send some https requests with no sucess.

It would be cool if it the ESP could act as a secure server too.

I've checked the some examples from the sdk and they have a code to create a secure server with digital certificate.

Thanks!

anteph avatar Apr 03 '15 13:04 anteph

SSL has been ~broken since 0.9.3-patch1 (and you needed a new libssl, separate from patch1, from Espressif.)

It's supposedly fixed again in 1.0.1b2 (you still need a special libssl for the moment) - http://bbs.espressif.com/viewtopic.php?f=5&t=382 - I haven't had a chance to try it yet, but I've heard good reports.

There are still some features missing for practical SSL - iirc there's no way to pin a certificate or do trust validation, it'll silently accept self-signed certs - but it's still a huge positive step.

abl avatar Apr 22 '15 20:04 abl

i have add the latest sdk + ssl patches see here: https://github.com/Links2004/Arduino/commit/af6c4008dfffdd2afca4a759cccdea8c7fe4c3ee pull request is waiting for merged (#93)

Links2004 avatar Apr 23 '15 13:04 Links2004

Merged that, thanks. Just one (obvious) thing to note: adding SSL libraries (axTLS) is one thing, but to make them useful we also need to add SSL support to WiFiClient/WiFiServer.

igrr avatar Apr 23 '15 14:04 igrr

@igrr does this issue cover adding HTTPS support to a WebClient application for accessing secure-connection-only APIs? What's the roadmap/timeline for including this feature? Is it actually possible?

vicatcu avatar Jun 17 '15 22:06 vicatcu

@Links2004 @igrr Do I read this thread correctly that there is support for an HTTPS WebClient built into the core now, but WiFiClient class "just" needs that core functionality integrated into it?

vicatcu avatar Jun 27 '15 00:06 vicatcu

@vicatcu:

does this issue cover adding HTTPS support to a WebClient application for accessing secure-connection-only APIs?

Yes - HTTPS is just HTTP over SSL sockets, so once SSL sockets are integrated with WiFiClient/WiFiServer, you should be able to talk to HTTPS servers.

What's the roadmap/timeline for including this feature?

I'm not very familiar with this project's codebase.

Is it actually possible?

Yes. Other projects (like https://github.com/tuanpmt/esp_bridge) are able to make HTTPS requests from an ESP8266. The primary limiting factor is certificate size and protocol support (TLS v1.2 is not yet supported and is mandatory for some servers) - and that the Espressif SDK doesn't always have working SSL built in to it (it works now!)

Do I read this thread correctly that there is support for an HTTPS WebClient built into the core now, but WiFiClient class "just" needs that core functionality integrated into it?

It's now possible to write a WiFiClient that opens a secure socket. The existing WebClient shouldn't need major changes.

abl avatar Jun 27 '15 01:06 abl

@abl cool, I need to come up to speed on on getting a dev environment set up so I can contribute...

vicatcu avatar Jun 27 '15 01:06 vicatcu

looking forward to SSL support as well for ESP8266. I am looking at using Golgi.io arduino stack as an option for the SSL shim as they provide other time saving and mission critical networking support functions.

glennalgie avatar Jul 20 '15 01:07 glennalgie

@igrr @Links2004 can you give any pointers on how to use axTLS to implement HTTPS capability into WiFiClient/WiFiServer? Any updates on progress here would be appreciated. I personally would like to see the WiFiClient capability implemented as the priority. Would it be beneficial splitting this issue into two; one for WiFiClient and one for WiFiServer?

vicatcu avatar Jul 25 '15 21:07 vicatcu

@vicatcu WiFiClient needs only TLS, not HTTPS. You can use WiFiClient for things other than HTTP — SSH and SMTP to name a few. The way to do this is to create a new class, let's say WiFiSecureClient, and override read/write methods of WiFiClient to pump data through TLS engine. Some additional methods for certificate management should be added as well. I'm not sure if there is anything that needs to be done on the server side, since WiFiServer's only job is to create a WiFiClient instance for every new connection. I suppose someone more familiar with TLS can comment on this.

igrr avatar Jul 25 '15 22:07 igrr

@igrr ah yes of course, that (that WiFiClient is not just about HTTP) makes a lot of sense.

vicatcu avatar Jul 25 '15 22:07 vicatcu

@vicatcu , have you started to implement the TLS on the WiFiClient? I need to connect to a webserver using https, and I'm interested in this functionality, and could try to help (don't know if I am able to do it, no previous experience with HTTPS or TLS).

Best regards

Fernando

fmgomes avatar Jul 30 '15 15:07 fmgomes

@fmgomes honestly I haven't really gotten anywhere yet - it's a pretty steep learning curve for me so I'm kind of in the same boat as you :-/. It's a bit frustrating to know it's possible for the last few months, but that I haven't had time / know-how / etc to help make it happen. @igrr spelled out what needs to happen pretty well in his last response, but I'm not sure what "certificate management" requires...

vicatcu avatar Jul 30 '15 15:07 vicatcu

When a client connects to a server and performs a TLS handshake (which is what turns a socket in to a secure socket, and HTTPS is just HTTP on a secure socket) the server sends over a certificate. The certificate is what identifies the server; without the certificate validation step, HTTPS prevents against eavesdropping but you could potentially be communicating with an attacker (aka a MitM attack.)

Validating a certificate:

  1. Check to see if the name of the server you're trying to connect to matches the server name on the certificate.
  2. Check to see if the certificate has expired.
  3. Check to see if the certificate was issued by a trusted CA.
  4. Check to see if the certificate has been revoked.

1 should be pretty easy to implement; the names should be exactly equal. Wildcard certificates exist but are considered harmful; not supporting them is probably fine for v1.

2 can probably be ignored for now; the vast majority of ESP8266 work will be bound to specific certificates because...

3 is the most complex part. On a normal computer, the OS (and sometimes the browser) maintains a list of trusted root certificates. For Debian, the size of this certificate package is 502kB (see https://packages.debian.org/sid/ca-certificates) - it's possible to shrink this down a bit but it's obviously a nonstarter for the average ESP8266 project. An alternative to this is simply maintaining a list of certificate fingerprints and checking that instead - creating an explicit whitelist of certificates. That's what I'd recommend - and when you're using certificate fingerprints, you can be lax about expiration and revocation and manage it yourself.

4 is a complicated topic - check out CRL and OCSP if you're curious - and way beyond what we'd want to do in an embedded system.

AxTLS probably has simple-ish calls to handle all of this; they'd need to be exposed via SecureWifiClient.

SecureWifiServer would need a new method that allows a user to set the public and private key to use.

abl avatar Jul 30 '15 17:07 abl

does thread this also cover applying TLS to MQTT eventually?

mtnbrit avatar Jul 30 '15 19:07 mtnbrit

For what I've read, adding https support is a little bit hard. But what about simple ciphering, for direct socket communication? Something with a symmetric key, that would be a good start.

I've read in the Espressif page that ESP8266 has a built in AES engine, but they don't specify if it is hardware or software based. Has anyone tried it?

anteph avatar Aug 02 '15 13:08 anteph

Just a comment on that list of work from @abl - to get going i'd be quite happy to not have any of that certificate validation stuff. Wont be sending my bank account details or anything top secret just need to post to a remote service that only supports https. So just binning the certificate after its read would be fine for my uses.

torntrousers avatar Aug 02 '15 15:08 torntrousers

If you just want to prevent un-authorized use rather then hid the messages, check out this page on using SipHash as a secure hash. http://www.forward.com.au/pfod/secureChallengeResponse/index.html

drmpf avatar Aug 02 '15 21:08 drmpf

So what's the latest?

  • Can I make a HTTPS request?
  • can I use TLS 1.2?
  • can I pin a certificate (avoid the CA lookups)?

cottsak avatar Aug 28 '15 02:08 cottsak

Is it now possible to make a HTTPS request? Or are there any libraries out there that I could use?

ghost avatar Aug 28 '15 18:08 ghost