我有提供自签名证书,我产生这样的HTTPS连接龙卷风服务器:HTTPS Python客户端
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
服务器的代码如下:
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()
我想有一个连接到服务器的python客户端,并检查服务器是否是正确的服务器(我猜是通过它的证书)。 目前我做了一个简单的客户端是这样的:
import httplib
HOSTNAME='localhost'
conn = httplib.HTTPSConnection(HOSTNAME)
conn.putrequest('GET','/')
conn.endheaders()
response = conn.getresponse()
print response.read()
什么你会建议我做(客户端将在稍后为移动应用我只使用Python为原型)?
谢谢。
如果你能为我提供一个Java的客户端也是可以的。 – lc2817
相关http://www.heikkitoivonen.net/blog/2010/08/23/ssl-in-python-2-7/ – jfs
相关:http://stackoverflow.com/questions/1087227/validate-ssl-certificates -with-python – jfs