Python HTTPS Client

I have a tornado server that provides an https connection to a self-signed certificate that I generated this way:

openssl genrsa -out privatekey.pem 1024 openssl req -new -key privatekey.pem -out certrequest.csr openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem 

The server code is as follows:

 import tornado.ioloop import tornado.web import tornado.httpserver import os class MainHandler(tornado.web.RequestHandler): def get(self): print "new client "+str(self) self.write("Hello, world") application = tornado.web.Application([ (r"/", MainHandler), ]) http_server = tornado.httpserver.HTTPServer(application, ssl_options={ "certfile": os.path.join("./", "certificate.pem"), "keyfile": os.path.join("./", "privatekey.pem"), }) if __name__ == "__main__": http_server.listen(443) tornado.ioloop.IOLoop.instance().start() 

I want the python client to connect to the server and verify that the server is the correct server (I think through its certificate). At the moment, I made a simple client like this:

 import httplib HOSTNAME='localhost' conn = httplib.HTTPSConnection(HOSTNAME) conn.putrequest('GET','/') conn.endheaders() response = conn.getresponse() print response.read() 

What would you suggest to me ( The client will later be a mobile application I use only python for prototyping)?

Thanks.

+6
source share
2 answers

If you also control the client side (for example, in the Android or iphone application), you can add your self-signed certificate to the trust store.

Well explained here for android app

+3
source

The client cannot verify that the server is telling the truth. You can create a self-signed certificate for google.com.

+1
source

Source: https://habr.com/ru/post/900989/


All Articles