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

gix*_*xer 6 python authentication ssl selenium

我根据Python Selenium中的答案查看了所有json文件中的所有可能键- FireFox webdriver配置文件首选项中有哪些可能的键,但是我找不到用于指定要在我的SSL连接中使用的客户端证书的密钥.

我已经对此进行了研究,但我找不到确切的答案.我发现我们需要根据如何使用Selenium [在Python中]为Firefox导入SSL证书中的答案将证书添加到FireFox配置文件中?,但我有点困在这里,我无法弄清楚这个证书究竟是如何添加的.

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

所以,总之,我正在寻找一些看起来像这样的配置:

profile.add_client_cert(path_to_cert)
profile.add_private_key(path_to_private_key)
Run Code Online (Sandbox Code Playgroud)

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

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

Lit*_*leQ 0

正如我在源代码中看到的,您可以使用参数 ( 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)
Run Code Online (Sandbox Code Playgroud)