Chromedriver in Selenium and SSL certificate
You can tell the Chrome browser to use a specific client certificate for a particual URL by adding a registry KEY with the following content:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\AutoSelectCertificateForUrls\1 = "{\"pattern\":\"https://www.example.com\",\"filter\":{\"ISSUER\":{\"CN\":\"cn of issuer\"}}}"
You may add additional entries by adding additional keys under the same branch.
It's a little more complex on Linux as you need to modify the preferences which are in json format under the following location:
~/.config/chromium/Default/Preferences
It looks like the above option only works for machines joined to an Active Directory domain. In case the above steps don't work You may try using a preconfigured template to introduce the changes available for download from the following url: https://www.chromium.org/administrators/policy-templates
Instead of installing the Client Certificate you could just tell Chrome to ignore the untrusted certificate error using the --ignore-certificate-errors
command line switch.
To do this, create your instance of ChromeDriver
as follows:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();capabilities.setCapability("chrome.switches", Arrays.asList("--ignore-certificate-errors"));driver = new ChromeDriver(capabilities);
I solved this issue with below code
DesiredCapabilities cap = DesiredCapabilities.chrome();ImmutableMap<String, String> commandLineArguments = ImmutableMap.<String, String>builder() .put("web-security", "false") .put("ssl-protocol", "any") .put("ignore-ssl-errors", "true") .put("webdriver-loglevel", "DEBUG") .put("ssl-client-certificate-file", certificatePath) .put("ssl-client-key-passphrase", certificatePassword) .build();String[] params = commandLineArguments.entrySet().stream() .map(e -> String.format("--%s=%s", e.getKey(), e.getValue())) .collect(Collectors.toList()) .toArray(new String[0]);cap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, params);cap.setCapability(ChromeOptions.CAPABILITY, options);WebDriver driver = new PhantomJSDriver(cap);driver.get(Url);
But I had to convert my pfx certificate to pem using below command
openssl pkcs12 -in client_ssl_cert.pfx -out client_ssl_cert.pem -clcerts