1. Этот сайт использует файлы cookie. Продолжая пользоваться данным сайтом, Вы соглашаетесь на использование нами Ваших файлов cookie. Узнать больше.

SSL по ГОСТу из Питона

Тема в разделе "python", создана пользователем searchengines, 5 июн 2019.


Поделиться в соц сетях

  1. searchengines

    searchengines Administrator

    Регистрация:
    5 янв 2019
    Сообщения:
    1.671
    Симпатии:
    2
    Баллы:
    38
    Пытаюсь реализовать https соединение по ГОСТ. Сервер которому посылаю запрос использует протокол TLSv1. Кодом задал версию протокола:

    import ssl
    from functools import wraps

    def sslwrap(func):
    @wraps(func)
    def bar(*args, **kw):
    kw['ssl_version'] = ssl.PROTOCOL_TLSv1
    return func(*args, **kw)
    return bar

    ssl.wrap_socket = sslwrap(ssl.wrap_socket)

    response = requests.post('https://api.stage.mdlp.crpt.ru/api/v1/documents/send', data=data, headers=header)
    print(response.content)


    Но все равно выдает ошибку:

    Internal Server Error: /api/integration/mdlp/query-kiz-info/
    Traceback (most recent call last):
    File "C:\python_venv\lib\site-packages\urllib3\contrib\pyopenssl.py", line 438, in wrap_socket
    cnx.do_handshake()
    File "C:\python_venv\lib\site-packages\OpenSSL\SSL.py", line 1915, in do_handshake
    self._raise_ssl_error(self._ssl, result)
    File "C:\python_venv\lib\site-packages\OpenSSL\SSL.py", line 1647, in _raise_ssl_error
    _raise_current_error()
    File "C:\python_venv\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
    OpenSSL.SSL.Error: [('SSL routines', 'ssl3_read_bytes', 'sslv3 alert handshake failure')]

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\python_venv\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
    File "C:\python_venv\lib\site-packages\urllib3\connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
    File "C:\python_venv\lib\site-packages\urllib3\connectionpool.py", line 844, in _validate_conn
    conn.connect()
    File "C:\python_venv\lib\site-packages\urllib3\connection.py", line 326, in connect
    ssl_context=context)
    File "C:\python_venv\lib\site-packages\urllib3\util\ssl_.py", line 325, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
    File "C:\python_venv\lib\site-packages\urllib3\contrib\pyopenssl.py", line 445, in wrap_socket
    raise ssl.SSLError('bad handshake: %r' % e)
    ssl.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_read_bytes', 'sslv3 alert handshake failure')],)",)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\python_venv\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
    File "C:\python_venv\lib\site-packages\urllib3\connectionpool.py", line 630, in urlopen
    raise SSLError(e)
    urllib3.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_read_bytes', 'sslv3 alert handshake failure')],)",)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\python_venv\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
    response = get_response(request)
    File "C:\python_venv\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
    File "C:\python_venv\lib\site-packages\django\core\handlers\base.py", line 227, in process_exception_by_middleware
    response = middleware_method(request, exception)
    File "C:/Users/amotov/IdeaProjects/kmisregion_backend\common\middleware.py", line 23, in process_exception
    raise exception
    File "C:\python_venv\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\python_venv\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
    File "C:\python_venv\lib\site-packages\django\views\generic\base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
    File "C:\python_venv\lib\site-packages\rest_framework\views.py", line 489, in dispatch
    response = self.handle_exception(exc)
    File "C:\python_venv\lib\site-packages\rest_framework\views.py", line 449, in handle_exception
    self.raise_uncaught_exception(exc)
    File "C:\python_venv\lib\site-packages\rest_framework\views.py", line 486, in dispatch
    response = handler(request, *args, **kwargs)
    File "C:/Users/amotov/IdeaProjects/kmisregion_backend\integration\mdlp\views.py", line 146, in post
    mdlp_tasks.test_send_doc(sign_service, utils.to_base64(xml), signed_message)
    File "C:/Users/amotov/IdeaProjects/kmisregion_backend\integration\mdlp\tasks.py", line 385, in test_send_doc
    response = requests.post('https://api.stage.mdlp.crpt.ru/api/v1/documents/send', data=data, headers=header, verify=False)
    File "C:\python_venv\lib\site-packages\requests\api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
    File "C:\python_venv\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
    File "C:\python_venv\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
    File "C:\python_venv\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
    File "C:\python_venv\lib\site-packages\requests\adapters.py", line 527, in send
    raise SSLError(e, request=request)
    requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_read_bytes', 'sslv3 alert handshake failure')],)",)
    [05/Jun/2019 12:31:30] "POST /api/integration/mdlp/query-kiz-info/ HTTP/1.1" 500 23022


    Что я делаю не так? Подскажите, плз!!!
     

Поделиться этой страницей