Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing https sites with IP address

Tags:

ssl

I wonder why I am getting certificate error if I try to access a site with ip address instead of domain name. Lets say for example nslookup says google.com is 173.194.43.96, so I tried to browse https://173.194.43.96 and I got certificate error saying that the security certificate presented by this website was issued for a different website's address. Why is that so?

like image 527
Steve Avatar asked Oct 29 '15 16:10

Steve


People also ask

Can you use HTTPS with an IP address?

The short answer is yes, but we don't recommend it. If your IP address changes your SSL certificate can become useless. If you decide that you really need an IP in your cert there are specific stipulations, conditions, and limitations to consider.

Can I access a website by its IP address?

Every web site on the internet is found not by its domain name but by its IP address. You can reach a site by typing in the IP address alone and that will take you directly to the site.

Why is accessing a website with IP address not secure?

This is because an SSL certificate is issued for a particular domain name. If the certificate name doesn't match the visited domain, the browser will show an error.

Are SSL Certificates tied to IP address?

An SSL Certificate is usually issued to a domain name and not an IP address. So long as your web server is hosting the domain name for which your SSL Certificate has been issued, the IP address doesn't matter.


2 Answers

This is because an SSL certificate is issued for a particular domain name. If the certificate name doesn't match the visited domain, the browser will show an error.

One of the main functions of SSL is to prove to the user that they are really connecting to the site they requested, and not to an attacker masquerading as the end site. Without linking the domain name to the certificate this would not be possible.

It is conceivable that the browser certificate system could have been designed to include the IP address in the certificate, but this would make it difficult to use DNS load balancing or even to change hosting providers, as a new certificate would have to be issued each time this happened. If the certificate included just the IP address and not the domain, this would leave the user defenseless against DNS spoofing attacks. So the only way forward really was to use the domain alone.

As a matter of interest, it is possible to obtain an SSL certificate for an IP address - and as Google is their own certificate authority, they could issue themselves a certificate for 173.194.43.96 and thus make it possible to browse google securely by ip address, so long as they used SNI to serve up the correct certificate. It seems implausible that this would be worth the additional complexity however...

This is a nice introduction to SSL if you want to read more:

https://timnash.co.uk/guessing-ssl-questions/

like image 109
jazmit Avatar answered Sep 25 '22 23:09

jazmit


On MAC High Sierra and Python 3.6.4, I tried the solution: requests toolbelt:HostHeaderSSLAdapter 1st, unfortunately, it doesn't work for me, then I tried forcediphttpsadapter, got it works finally.

The author explains everything in the readme part and has provided a sample script and it can be followed easily.

1.Install the library by pip install requests[security] forcediphttpsadapter

2.run the sample script:

import requests
from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter
session = requests.Session()
session.mount("https://example.com", ForcedIPHTTPSAdapter(dest_ip='1.2.3.4'))
response = session.get(
    '/some/path', headers={'Host': 'example.com'}, verify=False)

Note: For some cases, you may need to remove the prefix: 'www' from the url.

like image 20
Xb74Dkjb Avatar answered Sep 23 '22 23:09

Xb74Dkjb