title: Finding a certificate on iOS
body: <p>Note this question is was asked in 2001. Things have changed.</p>
  
  <p>I have an iOS device that needs to access a Junos VPN. The opaque instructions from the Junos admin say that I have to retrieve a certificate that has been provisioned to the device using the Apple IPCU. I know that the cert is on the device (I can see it in Settings) and I can access the VPN though Mail, Safari and the Junos App. </p>
  
  <p>The Apple docs state that each app has its own keychain and yet all three of these apps can see the cert. The fact that Jusos can access a cert provisioned by IPCU implies that any app can access this certificate. However when I try to locate it: </p>
  
  <pre><code>    CFTypeRef   certificateRef = NULL;                                                  // will hold a ref to the cert we're trying to retrieve
  const char *certLabelString = "myCertificateName";                                      // c string of the certificate we're searching for.
  CFStringRef certLabel = CFStringCreateWithCString( NULL, certLabelString, kCFStringEncodingUTF8); // the search we need - a string match for a UTF8 String.
  
  const void *keys[] =   { kSecClass, kSecAttrLabel, kSecReturnRef };
  const void *values[] = { kSecClassCertificate, certLabel, kCFBooleanTrue };
  CFDictionaryRef dict = CFDictionaryCreate(NULL, keys, values, 3, NULL, NULL);       // set up a search to retrieve this certificate.
  OSStatus status = SecItemCopyMatching(dict, &amp;certificateRef);                               // Search the keychain, returning in dict
  
  if(status != errSecSuccess)
      NSLog(@"keychain find returned %ld", status);
  
  if(dict)
      CFRelease(dict);
  </code></pre>
  
  <p>It fails. My questions:</p>
  
  <ul>
  <li><p>Is this code correct? Actually I know
  it isn't because
  <code>SecItemCopyMatching</code> returns
  <code>errSecItemNotFound</code></p></li>
  <li><p>What value should I use for
  <code>certLabelString</code> - I am assuming the
  human readable name shown in
  Settings.</p></li>
  </ul>
  
  <p>In Settings, the cert looks like this (sadly obfuscated to death) the search text I specify is exactly the text shown in settings.</p>
  
  <p><img src="https://i.stack.imgur.com/nV3xQ.jpg" alt="alt text"></p>
  
  <p>Cross posted to <a href="https://devforums.apple.com/thread/79552" rel="nofollow noreferrer">Apple developer forums</a></p>