4 * doSet up SecTrust object, do a SecTrustEvaluate, release.
6 #include "testParams.h"
7 #include <Security/cssm.h>
8 #include <utilLib/common.h>
9 #include <utilLib/cspwrap.h>
10 #include <clAppUtils/clutils.h>
11 #include <clAppUtils/tpUtils.h>
12 #include <security_cdsa_utils/cuFileIo.h>
17 #include <Security/Security.h>
19 #define HOLD_SEARCH_LIST 0
21 /* for malloc debug */
24 //static const char *CERT_FILE = "amazon_v3.100.cer";
25 static const char *CERT_FILE
= "cduniverse_v3.100.cer";
27 /* common data, our known good cert, shared by all threads */
28 static unsigned char *certData
= NULL
;
29 static unsigned certLength
= 0;
31 /* read in our known good cert file, just once */
32 int secTrustEvalInit(TestParams
*testParams
)
34 if(certData
!= NULL
) {
37 if(testParams
->verbose
) {
38 printf("secTrusEval thread %d: reading cert file %s...\n",
39 testParams
->threadNum
, CERT_FILE
);
41 if(readFile(CERT_FILE
, &certData
, &certLength
)) {
42 printf("Error reading %s; aborting\n", CERT_FILE
);
43 printf("***This test must be run from the clxutils/threadTest directory.\n");
50 int secTrustEval(TestParams
*testParams
)
53 SecCertificateRef certRef
;
54 const CSSM_DATA cdata
= {certLength
, (uint8
*)certData
};
56 OSStatus ortn
= SecCertificateCreateFromData(&cdata
,
58 CSSM_CERT_ENCODING_DER
,
61 cssmPerror("SecCertificateCreateFromData", ortn
);
67 ortn
= SecKeychainCopySearchList(&sl
);
69 cssmPerror("SecPolicySearchCreate", ortn
);
74 for(loopNum
=0; loopNum
<testParams
->numLoops
; loopNum
++) {
75 if(testParams
->verbose
) {
76 printf("secTrustEval loop %d\n", loopNum
);
78 else if(!testParams
->quiet
) {
79 printChar(testParams
->progressChar
);
82 /* from here on emulate exactly what SecureTransport does */
83 CFMutableArrayRef certs
;
84 certs
= CFArrayCreateMutable(NULL
, 1, &kCFTypeArrayCallBacks
);
85 CFArrayInsertValueAtIndex(certs
, 0, certRef
);
87 SecPolicyRef policy
= NULL
;
88 SecPolicySearchRef policySearch
= NULL
;
90 OSStatus ortn
= SecPolicySearchCreate(CSSM_CERT_X_509v3
,
91 &CSSMOID_APPLE_TP_SSL
,
95 cssmPerror("SecPolicySearchCreate", ortn
);
99 ortn
= SecPolicySearchCopyNext(policySearch
, &policy
);
101 cssmPerror("SecPolicySearchCopyNext", ortn
);
104 CFRelease(policySearch
);
106 SecTrustRef secTrust
;
107 ortn
= SecTrustCreateWithCertificates(certs
, policy
, &secTrust
);
109 cssmPerror("SecTrustCreateWithCertificates", ortn
);
112 /* no action data for now */
114 SecTrustResultType secTrustResult
;
115 ortn
= SecTrustEvaluate(secTrust
, &secTrustResult
);
117 cssmPerror("SecTrustEvaluate", ortn
);
127 printf("Hit CR to continue: ");