Need script to validate certificate in sys_certificate table

IceIronDragon
Tera Guru

We have a task :

 

>>validate all certs in sys_certificate

>>if If any errors occur during the validation, either mark the "Active" checkbox as false/disable 

 

What is the code to achieve this. thanks 

1 ACCEPTED SOLUTION

Dom Gattuso
Mega Sage

Hi @IceIronDragon 

 

You can run the following background script to check if the certificates are valid, I recommend running in a sub-production environment first of course:

 

 

var gr = new GlideRecord('sys_certificate');
gr.addEncodedQuery('expires_in_days>0');
gr.query();

while(gr.next()){
       var valid = new SNC.CertificateValidator().validate(gr);
       if(!valid){
              gs.info("Certificate for "+gr.getValue('name')+" = VALID");
              gr.setValue('active', true);

       }else{
              gs.info("Certificate for "+gr.getValue('name')+" = INVALID");
              gr.setValue('active', false);
       }
       gr.update();
}

 

 

 

This uses the CertificateValidator API which is the same API used for the UI Action "Validate Stores/Certificates" on the sys_certificate table. 

View solution in original post

2 REPLIES 2

Dom Gattuso
Mega Sage

Hi @IceIronDragon 

 

You can run the following background script to check if the certificates are valid, I recommend running in a sub-production environment first of course:

 

 

var gr = new GlideRecord('sys_certificate');
gr.addEncodedQuery('expires_in_days>0');
gr.query();

while(gr.next()){
       var valid = new SNC.CertificateValidator().validate(gr);
       if(!valid){
              gs.info("Certificate for "+gr.getValue('name')+" = VALID");
              gr.setValue('active', true);

       }else{
              gs.info("Certificate for "+gr.getValue('name')+" = INVALID");
              gr.setValue('active', false);
       }
       gr.update();
}

 

 

 

This uses the CertificateValidator API which is the same API used for the UI Action "Validate Stores/Certificates" on the sys_certificate table. 

Thanks, this is for sub prod only 🙂 

 

I will test and update, thank you for the prompt response