title: Get a PEM file for a trusted root certificate included in iOS (for authenticating gRPC)
body: <p>I have an iOS app that communicates with a server using gRPC. In order to secure the connection, the server has issued a certificate bound to a hostname. I need to validate that certificate against a root certificate on the iOS device.</p>
  
  <p>It looks like the following method, provided by gRPC on iOS, can be used to do the validation:</p>
  
  <pre><code>open class func setTLSPEMRootCerts(_ pemRootCert: String?, forHost host: String) throws
  </code></pre>
  
  <p>So to use it, I need to provide the root certificate I want to use for the validation, and the host that the server has issued their certificate against. The host part is easy -- it should just be the hostname that the server-issued cert it bound to. But I am stuck on getting hold of the root certificate.</p>
  
  <p>I've found the following example for accessing a root certificate:</p>
  
  <pre><code>NSString *certsPath = [[NSBundle mainBundle] pathForResource:@"cacert_product" ofType:@"pem"];
  NSError *error;
  NSString *contentInUTF8 = [NSString stringWithContentsOfFile:certsPath
                                                      encoding:NSUTF8StringEncoding
                                                         error:&amp;error];
  </code></pre>
  
  <p>In the example, the resulting <code>contentInUTF8</code> can then be used as the certificate parameter to the aforementioned method. But, the resource name in the example, <code>cacert_product</code>, seems to be a placeholder; at any rate, I don't have such a resource on my device, and I don't think it would refer to the resource I want to use anyway.</p>
  
  <p>The certificate I want to use is one of the trusted root certificates on <a href="https://support.apple.com/en-za/HT207177" rel="nofollow noreferrer">this list</a> of trusted root certificates included with iOS 10. I do not understand how to access it though.</p>
  
  <p>So my question is: how do I get a PEM file for one of the trusted root certificates included on an iOS device?</p>