Ho un server tornado che forniscono una connessione HTTPS con un certificato auto firmato che ho generato in questo modo:HTTPS Python cliente
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
Il codice del server è la seguente:
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()
Voglio avere un client python che si connette al server e verificare che il server sia il server giusto (suppongo attraverso il suo certificato). Per il momento ho fatto un semplice client come questo:
import httplib
HOSTNAME='localhost'
conn = httplib.HTTPSConnection(HOSTNAME)
conn.putrequest('GET','/')
conn.endheaders()
response = conn.getresponse()
print response.read()
Cosa suggerirebbe che io faccia (Il cliente sarà in seguito un app mobile Io uso solo pitone per la prototipazione)?
Grazie.
Se mi è possibile fornire un client in Java che è anche OK. – lc2817
correlati http://www.heikkitoivonen.net/blog/2010/08/23/ssl-in-python-2-7/ – jfs
correlati: http://stackoverflow.com/questions/1087227/validate-ssl-certificates -with-python – jfs