4 * do a "GetAllFields" 'n' times on a known good cert; verify same results
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;
33 /* read in our known good cert file, just once */
34 int getFieldsInit(TestParams
*testParams
)
36 if(certData
!= NULL
) {
39 if(testParams
->verbose
) {
40 printf("getFields thread %d: reading cert file %s...\n",
41 testParams
->threadNum
, CERT_FILE
);
43 if(readFile(CERT_FILE
, &certData
, &certLength
)) {
44 printf("Error reading %s; aborting\n", CERT_FILE
);
45 printf("***This test must be run from the clxutils/threadTest directory.\n");
51 static int compareFields(
52 const CSSM_FIELD
*fieldPtr1
,
53 const CSSM_FIELD
*fieldPtr2
)
55 const CSSM_DATA
*val1
= &fieldPtr1
->FieldValue
;
56 const CSSM_DATA
*val2
= &fieldPtr2
->FieldValue
;
58 /* OIDs must match exactly */
59 if(!appCompareCssmData(&fieldPtr1
->FieldOid
, &fieldPtr2
->FieldOid
)) {
60 printf("***FieldOid miscompare\n");
64 /* data length must match */
65 if(val1
->Length
!= val2
->Length
) {
66 printf("***FieldValue.Length miscompare\n");
71 * The hard part. Most OIDs have some kind of C struct pointer in their
72 * FieldValue.Data pointers, so comparison is on an oid-by-oid basis.
73 * We'll just do the easy ones, and the ones we suspect may be causing
76 const CSSM_OID
*thisOid
= &fieldPtr1
->FieldOid
;
77 if(appCompareCssmData(thisOid
, &CSSMOID_X509V1Version
)) {
78 if(!appCompareCssmData(val1
, val2
)) {
79 printf("***CSSMOID_X509V1Version mismatch\n");
83 else if(appCompareCssmData(thisOid
, &CSSMOID_X509V1SerialNumber
)) {
84 if(!appCompareCssmData(val1
, val2
)) {
85 printf("***CSSMOID_X509V1SerialNumber mismatch\n");
89 else if(appCompareCssmData(thisOid
, &CSSMOID_X509V1ValidityNotBefore
)) {
90 CSSM_X509_TIME
*cssmTime1
= (CSSM_X509_TIME
*)val1
->Data
;
91 CSSM_X509_TIME
*cssmTime2
= (CSSM_X509_TIME
*)val2
->Data
;
92 if(!appCompareCssmData(&cssmTime1
->time
, &cssmTime2
->time
)) {
93 printf("***CSSMOID_X509V1ValidityNotBefore mismatch\n");
97 else if(appCompareCssmData(thisOid
, &CSSMOID_X509V1ValidityNotAfter
)) {
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_X509V1ValidityNotAfter mismatch\n");
105 else if(appCompareCssmData(thisOid
, &CSSMOID_X509V1CertificateIssuerUniqueId
)) {
106 if(!appCompareCssmData(val1
, val2
)) {
107 printf("***CSSMOID_X509V1CertificateIssuerUniqueId mismatch\n");
111 else if(appCompareCssmData(thisOid
, &CSSMOID_X509V1CertificateSubjectUniqueId
)) {
112 if(!appCompareCssmData(val1
, val2
)) {
113 printf("***CSSMOID_X509V1CertificateSubjectUniqueId mismatch\n");
117 else if(appCompareCssmData(thisOid
, &CSSMOID_X509V1Signature
)) {
118 if(!appCompareCssmData(val1
, val2
)) {
119 printf("***CSSMOID_X509V1Signature mismatch\n");
126 int getFields(TestParams
*testParams
)
129 CSSM_FIELD_PTR fieldPtr1
; // reference - mallocd by CL
130 CSSM_FIELD_PTR fieldPtr2
; // mallocd by CL
138 for(loopNum
=0; loopNum
<testParams
->numLoops
; loopNum
++) {
139 if(testParams
->verbose
) {
140 printf("getFields loop %d\n", loopNum
);
142 else if(!testParams
->quiet
) {
143 printChar(testParams
->progressChar
);
146 /* get reference fields */
147 cert
.Data
= certData
;
148 cert
.Length
= certLength
;
149 crtn
= CSSM_CL_CertGetAllFields(testParams
->clHand
,
154 printError("CSSM_CL_CertGetAllFields(1)", crtn
);
158 for(dex
=0; dex
<NUM_INNER_LOOPS
; dex
++) {
159 /* get all fields again */
160 crtn
= CSSM_CL_CertGetAllFields(testParams
->clHand
,
165 printError("CSSM_CL_CertGetAllFields(2)", crtn
);
169 /* compare to reference fields */
170 if(numFields1
!= numFields2
) {
171 printf("***CSSM_CL_CertGetAllFields returned differing numFields "
172 "(%u, %u)\n", (unsigned)numFields1
, (unsigned)numFields2
);
175 for(i
=0; i
<numFields1
; i
++) {
176 if(compareFields(&fieldPtr1
[i
], &fieldPtr2
[i
])) {
180 crtn
= CSSM_CL_FreeFields(testParams
->clHand
, numFields1
, &fieldPtr2
);
182 printError("CSSM_CL_FreeFields", crtn
);
188 printf("Hit CR to continue: ");
193 crtn
= CSSM_CL_FreeFields(testParams
->clHand
, numFields1
, &fieldPtr1
);
195 printError("CSSM_CL_FreeFields", crtn
);