Python Selenium - 如何指定在客户端SSL身份验证中使用的客户端证书

时间:2016-07-12 20:05:23

标签: python selenium authentication ssl

我根据Python Selenium - What are possible keys in FireFox webdriver profile preferences中的答案查看了所有json文件中的所有可能键,但是我找不到用于指定要在SSL连接中使用的客户端证书的密钥。

我已对此进行了研究,但我无法找到确切的答案。我发现我们需要根据How to import SSL certificates for Firefox with Selenium [in Python]?中的答案将证书添加到FireFox配置文件中,但我有点困在这里,我无法弄清楚这个证书究竟需要添加的程度。< / p>

请注意,我不是在谈论信任服务器的证书。默认情况下,启动SSL连接时,将分配给工作站的本地证书用作客户端证书。在这里,我需要为我的SSL连接使用新的证书/私钥对。我需要这样做来测试SSL中的客户端身份验证。

因此,总而言之,我正在寻找一些看起来像这样的配置:

profile.add_client_cert(path_to_cert)
profile.add_private_key(path_to_private_key)

我发现了一些可能需要调整的文件,但不确定如何将证书和密钥添加到这些文件cert8.dbkey3.db。我在FireFox配置文件目录中找到了这些文件。

我搜索了硒的源代码,但无法找到答案: https://github.com/SeleniumHQ/selenium/search?utf8=%E2%9C%93&q=cert

2 个答案:

答案 0 :(得分:0)

要piggy带以前的回答,这就是我所做的。

在我的python代码中:我有:

import os

profile_directory = os.path.join(os.path.abspath(os.sep),"home","rumpelstiltskin","my_cert_db")
self.driver = WebDriver(firefox_profile=profile)

然后使用以下终端命令创建cert8.db文件:

cd /home/rumpelstiltskin
mkdir my_cert_db
certutil -N -d sql:my_cert_db/
pk12util -n my-cert-name -d sql:my_cert_db/ -i /my/path/to/cert.p12

答案 1 :(得分:-2)

正如我在source code中看到的那样,您可以使用参数(profile_directory)创建一个firefox配置文件,并使用给定的配置文件启动firefox。我想你也可以设置偏好profile.accept_untrusted_certs = True

给定的配置文件目录应准备好客户端证书。

# Prepared Firefox profile directory
profile = FirefoxProfile(profile_diretory)

profile.set_preference("security.default_personal_cert", "Select Automatically")
profile.set_preference("webdriver_accept_untrusted_certs", True)
self.driver = WebDriver(firefox_profile=profile)
相关问题