0

I'm creating a SSL Connection using PyOpenSSL and the trying to make a GET call but i run into :

`'HTTP/1.1 400 Bad Request\r\nDate: Fri, 14 Jul 2017 20:04:51 GMT\r\nServer: Apache/2.4.18 (Ubuntu)\r\nContent-Length: 305\r\nConnection: close\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n'
(Pdb) c
.. info: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at ecdhe-server Port 443</address>
</body></html>`

The Code i have is as follows :

1) I create SSL Connection as follows :

 client = socket()
            if self._proxy:
                    client.connect((proxy, 8080))
            else:
                    client.connect((host_name, port))
            context = Context(self._ssl_version)
            if self._ciphers:
                    context.set_cipher_list(self._ciphers)
            ssl_connection = Connection(context, client)
            if self._extension=='SNI':
                    ssl_connection.set_tlsext_host_name(host_name)
            ssl_connection.set_connect_state()
            ssl_connection.do_handshake()
            self._session_ref = ssl_connection.get_session()
            self._ssl_connection = ssl_connection

And then call the get() function which is as follows:

   def get(self, http_version='1.0'):
                #self._ssl_connection.sendall("GET / HTTP/1.1\r\n\r\n")
                self._ssl_connection.sendall("GET / HTTP/1.0\r\n\r\n")
                response_contents = self._ssl_connection.recv(4096)
                return response_contents

I tried all combinations of sendall and send(also i think) but i run into : .. info: HTTP/1.1 400 Bad Request Date: Fri, 14 Jul 2017 20:19:13 GMT Server: Apache/2.4.18 (Ubuntu) Content-Length: 305 Connection: close Content-Type: text/html; charset=iso-8859-1

I would appreciate if some one would help out in resolving the issue.

user1999223
  • 41
  • 1
  • 6
  • Some servers want you to provide at least a little additional information such as a "Host:" header (almost always required these days) and perhaps even a "User-Agent:" and "Accept:" header, plus others. A simple "GET /" isn't going to get you much these days. –  Jul 15 '17 at 01:40
  • That sounds strange as when i use the s_client to connect and then issue :GET / HTTP/1.0\r\n\r\n i get back the expected page output. But i'm know why the : recv api seems to hang. – user1999223 Jul 16 '17 at 01:50
  • Silly question, but is the page length greater than 4096 bytes and/or is ssl_connection.recv a non-blocking method? Also, can you sniff the traffic and see what happens? You won't be able to read the traffic (it's encrypted), but perhaps seeing what data, if any, is being transferred might help. –  Jul 16 '17 at 15:14
  • This issue is resolved i was missing the Host: in the call, hence i was able to get the expected results once i do : GET / HTTP/1.1\r\nHost: \r\nConnection: Close\r\n\r\n – user1999223 Jul 23 '17 at 15:32

0 Answers0