'SecTrustCreateWithCertificates returns null trust object

I am trying to run cert chain verification and running into a problem where my trust object is null.

SecTrustCreateWithCertificates(certificates, SecPolicyCreateBasicX509(), trustObject)

Where "certificates" is an array that contains 3 SecCertificate,

  1. first one is the leaf cert,
  2. second is the intermediate and
  3. last one is the root cert.

osStatus returned is -50 which translates to "One or more parameters passed to a function were not valid"

If the array only has the leaf cert, the trust object is created just fine but obviously the SecTrustEvaluateWithError returns false since I am not passing in the intermediate and root cert.

Root cert is supposed to be the anchor cert so I tried setting it too but no luck. NOTE: I do not have these 3 certs saved in keychain or trust store, I create them using SecCertificateCreateWithData and the data I receive from the server. I have also verified from open ssl that all 3 generated certs are valid.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source