Reputation: 824
I looked at all the possible keys in all json files based on the answer in Python Selenium - What are possible keys in FireFox webdriver profile preferences, but I couldn't find a key to specify the client certificate to use in my SSL connection.
I have researched on this, but I couldn't find the exact answer. I found that we need to add the certificate to the FireFox profile based on the answer in How to import SSL certificates for Firefox with Selenium [in Python]?, but I am kind of stuck here, I can't figure out how exactly this certificate needs to be added.
Please note that I am not talking about trusting a server's certificate. By default, when you initiate an SSL connection, a local certificate that is assigned to your workstation is used as the client certificate. Here I need to use a new certificate/private key pair for my SSL connection. I need to do this to test client authentication in SSL.
So, in summary, I am looking for some configuration that looks like this:
profile.add_client_cert(path_to_cert)
profile.add_private_key(path_to_private_key)
I found a couple of files that might be what I need to tweak, but not sure how to add certificate and keys to these files, cert8.db
and key3.db
. I found these files in the FireFox profile directory.
I searched the source code of selenium but couldn't find the answer: https://github.com/SeleniumHQ/selenium/search?utf8=%E2%9C%93&q=cert
Upvotes: 6
Views: 5341
Reputation: 2243
To piggyback on the previous response here's what I did.
In my python code: I have:
import os
profile_directory = os.path.join(os.path.abspath(os.sep),"home","rumpelstiltskin","my_cert_db")
self.driver = WebDriver(firefox_profile=profile)
Then to create the cert8.db
file I used the following terminal commands:
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
Upvotes: 0
Reputation: 1925
As I can see in the source code, you could create a firefox profile with a parameter (profile_directory
) and get firefox launched with the given profile. I think you may also set the preference profile.accept_untrusted_certs = True
.
The given profile directory should have client certificates prepared.
# 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)
Upvotes: 0