9

当我尝试:

HTTPoison.get! "https://facebook.com"

我得到:

** (HTTPoison.Error) {:tls_alert, 'unknown ca'}
[error] SSL: :certify: ssl_handshake.erl:1606:Fatal error: unknown ca

    (httpoison) lib/httpoison.ex:66: HTTPoison.request!/5

这是意料之中的,因为在我的公司中,我需要信任防火墙的证书才能退出。

我信任系统范围内的证书(.cer 文件),这就是为什么在访问URLwget时不给我 ssl 错误的原因。https但似乎 hackney/HTTPoison 忽略了这个配置。

如何让 HTTPoison/hackney 将证书识别为可信证书?

4

2 回答 2

5

我最近也遇到了这个问题。对我有用的是将证书文件的位置直接传递给此票hackney中开发人员的建议:

opts = [{:ssl_options, [{:cacertfile, "/<path to my cert>/MyCertificates.pem"}]}]
HTTPoison.post(login, headers, hackney: opts)

或者,您可以在不检查证书的情况下执行 SSL 连接(更多关于请求选项的信息):

HTTPoison.post(login, headers, hackney: [:insecure])
于 2016-10-11T17:52:36.083 回答
5

证书文件路径被传递给 HTTPoison 选项,如下所示:

   defp add_certs do
          [                                                                                                                                        
            hackney: [ # :hackney options                                                                                                          
             ssl_options: [ # :ssl options                                                                                                         
               cacertfile: # CA certificate used to validate server cert; path(), "string" is ok                  
               certfile:  # client certificate, signed by CA; path(), "string" is ok                                 
               keyfile:  # private key for client.crt; path(). "string" is ok                                         
               password:  # password for keyfile; string(), "string" not ok, use 'char list'                                  
             ]                                                                                                                                     
           ]                                                                                                     
          ]
    end
    HTTPoison.post(url, request_xml, headers, add_certs)
于 2016-10-12T08:22:12.843 回答