繁体   English   中英

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

[英]Python Selenium - How to specify a client certificate to use in client SSL authentication

我根据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)

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

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

捎带以前的回复,这就是我所做的。

在我的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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM