确保烧瓶服务器连接安全

时间:2019-06-30 11:57:34

标签: python security networking encryption flask

我正在通过python中的flask创建一个普通的HTTP服务器。该程序应在普通计算机上运行。然后,移动应用程序将访问该Web服务器,并交换一些关键数据。

现在的问题是,如何确保连接的安全性。 代码段:

from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['GET'])
def result():
    some_critical_data = request.form['data']
    return 'Some other critical data'


if __name__ == '__main__':
    app.run(host='0.0.0.0', port='8071', debug=True)

1 个答案:

答案 0 :(得分:0)

OpenSSL很酷:

from flask import Flask, jsonify

from OpenSSL import SSL
context = SSL.Context(SSL. SSL.SSLv23_METHOD)
context.use_privatekey_file('server.key')
context.use_certificate_file('server.crt')

from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['GET'])
def result():
    some_critical_data = request.form['data']
    return 'Some other critical data'


if __name__ == '__main__':  
     app.run(host='0.0.0.0', port='8071', debug=True, ssl_context=context)