यहाँ है मैं क्या किया है अब तक. का उपयोग कर ओपनएसएसएल, मैं अब इन फ़ाइलों: सीए.crt, ca.कुंजी है, सीए.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)
ग्राहक मशीन पर, मैं इस कोड. मैं भी नकल ca.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()
शुरू करने के बाद सर्वर एपीआई और फिर चल रहे ग्राहक कोड, मैं इस त्रुटि संदेश मिलता है पर क्लाइंट:
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 के द्वारा किसी भी मतलब है, तो मैं सच में नहीं पता है के बीच अंतर के सभी फ़ाइल एक्सटेंशन (मैं देखा है .पीईएम फ़ाइल में इस्तेमाल किया जा रहा सत्यापित करें, उदाहरण के लिए).
के अंदर लिंक मैं पता चला है इससे पहले, मैं भी करने की कोशिश की के मार्ग के निर्माण के ग्राहक हैं । पीईएम और उपयोग में है कि सत्यापित क्षेत्र है.