User Certificate installation

It is necessary to automate the case that involves checking the certificate that installed on a device, if the certificate is not on the device, access to the app is absent, is it possible to somehow automate the process of installing CA certificate on the device, access to physical devices is absent, they are all on Device Farm

At first I thought I would use this solution, but I need a solution that covers both platforms

  1. Check that device farm company will allow you to do this. For me this looks not legal.
  2. For android first link in google https://stackoverflow.com/questions/44942851/install-user-certificate-via-adb. Easy can be automated