【问题标题】:How can I verify my selfsigned certificate when using easywebdav?使用 easy webdav 时如何验证我的自签名证书?
【发布时间】:2014-05-20 18:28:30
【问题描述】:

我知道how to connect to my owncloud with python, by using easywebdav

我使用的是自签名证书和verify_ssl=False,但这使我容易受到中间人攻击,这是首先使用 ssl 的唯一原因。

我正在使用 Fedora,并尝试将我的服务器证书添加到 $HOME/.pki/CA/cacert.pem,但仍然失败。

【问题讨论】:

    标签: python ssl webdav owncloud


    【解决方案1】:

    您已经在$HOME/.pki/CA/cacert.pem 中拥有服务器证书。但是为了对其他人来说是完整的,您可以像这样使用 python 获得证书:

    import ssl
    import os
    # get the https certificate
    cert = ssl.get_server_certificate(('example.com', 443))
    # append it to my personal chain
    pem_path = os.path.expanduser('~/.pki/CA/cacert.pem')
    with open(pem_path, 'a+') as f:
        f.write(cert)
    

    然后在easywebdav中使用它。 Easywebdav builds on requests。而verify_ssl 用作requests.Session.verify Requests docs say 它接受布尔值(True 使用默认链)CA_BUNDLE 的路径

    所以这应该有效:

    import easywebdav
    pem_path = os.path.expanduser('~/.pki/CA/cacert.pem')
    webdav = easywebdav.connect('example.com', username='user', password='pass', 
                                protocol='https', port=443,
                                verify_ssl=pem_path)
    ...
    

    【讨论】:

      猜你喜欢
      • 2017-01-30
      • 2015-11-01
      • 2012-09-08
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 2011-09-22
      • 2014-03-16
      • 1970-01-01
      相关资源
      最近更新 更多