Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPS for local IP address

I have a gadget[*] that connects to the user's WiFi network and responds to commands over a simple REST interface. The user uses a web app to control this gadget. The web app is currently served over http and the app's javascript does AJAX calls to the gadget's local IP address to control it. This scheme works well and I have no issues with it.

[*] By "gadget" I mean an actual, physical IoT device that the user buys and installs within their home, and configures to connect to their home WiFi network

Now, I want to serve this web app over https. I have no issue setting up https on the hosting side. The problem is, now the browser blocks access to the gadget (since the gadget's REST API is over http and not https).

The obvious solution is to have the gadget serve it's REST API over https. But how? It has a local IP address and no one will issue a certificate for it. (Even if they did, I'd have to buy a boatload of certificates for each possible local IP address.) I could round-trip via the cloud (by adding additional logic on my server side to accept commands from the web app and forward it to the gadget over another connection), but this will increase latencies.

Is there a way around this problem? One possibility that I have in mind is to:

  1. Get a wildcard certificate (say, *.mydomain.com)
  2. Run my own DNS that maps sub-domains to a local IP address following a pattern (For example, 192-168-1-123.mydomain.com would map to 192.168.1.123)
  3. Use the wild-card certificate in all the gadgets
  4. My web app could then make AJAX calls to https://192-168-1-123.mydomain.com instead of http://192.168.1.123 and latencies would remain unaffected aside from the initial DNS lookup

Would this work? It's an expensive experiment to try out (wildcard certificates cost ~$200) and running a DNS server seems like a lot of work. Plus I find myself under-qualified to think through the security implications.

Perhaps there's already a service out there that solves this problem?

like image 863
Harikrishna R Avatar asked Mar 30 '16 11:03

Harikrishna R


2 Answers

While this is a pretty old question, it is still nothing that you find out-of-the-box solutions for today.

Just as @Jaffa-the-cake posted in a comment, you can lean on how Plex did it, which Filippo Valsorda explained in his blog: https://blog.filippo.io/how-plex-is-doing-https-for-all-its-users/

This is very similar to what you proposed yourself. You don't even need a wildcard certificate, but you can generate certificates on-the-fly using Let's Encrypt. (You can still use wildcard certificates, if you want, which Let's Encrypt supports now, too.)

Just yesterday I did a manual proof-of-concept for that workflow, that can be automated with the following steps:

  • Write a Web Service that can create DNS entries for individual devices dynamically and generate matching certificates via Let's Encrypt - this is pretty easy using certbot and e.g. Google Cloud DNS. I guess Azure, AWS and others have similar offerings, too. When you use certbot's DNS plugins, you don't even need to have an actual web server running on port 80/443.
  • On you local device, contact that Web Service to generate a unique DNS entry (e.g. ..yourdns.com) and certificate for that domain
  • Use that certificate in your local HTTPS server
  • Browse to that domain instead of your local IP

Now you will have a HTTPS connection to your local server, using a local IP, but a publicly resolved DNS entry.

The downside is that this does not work offline from arbitrary clients. And you need to think of a good security concept to create trust between the client that requests a DNS and certificate, and your web service that will generate those.

BTW, do you mind sharing what kind of gadget it is that you are building?

like image 154
Daniel Albuschat Avatar answered Oct 17 '22 01:10

Daniel Albuschat


If all you want is to access the device APIs through the web browser, A Simple solution would be to proxy all the requests to the device through your web server.this was even self signed certs for the devices wont be a problem. Only problem though is that the server would have to be on the same network as your devices.

If you are not on the same network, you can write a simple browser plugin (chrome) to send the api request to IoT device. but then the dependency on the app/plugin will be clumsy.

like image 34
user3251850 Avatar answered Oct 17 '22 01:10

user3251850