는 방법을 확인하는 자체 서명된 인증서는 https 를 사용하여 요청"요청"모듈은 클라이언트에"플라스크-restful"서버에(TLS1.2)

0

질문

여기에 나는 지금까지. Openssl 을 사용하여,내가 지금 이러한 파일이 있: 캘리포니아입니다.crt,ca.키,ca.srl,서버입니다.crt,서버입니다.csr,서버입니다.키입니다.

그 후에 저는 튜토리얼: 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()

서버를 시작한 다음 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 고 사용하는 것에 확인하는 분야이다.

flask flask-restful self-signed tls1.2
2021-11-23 18:09:50
1

최고의 응답

0

오류에서 아래 [url of server] 해야제 host + port 예를 들어 127.0.0.1:8000

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)')))
2021-12-03 16:30:10

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................