Chrome on Windows : Automatic Client Certificate selection while using Selenium

To avoid the browser prompt for certificate selection (which requires code outside of Selenium like autoIt/Sikuli)

1. Import the certificate to Windows CAPI

a. You can use IE to import the certificate and store it in in “My Certificate” tab.

or, b. You can use below command to import the certificate

“certutil -f -user -p <password>  -importpfx <certificate>”

If you are automating the flow and may want to delete older certificate , You can use bolo code written in Java

String allCerts = execCommand.runCommand(“certutil -store -user My”);

List<String> CN = new ArrayList<String>();

int a = allCerts.indexOf(“, CN=”);

int b = allCerts.lastIndexOf(“, CN=”);

int c = allCerts.indexOf(” Non-root Certificate”);

int l = 0;

while( a <= b && a!=-1){

CN.add(allCerts.substring(a+5,c ));

String delCerts = execCommand.runCommand(“certutil -delstore -user My \”” + CN.get(l) + “\””);

log.info(“Deleting “ + CN.get(l) + ” : “ + delCerts);

l++;

a = allCerts.indexOf(“, CN=”,i+1);

c = allCerts.indexOf(” Non-root Certificate”,c+1);

}}

2. To let Chrome automatically select the certificate automatically:

Edit registry entry:  (If it does not exist, create it )

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\AutoSelectCertificateForUrls

Add Key: 1

Value: {{“pattern”:”[*.]abhay.com”,”filter”:{“ISSUER”:{“CN”:”ABHAY_ISSUER”}}}}

–> with above content, a certificate issued from CA “ABHAY_ISSUER” will automatically get selected when user access <any>.abhay.com

Advertisements