title: Thread 1: EXC_BAD_ACCESS (code=1, address=0x10) error
body: <p>I have an <code>certificate</code> with <code>p12-format</code> and wanted to get some information off it. </p>
  
  <p>I have the following two functions</p>
  
  <pre><code>-(OSStatus)extractIdentityAndTrust: (CFDataRef) inPKCS12Data withIdentity:(SecIdentityRef *) outIdentity withTrust:(SecTrustRef *) outTrust withPassword:(CFStringRef) keyPassword
  {
      OSStatus securityError = errSecSuccess;
      const void *keys[] =   { kSecImportExportPassphrase };
      const void *values[] = { keyPassword };
      CFDictionaryRef optionsDictionary = NULL;
      optionsDictionary = CFDictionaryCreate(NULL, keys, values, (keyPassword ? 1 : 0), NULL, NULL);
      CFArrayRef items = NULL;
      securityError = SecPKCS12Import(inPKCS12Data, optionsDictionary, &amp;items);
      if(securityError == 0)
      {
          CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0);
          const void *tempIdentity = NULL;
          tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemIdentity);
          CFRetain(tempIdentity);
          *outIdentity = (SecIdentityRef)tempIdentity;
          const void *tempTrust = NULL;
          tempTrust = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemTrust);
          CFRetain(tempTrust);
          *outTrust = (SecTrustRef)tempTrust;
      }
  
      if(optionsDictionary) CFRelease(optionsDictionary);
      if(items) CFRelease(items);
      return securityError;
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>-(NSString *)copySummaryString:(SecIdentityRef *) identity
  {
      // Get the certificate from the identity.
      SecCertificateRef myReturnedCertificate = NULL;
      OSStatus status = SecIdentityCopyCertificate (*identity, &amp;myReturnedCertificate);
  
      if(status)
      {
          NSLog(@"SecIdentityCopyCertificate failed.\n");
          return NULL;
      }
  
      CFStringRef certSummary = SecCertificateCopySubjectSummary(myReturnedCertificate);
      NSString* summaryString = [[NSString alloc] initWithString:(__bridge NSString *)certSummary];
      CFRelease(certSummary);
      return summaryString;
  }
  </code></pre>
  
  <p>I call these two methods in my <code>viewDidLoad</code> in the following lines</p>
  
  <pre><code>SecIdentityRef identity = nil;
  SecTrustRef trust = nil;
  NSData *certPath = [[NSData alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"p12"]];
  CFDataRef certData = (__bridge_retained CFDataRef)(certPath);
  [self extractIdentityAndTrust:certData withIdentity:&amp;identity withTrust:&amp;trust withPassword:CFSTR("")];
  NSString* summaryString = [self copySummaryString:&amp;identity];
  NSLog(@"%@", summaryString);
  </code></pre>
  
  <p>But in my function <code>copySummaryString</code> I got the error at the following line</p>
  
  <pre><code>OSStatus status = SecIdentityCopyCertificate (*identity, &amp;myReturnedCertificate);
  </code></pre>
  
  <p>I didn't find any good example for it. How do I call these function correctly, why I get this error and what does this error mean?</p>
  
  <p>I also found post like <a href="https://stackoverflow.com/a/20913426/5629933">https://stackoverflow.com/a/20913426/5629933</a>, <a href="https://stackoverflow.com/a/19219932/5629933">https://stackoverflow.com/a/19219932/5629933</a> or <a href="https://stackoverflow.com/q/27852186">Custom Certificate in iOS App</a>.</p>
  
  <p>I also read the documentation of Apple on <a href="https://developer.apple.com/library/ios/documentation/Security/Conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html#//apple_ref/doc/uid/TP40001358-CH208-SW13" rel="nofollow noreferrer">https://developer.apple.com/library/ios/documentation/Security/Conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html#//apple_ref/doc/uid/TP40001358-CH208-SW13</a> but it's not very helpful.</p>