How to add a specific certificate to driver with chrome options ?

Hello everyon, i want to add a specific certificate to my chrome options, i have been struggling for hours. Let me know if you have any type of solution. here is the example simplified code:

def certificatePath = ‘path/to/certificate.pem’

ChromeOptions options = new ChromeOptions()

options.addArguments(“–ignore-certificate-errors”)

options.addArguments(“–allow-running-insecure-content”)

options.addArguments(“–allow-insecure-localhost”)

options.addArguments(“–user-data-dir=” + certificatePath)

DriverFactory.changeWebDriver(driver(options))

WebUI.navigateToUrl(‘example.com’)

Thanks in advance for any contribution towards this topic !!

Hi,

Thank you for letting us know. Does anyone have the experience with this :smiley:

hi @cdion

chrome has no command line flag that takes a .pem, so there is nothing to put in ChromeOptions for this, and --user-data-dir= pointing at the cert path only creates a fresh empty profile folder there. certificates live in the os store (chrome reads it), so the fix is one import outside the test.

windows, run once as the user that runs katalon:

certutil -addstore -user Root path\to\certificate.pem

linux (chrome uses the nss db in your home):

certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n my-ca -i certificate.pem

after that a plain openBrowser trusts the site, you can drop --ignore-certificate-errors.

if it is a client certificate (the site asks you to pick one), import the .p12 into the personal store instead and add a chrome policy so the picker never shows: registry key HKLM\Software\Policies\Google\Chrome\AutoSelectCertificateForUrls with a value like {"pattern":"https://example.com","filter":{}}. that is the only way to make the dialog go away, selenium cannot click it.

If I am not wrong Chrome can’t take a cert file through ChromeOptions, and --user-data-dir just creates an empty profile. So, Import the certificate into the OS store instead (certutil -addstore Root cert.pem on Windows, the NSS db on Linux). If the site asks for a client certificate, import the .p12 and set Chrome’s AutoSelectCertificateForUrls policy to skip the picker.