ssl - curl:(60)SSL证书问题:在代理后面上传时

标签 ssl curl proxy upload zscaler

我需要在公司代理后面进行 curl 上传。根据我尝试的网站,我遇到了以下两种类型的问题,

  • curl:(35)错误:1408F10B:SSL例程:ssl3_get_record:错误的版本号
  • curl: (60) SSL 证书问题:无法获取本地颁发者证书

  • 以下是详细信息:
    案例一:
    . . . 
    < HTTP/1.1 200 Connection established
    < Proxy-agent: CCProxy
    < 
    * Proxy replied 200 to CONNECT request
    * CONNECT phase completed!
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    *   CAfile: /etc/ssl/certs/ca-certificates.crt
      CApath: /etc/ssl/certs
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    * CONNECT phase completed!
    * CONNECT phase completed!
    * error:1408F10B:SSL routines:ssl3_get_record:wrong version number
    * Closing connection 0
    curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number
    
    案例二:
    $ curl -vX POST -d "userId=5&title=Hello World&body=Post body." https://jsonplaceholder.typicode.com/posts
    Note: Unnecessary use of -X or --request, POST is already inferred.
    * Uses proxy env variable https_proxy == 'http://10.xx.xx.xx:808/'
    *   Trying 10.xx.xx.xx:808...
    * TCP_NODELAY set
    * Connected to 10.xx.xx.xx port 808 (#0)
    * allocate connect buffer!
    * Establish HTTP proxy tunnel to jsonplaceholder.typicode.com:443
    > CONNECT jsonplaceholder.typicode.com:443 HTTP/1.1
    > Host: jsonplaceholder.typicode.com:443
    > User-Agent: curl/7.68.0
    > Proxy-Connection: Keep-Alive
    > 
    < HTTP/1.1 200 Connection established
    < Proxy-agent: CCProxy
    < 
    * Proxy replied 200 to CONNECT request
    * CONNECT phase completed!
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    *   CAfile: /etc/ssl/certs/ca-certificates.crt
      CApath: /etc/ssl/certs
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    * CONNECT phase completed!
    * CONNECT phase completed!
    * TLSv1.3 (IN), TLS handshake, Server hello (2):
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (OUT), TLS alert, unknown CA (560):
    * SSL certificate problem: unable to get local issuer certificate
    * Closing connection 0
    curl: (60) SSL certificate problem: unable to get local issuer certificate
    More details here: https://curl.haxx.se/docs/sslcerts.html
    
    curl failed to verify the legitimacy of the server and therefore could not
    establish a secure connection to it. To learn more about this situation and
    how to fix it, please visit the web page mentioned above.
    
    问题不是上面的 CCProxy,而是我们公司使用的是 Zscaler 透明代理,它使用自己的证书拦截 SSL 请求。
    请问有什么办法可以解决吗?
    $ curl --version
    curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1g zlib/1.2.11 brotli/1.0.7 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.8.0 nghttp2/1.40.0 librtmp/2.3
    Release-Date: 2020-01-08
    
    $ lsb_release -a 
    No LSB modules are available.
    Distributor ID: Debian
    Description:    Debian GNU/Linux bullseye/sid
    Release:        testing
    Codename:       bullseye
    

    最佳答案

    两个选项中的第 1 步都将提取 Zscaler 证书。
    选项 1 直接 curl

  • 下载证书(所有证书都包含在一个文件中)
  • 执行curl命令传递您要使用的证书。

  • # 1
    openssl s_client -showcerts \
    -connect jsonplaceholder.typicode.com:443 </dev/null 2>/dev/null \
    | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p'  > typicode.crt
    # 2
    curl --cacert typicode.crt -v \
    -d "userId=5&title=Hello World&body=Post body." \
     https://jsonplaceholder.typicode.com/posts
    
    选项 2(安装程序脚本)
    万一curl命令由您无法控制的安装程序执行,然后更新您的证书:
  • 从服务器中提取证书(使用 FQDN 或 IP 和 PORT,即:jsonplaceholder.typicode.com:443)
  • 将 XXX.crt 证书移动到您的证书目录
  • 更新证书
  • 执行安装脚本

  • # 1
    openssl s_client -showcerts \
    -connect jsonplaceholder.typicode.com:443 </dev/null 2>/dev/null \
    | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p'  > typicode.crt
    # 2
    sudo mv typicode.crt /usr/local/share/ca-certificates/
    # 3
    sudo update-ca-certificates
    # 4 execute your installer script
    
    奖金
    如果您只需要/想要获取 Zscaler 证书,请从以下位置获取 IP:https://ip.zscaler.com
    openssl s_client -showcerts -servername server -connect 165.225.216.33:443 >  </dev/null 2>/dev/null | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | grep -m1 -B-1 -- '-----END CERTIFICATE-----'  > zscaler.crt
    
    更新(21 年 11 月 19 日):
  • 添加选项 1,何时是直接 curl并且无需安装证书。
  • 优化了提取证书(创建文件)的命令
  • 奖励:获得 Zscaler IP

  • 在 Zscaler 代理后面的 Ubuntu 20 和 18 上测试。
    无证书
    Without certificate
    有证书
    With certificate
    引用:
  • How to install certificates for command line
  • unable to connect to server: x509: certificate signed by unknown authority
  • 关于ssl - curl:(60)SSL证书问题:在代理后面上传时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63180813/

    相关文章:

    ssl - Java SSL : Invalid service principal name

    ubuntu - 当我通过 https 访问我的站点时,浏览器从服务器下载源代码

    PHP cURL 同步和异步

    proxy - 如何在tweepy中设置socks5代理?

    webpack - 无法将webpack-dev-server用作https网站的代理-ERR_TLS_CERT_ALTNAME_INVALID

    python - 米特代理 : does one have to set proxy server to local?

    amazon-web-services - 在 AWS Ubuntu(18.04) Nginx 上安装 SSL 证书(从 Godaddy 购买)

    ssl - 使用 Paypal Pro 需要哪种类型的 SSL 证书?

    bash - 如何使用 bash 从 wttr.in curl 结果中获取当前平均温度?

    java - 带有 tomcat 服务器的自签名证书的 TLS - 无法加载 PEM 客户端证书