4 * do a "CSSM_CL_CertGetFirstCachedFieldValue" 'n' times on a known good
5 * cert; with a variety of fields; verify same results each time.
7 #include "testParams.h"
8 #include <Security/cssm.h>
9 #include <utilLib/common.h>
10 #include <utilLib/cspwrap.h>
11 #include <clAppUtils/clutils.h>
12 #include <clAppUtils/tpUtils.h>
13 #include <security_cdsa_utils/cuFileIo.h>
18 #include <Security/oidscert.h>
19 #include <Security/x509defs.h>
20 #include <Security/oidsattr.h>
24 //static const char *CERT_FILE = "serverpremium.crt";
25 static const char *CERT_FILE
= "mypage.apple_v3.100.cer";
27 #define NUM_INNER_LOOPS 10
29 /* common data, our known good cert, shared by all threads */
30 static unsigned char *certData
= NULL
;
31 static unsigned certLength
= 0;
34 * Hard coded list of field OIDs to fetch
36 static const CSSM_OID
*fieldOids
[] =
38 &CSSMOID_X509V1Version
,
39 &CSSMOID_X509V1SubjectName
,
40 &CSSMOID_X509V1IssuerName
,
41 &CSSMOID_X509V1SerialNumber
,
42 &CSSMOID_X509V1ValidityNotBefore
,
43 &CSSMOID_X509V1ValidityNotAfter
,
44 &CSSMOID_X509V1Signature
47 #define NUM_FIELD_OIDS (sizeof(fieldOids) / sizeof(CSSM_OID *))
50 /* read in our known good cert file, just once */
51 int getCachedFieldsInit(TestParams
*testParams
)
53 if(certData
!= NULL
) {
56 if(testParams
->verbose
) {
57 printf("getFields thread %d: reading cert file %s...\n",
58 testParams
->threadNum
, CERT_FILE
);
60 if(readFile(CERT_FILE
, &certData
, &certLength
)) {
61 printf("Error reading %s; aborting\n", CERT_FILE
);
62 printf("***This test must be run from the clxutils/threadTest directory.\n");
68 static int compareFields(
70 const CSSM_DATA
*val1
,
71 const CSSM_DATA
*val2
)
73 /* data length must match */
74 if(val1
->Length
!= val2
->Length
) {
75 printf("***FieldValue.Length miscompare\n");
80 * The hard part. Most OIDs have some kind of C struct pointer in their
81 * FieldValue.Data pointers, so comparison is on an oid-by-oid basis.
82 * We'll just do the easy ones, and the ones we suspect may be causing
85 if(appCompareCssmData(oid
, &CSSMOID_X509V1Version
)) {
86 if(!appCompareCssmData(val1
, val2
)) {
87 printf("***CSSMOID_X509V1Version mismatch\n");
91 else if(appCompareCssmData(oid
, &CSSMOID_X509V1SerialNumber
)) {
92 if(!appCompareCssmData(val1
, val2
)) {
93 printf("***CSSMOID_X509V1SerialNumber mismatch\n");
97 else if(appCompareCssmData(oid
, &CSSMOID_X509V1ValidityNotBefore
)) {
98 CSSM_X509_TIME
*cssmTime1
= (CSSM_X509_TIME
*)val1
->Data
;
99 CSSM_X509_TIME
*cssmTime2
= (CSSM_X509_TIME
*)val2
->Data
;
100 if(!appCompareCssmData(&cssmTime1
->time
, &cssmTime2
->time
)) {
101 printf("***CSSMOID_X509V1ValidityNotBefore mismatch\n");
105 else if(appCompareCssmData(oid
, &CSSMOID_X509V1ValidityNotAfter
)) {
106 CSSM_X509_TIME
*cssmTime1
= (CSSM_X509_TIME
*)val1
->Data
;
107 CSSM_X509_TIME
*cssmTime2
= (CSSM_X509_TIME
*)val2
->Data
;
108 if(!appCompareCssmData(&cssmTime1
->time
, &cssmTime2
->time
)) {
109 printf("***CSSMOID_X509V1ValidityNotAfter mismatch\n");
113 else if(appCompareCssmData(oid
, &CSSMOID_X509V1CertificateIssuerUniqueId
)) {
114 if(!appCompareCssmData(val1
, val2
)) {
115 printf("***CSSMOID_X509V1CertificateIssuerUniqueId mismatch\n");
119 else if(appCompareCssmData(oid
, &CSSMOID_X509V1CertificateSubjectUniqueId
)) {
120 if(!appCompareCssmData(val1
, val2
)) {
121 printf("***CSSMOID_X509V1CertificateSubjectUniqueId mismatch\n");
125 else if(appCompareCssmData(oid
, &CSSMOID_X509V1Signature
)) {
126 if(!appCompareCssmData(val1
, val2
)) {
127 printf("***CSSMOID_X509V1Signature mismatch\n");
134 static int checkOneField(
135 CSSM_CL_HANDLE clHand
,
136 CSSM_HANDLE cacheHand1
,
137 CSSM_HANDLE cacheHand2
,
138 const CSSM_OID
*fieldOid
)
140 CSSM_DATA_PTR fieldData1
= NULL
;
141 CSSM_DATA_PTR fieldData2
= NULL
;
143 CSSM_HANDLE resultHand1
= 0;
144 CSSM_HANDLE resultHand2
= 0;
145 uint32 numFields
= 0;
148 crtn
= CSSM_CL_CertGetFirstCachedFieldValue(
159 printf("Fiedl not present; try another cert\n");
162 crtn
= CSSM_CL_CertGetFirstCachedFieldValue(
172 rtn
= compareFields(fieldOid
, fieldData1
, fieldData2
);
173 CSSM_CL_CertAbortQuery(clHand
, resultHand1
);
174 CSSM_CL_CertAbortQuery(clHand
, resultHand2
);
175 CSSM_CL_FreeFieldValue(clHand
, fieldOid
, fieldData1
);
176 CSSM_CL_FreeFieldValue(clHand
, fieldOid
, fieldData2
);
180 int getCachedFields(TestParams
*testParams
)
183 CSSM_HANDLE cacheHand1
;
184 CSSM_HANDLE cacheHand2
;
189 for(loopNum
=0; loopNum
<testParams
->numLoops
; loopNum
++) {
190 if(testParams
->verbose
) {
191 printf("getCachedFields loop %d\n", loopNum
);
193 else if(!testParams
->quiet
) {
194 printChar(testParams
->progressChar
);
197 /* get two cached certs */
198 cert
.Data
= certData
;
199 cert
.Length
= certLength
;
200 crtn
= CSSM_CL_CertCache(testParams
->clHand
, &cert
, &cacheHand1
);
202 printError("CSSM_CL_CertCache(1)", crtn
);
205 crtn
= CSSM_CL_CertCache(testParams
->clHand
, &cert
, &cacheHand2
);
207 printError("CSSM_CL_CertCache(2)", crtn
);
211 /* grind thru the known OIDs */
212 for(fieldNum
=0; fieldNum
<NUM_FIELD_OIDS
; fieldNum
++) {
213 int rtn
= checkOneField(testParams
->clHand
,
216 fieldOids
[fieldNum
]);
221 CSSM_CL_CertAbortCache(testParams
->clHand
, cacheHand1
);
222 CSSM_CL_CertAbortCache(testParams
->clHand
, cacheHand2
);
226 printf("Hit CR to continue: ");