#include <Security/SecPolicy.h>
#include <Security/SecTrust.h>
#endif /* !USE_CDSA_CRYPTO */
-#include <Security/SecInternal.h>
+#include "utilities/SecCFRelease.h"
#include "sslDebug.h"
#include "sslKeychain.h"
#include <string.h>
#include <assert.h>
+#if TARGET_OS_IPHONE
+#include "utilities/SecCFRelease.h"
+#endif
#ifdef USE_SSLCERTIFICATE
thisSslCert = (SSLCertificate *)sslMalloc(sizeof(SSLCertificate));
if(thisSslCert == NULL) {
- return memFullErr;
+ return errSecAllocate;
}
if(SSLAllocBuffer(&thisSslCert->derCert, certData.Length,
ctx)) {
- return memFullErr;
+ return errSecAllocate;
}
memcpy(thisSslCert->derCert.data, certData.Data, certData.Length);
thisSslCert->derCert.length = certData.Length;
*sslCert = thisSslCert;
- return noErr;
+ return errSecSuccess;
}
/*
if(!cssmOidToAlg(&algId->algorithm, &sigAlg)) {
/* Only way this could happen is if we're given a bad cert */
sslErrorLog("sslCertSignerAlg() bad sigAlg OID\n");
- ortn = paramErr;
+ ortn = errSecParam;
goto errOut;
}
break;
default:
sslErrorLog("sslCertSignerAlg() unknown sigAlg\n");
- ortn = paramErr;
+ ortn = errSecParam;
break;
}
errOut:
identity = (SecIdentityRef)CFArrayGetValueAtIndex(certs, 0);
if(identity == NULL) {
sslErrorLog("parseIncomingCerts: bad cert array (1)\n");
- return paramErr;
+ return errSecParam;
}
if(CFGetTypeID(identity) != SecIdentityGetTypeID()) {
sslErrorLog("parseIncomingCerts: bad cert array (2)\n");
- return paramErr;
+ return errSecParam;
}
/*
certRef = (SecCertificateRef)CFArrayGetValueAtIndex(certs, cert);
if(certRef == NULL) {
sslErrorLog("parseIncomingCerts: bad cert array (5)\n");
- return paramErr;
+ return errSecParam;
}
if(CFGetTypeID(certRef) != SecCertificateGetTypeID()) {
sslErrorLog("parseIncomingCerts: bad cert array (6)\n");
- return paramErr;
+ return errSecParam;
}
/* Extract cert, convert to local format.
/* SUCCESS */
*destCert = certChain;
- return noErr;
+ return errSecSuccess;
/* free certChain, everything in it, other vars, return ortn */
sslDeleteCertificateChain(certChain, ctx);
SecKeyRef pubKey = NULL; /* Retained */
SecKeyRef privKey = NULL; /* Retained */
SecTrustRef trust = NULL; /* Retained */
- SecTrustResultType trustResult;
assert(ctx != NULL);
assert(destCertChain != NULL); /* though its referent may be NULL */
identity = (SecIdentityRef)CFArrayGetValueAtIndex(certs, 0);
if (identity == NULL) {
sslErrorLog("parseIncomingCerts: bad cert array (1)\n");
- ortn = paramErr;
+ ortn = errSecParam;
goto errOut;
}
if (CFGetTypeID(identity) != SecIdentityGetTypeID()) {
sslErrorLog("parseIncomingCerts: bad cert array (2)\n");
- ortn = paramErr;
+ ortn = errSecParam;
goto errOut;
}
certChain = CFArrayCreateMutable(kCFAllocatorDefault, numCerts,
&kCFTypeArrayCallBacks);
if (!certChain) {
- ortn = memFullErr;
+ ortn = errSecAllocate;
goto errOut;
}
CFArrayAppendValue(certChain, leafCert);
(SecCertificateRef)CFArrayGetValueAtIndex(certs, ix);
if (intermediate == NULL) {
sslErrorLog("parseIncomingCerts: bad cert array (5)\n");
- ortn = paramErr;
+ ortn = errSecParam;
goto errOut;
}
if (CFGetTypeID(intermediate) != SecCertificateGetTypeID()) {
sslErrorLog("parseIncomingCerts: bad cert array (6)\n");
- ortn = paramErr;
+ ortn = errSecParam;
goto errOut;
}
}
/* Obtain public key from cert */
-#if TARGET_OS_IOS
+#if TARGET_OS_IPHONE
ortn = SecTrustCreateWithCertificates(certChain, NULL, &trust);
#else
{
(int)ortn);
goto errOut;
}
- ortn = SecTrustEvaluate(trust, &trustResult);
- if (ortn) {
- sslErrorLog("parseIncomingCerts: SecTrustEvaluate err %d\n",
- (int)ortn);
- goto errOut;
- }
+
+
+#if !TARGET_OS_IPHONE
+ /* This is not required on iOS, but still required on osx */
+ SecTrustResultType trustResult;
+ ortn = SecTrustEvaluate(trust, &trustResult);
+ if (ortn) {
+ sslErrorLog("parseIncomingCerts: SecTrustEvaluate err %d\n",
+ (int)ortn);
+ goto errOut;
+ }
+#endif
+
+
pubKey = SecTrustCopyPublicKey(trust);
- if (pubKey == NULL) {
- sslErrorLog("parseIncomingCerts: SecTrustCopyPublicKey failed\n");
- ortn = -67712; // errSecInvalidKeyRef
- goto errOut;
- }
+ if (!pubKey) {
+ /* We parsed the private key succesfully but could not get the public key: return an error */
+ sslErrorLog("parseIncomingCerts: SecTrustCopyPublicKey failed\n");
+ ortn = errSecParam;
+ goto errOut;
+ }
/* SUCCESS */
errOut: