这里是什么我有这么远。 使用openssl,我现在有这些文件: 加利福尼亚州。crt,加利福尼亚州。关键,加利福尼亚州。srl公司、服务器。crt、服务器。企业社会责任、服务器。关键。
我跟随了这个教程: https://carolinafernandez.github.io/development/2017/09/13/HTTPS-and-trust-chain-in-Flask
现在有这样的服务器:
from flask import Flask, request
from flask_restful import Resource, Api, reqparse
import psycopg2
import ssl
import sys
app = Flask(__name__)
api = Api(app)
# TODO: https security
HTTPS_ENABLED = True
VERIFY_USER = True
API_HOST = "0.0.0.0"
API_PORT = 8000
API_CRT = "server.crt"
API_KEY = "server.key"
API_CA_T = "ca.crt"
context = None
if(HTTPS_ENABLED):
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
if(VERIFY_USER):
context.verify_mode = ssl.CERT_REQUIRED
context.load_verify_locations(API_CA_T)
try:
context.load_cert_chain(API_CRT, API_KEY)
except Exception as e:
sys.exit("Error starting server: {}".format(e))
...[implementation of api]...
if __name__ == '__main__':
app.run(ssl_context=context, host=API_HOST, port=API_PORT, debug=True)
在客户机上,我有这样的代码。 我也复制的加利福尼亚州。crt到,机:
import os
import requests
import ssl
def test():
response = requests.get("https://[url of server]:8000/helloworld", verify='ca.crt')
#response = requests.get("http://[url of server]:8000/helloworld")
print(response.text);
def print_version():
print(ssl.OPENSSL_VERSION)
if __name__ == "__main__":
test()
#print_version()
之后开始的server api和随后运行的客户的代码,我获得这条错误消息的客户:
requests.exceptions.SSLError: HTTPSConnectionPool(host='[url of server]', port=8000): Max retries exceeded with url: /helloworld (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1123)')))
这样做的目的是,这样我可以有安全服务器服务器进行通信。 在可预见的未来,这将是一个服务器发送https请求到另一个服务器。 我用了错误的文件的格式为任何客户已经使用验证? 我不是专家在TLS通过任何手段,所以我真的不知道其中的差别之间的所有文件的扩展(我看见一个。pem文件中正在使用验证,例如)。
里面的链接表明我早些时候,我也试过的路线产生的客户。pem和使用,在核实领域。