【问题标题】:Handshake error in client (OS Error: TLSV1_ALERT_PROTOCOL_VERSION(tls_record.cc:586) in flutter app when trying to do a post/get request客户端握手错误(操作系统错误:TLSV1_ALERT_PROTOCOL_VERSION(tls_record.cc:586)在尝试执行发布/获取请求时颤振应用程序中
【发布时间】:2019-12-10 19:25:19
【问题描述】:

我有 Node.js 休息 API,我在我的颤振应用程序中使用它来相应地执行请求,但是当我尝试做同样的事情时,我得到一个异常:

Exception has occurred.
HandshakeException (HandshakeException: Handshake error in client (OS Error: TLSV1_ALERT_PROTOCOL_VERSION(tls_record.cc:586)))

我正在使用 http 客户端发出请求,例如:

import 'package:http/http.dart' as http;
const _baseUrl = https://domain.in/api/

http.Response response = await http.post(
      _baseUrl + 'user/login',
      body: json.encode(_authData),
      headers: {'Content-Type': 'application/json'},
    ).catchError((onError){
      print(onError);
    });

它可以与 http 一起使用,但它不能与 https 一起使用。

【问题讨论】:

    标签: node.js http flutter https nginx-reverse-proxy


    【解决方案1】:

    这是一个服务器端错误,因为您的 nginx ssl 配置。

    ssl_protocols 文件中的/etc/nginx/nginx.conf 行应如下所示:

    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    

    如果您在/etc/nginx/sites-enabled/defaultyourdomain 文件中为ssl 设置使用额外文件,例如ssl-params.conf,请在此文件中添加ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; 行。

    这是我的/etc/nginx/sites-enabled/default 文件的一部分:

    server {
        #Enable HTTP/2
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name domain.net www.domain.net;
    
        # Use the Let's Encrypt certificates
        ssl_certificate /etc/letsencrypt/live/domain.net/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.net/privkey.pem;
    
        #Include the SSL configuration from cipherli.st
        include snippets/ssl-params.conf; // <- !pay attention this line
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://localhost:5000/;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_cache_bypass $http_upgrade;
            proxy_redirect off;
        }
    }
    

    这是我的/etc/nginx/snippets/ssl-params.conf 文件:

    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on; 
    ssl_dhparam /etc/ssl/certs/dhparam.pem; 
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
    ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
    ssl_session_timeout  10m;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off; # Requires nginx >= 1.5.9
    ssl_stapling on; # Requires nginx >= 1.3.7
    ssl_stapling_verify on; # Requires nginx => 1.3.7
    resolver 8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout 5s; 
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    

    这是我的/etc/nginx/nginx.conf 中的ssl_protocols

    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    

    这个设置解决了我的问题。 我希望也能帮助其他人。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。问题出在服务器端 ssl 证书上。 我将请求从 https 更改为 http。

      【讨论】:

        猜你喜欢
        • 2021-07-13
        • 2019-07-22
        • 2020-03-22
        • 2022-07-20
        • 2021-11-17
        • 2021-07-18
        • 2020-06-18
        • 1970-01-01
        • 2014-10-04
        相关资源
        最近更新 更多