Imported Upstream version 3.13.6
[platform/upstream/nss.git] / mozilla / security / nss / cmd / libpkix / pkix / params / test_valparams.c
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is the PKIX-C library.
15  *
16  * The Initial Developer of the Original Code is
17  * Sun Microsystems, Inc.
18  * Portions created by the Initial Developer are
19  * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
20  *
21  * Contributor(s):
22  *   Sun Microsystems, Inc.
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 /*
38  * test_valparams.c
39  *
40  * Test ValidateParams Type
41  *
42  */
43
44 #include "testutil.h"
45 #include "testutil_nss.h"
46
47 static void *plContext = NULL;
48
49 static void
50 testDestroy(void *goodObject, void *equalObject, void *diffObject)
51 {
52         PKIX_TEST_STD_VARS();
53
54         subTest("PKIX_ValidateParams_Destroy");
55
56         PKIX_TEST_DECREF_BC(goodObject);
57         PKIX_TEST_DECREF_BC(equalObject);
58         PKIX_TEST_DECREF_BC(diffObject);
59
60 cleanup:
61
62         PKIX_TEST_RETURN();
63
64 }
65
66 static
67 void testGetProcParams(
68         PKIX_ValidateParams *goodObject,
69         PKIX_ValidateParams *equalObject){
70
71         PKIX_ProcessingParams *goodProcParams = NULL;
72         PKIX_ProcessingParams *equalProcParams = NULL;
73
74         PKIX_TEST_STD_VARS();
75         subTest("PKIX_ValidateParams_GetProcessingParams");
76
77         PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetProcessingParams
78                 (goodObject, &goodProcParams, plContext));
79
80         PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetProcessingParams
81                 (equalObject, &equalProcParams, plContext));
82
83         testEqualsHelper
84                 ((PKIX_PL_Object *)goodProcParams,
85                 (PKIX_PL_Object *)equalProcParams,
86                 PKIX_TRUE,
87                 plContext);
88
89 cleanup:
90
91         PKIX_TEST_DECREF_AC(goodProcParams);
92         PKIX_TEST_DECREF_AC(equalProcParams);
93
94         PKIX_TEST_RETURN();
95 }
96
97
98 static
99 void testGetCertChain(
100         PKIX_ValidateParams *goodObject,
101         PKIX_ValidateParams *equalObject){
102
103         PKIX_List *goodChain = NULL;
104         PKIX_List *equalChain = NULL;
105
106         PKIX_TEST_STD_VARS();
107         subTest("PKIX_ValidateParams_GetCertChain");
108
109         PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetCertChain
110                 (goodObject, &goodChain, plContext));
111
112         PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetCertChain
113                 (equalObject, &equalChain, plContext));
114
115         testEqualsHelper
116                 ((PKIX_PL_Object *)goodChain,
117                 (PKIX_PL_Object *)equalChain,
118                 PKIX_TRUE,
119                 plContext);
120
121 cleanup:
122
123         PKIX_TEST_DECREF_AC(goodChain);
124         PKIX_TEST_DECREF_AC(equalChain);
125
126         PKIX_TEST_RETURN();
127 }
128
129 static
130 void printUsage(char *pName){
131         printf("\nUSAGE: %s <central-data-dir>\n\n", pName);
132 }
133
134 int test_valparams(int argc, char *argv[]) {
135
136         PKIX_ValidateParams *goodObject = NULL;
137         PKIX_ValidateParams *equalObject = NULL;
138         PKIX_ValidateParams *diffObject = NULL;
139         PKIX_List *chain = NULL;
140         PKIX_UInt32 actualMinorVersion;
141         PKIX_UInt32 j = 0;
142         char *dirName = NULL;
143
144         char *goodInput = "yassir2yassir";
145         char *diffInput = "yassir2bcn";
146
147         char *expectedAscii =
148                 "[\n"
149                 "\tProcessing Params: \n"
150                 "\t********BEGIN PROCESSING PARAMS********\n"
151                 "\t\t"
152                 "[\n"
153                 "\tTrust Anchors: \n"
154                 "\t********BEGIN LIST OF TRUST ANCHORS********\n"
155                 "\t\t"
156 "([\n"
157                 "\tTrusted CA Name:         "
158                 "CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
159                 "\tTrusted CA PublicKey:    ANSI X9.57 DSA Signature\n"
160                 "\tInitial Name Constraints:(null)\n"
161                 "]\n"
162                 ", [\n"
163                 "\tTrusted CA Name:         OU=bcn,OU=east,O=sun,C=us\n"
164                 "\tTrusted CA PublicKey:    ANSI X9.57 DSA Signature\n"
165                 "\tInitial Name Constraints:(null)\n"
166                 "]\n"
167                 ")\n"
168                 "\t********END LIST OF TRUST ANCHORS********\n"
169                 "\tDate:    \t\t(null)\n"
170                 "\tTarget Constraints:    (null)\n"
171                 "\tInitial Policies:      (null)\n"
172                 "\tQualifiers Rejected:   FALSE\n"
173                 "\tCert Stores:           (EMPTY)\n"
174                 "\tCRL Checking Enabled:  0\n"
175                 "]\n"
176                 "\n"
177                 "\t********END PROCESSING PARAMS********\n"
178                 "\tChain:    \t\t"
179                 "([\n"
180                 "\tVersion:         v3\n"
181                 "\tSerialNumber:    37bc66ec\n"
182                 "\tIssuer:          CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
183                 "\tSubject:         OU=bcn,OU=east,O=sun,C=us\n"
184                 "\tValidity: [From: Thu Aug 19 16:19:56 1999\n"
185                 "\t           To:   Fri Aug 18 16:19:56 2000]\n"
186                 "\tSubjectAltNames: (null)\n"
187                 "\tAuthorityKeyId:  (null)\n"
188                 "\tSubjectKeyId:    (null)\n"
189                 "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
190                 "\tCritExtOIDs:     (2.5.29.15, 2.5.29.19)\n"
191                 "\tExtKeyUsages:    (null)\n"
192                 "\tBasicConstraint: CA(0)\n"
193                 "\tCertPolicyInfo:  (null)\n"
194                 "\tPolicyMappings:  (null)\n"
195                 "\tExplicitPolicy:  -1\n"
196                 "\tInhibitMapping:  -1\n"
197                 "\tInhibitAnyPolicy:-1\n"
198                 "\tNameConstraints: (null)\n"
199                 "]\n"
200                 ", [\n"
201                 "\tVersion:         v3\n"
202                 "\tSerialNumber:    37bc65af\n"
203                 "\tIssuer:          CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
204                 "\tSubject:         CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
205                 "\tValidity: [From: Thu Aug 19 16:14:39 1999\n"
206                 "\t           To:   Fri Aug 18 16:14:39 2000]\n"
207                 "\tSubjectAltNames: (null)\n"
208                 "\tAuthorityKeyId:  (null)\n"
209                 "\tSubjectKeyId:    (null)\n"
210                 "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
211                 "\tCritExtOIDs:     (2.5.29.15, 2.5.29.19)\n"
212                 "\tExtKeyUsages:    (null)\n"
213                 "\tBasicConstraint: CA(0)\n"
214                 "\tCertPolicyInfo:  (null)\n"
215                 "\tPolicyMappings:  (null)\n"
216                 "\tExplicitPolicy:  -1\n"
217                 "\tInhibitMapping:  -1\n"
218                 "\tInhibitAnyPolicy:-1\n"
219                 "\tNameConstraints: (null)\n"
220                 "]\n"
221                 ")\n"
222                 "]\n";
223
224         PKIX_TEST_STD_VARS();
225
226         startTests("ValidateParams");
227
228         PKIX_TEST_EXPECT_NO_ERROR(
229             PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
230
231         if (argc < 2){
232                 printUsage(argv[0]);
233                 return (0);
234         }
235
236         dirName = argv[j+1];
237
238         subTest("PKIX_ValidateParams_Create");
239         chain = createCertChain(dirName, diffInput, goodInput, plContext);
240         goodObject = createValidateParams
241                 (dirName,
242                 goodInput,
243                 diffInput,
244                 NULL,
245                 NULL,
246                 PKIX_FALSE,
247                 PKIX_FALSE,
248                 PKIX_FALSE,
249                 PKIX_FALSE,
250                 chain,
251                 plContext);
252         equalObject = createValidateParams
253                 (dirName,
254                 goodInput,
255                 diffInput,
256                 NULL,
257                 NULL,
258                 PKIX_FALSE,
259                 PKIX_FALSE,
260                 PKIX_FALSE,
261                 PKIX_FALSE,
262                 chain,
263                 plContext);
264         diffObject = createValidateParams
265                 (dirName,
266                 diffInput,
267                 goodInput,
268                 NULL,
269                 NULL,
270                 PKIX_FALSE,
271                 PKIX_FALSE,
272                 PKIX_FALSE,
273                 PKIX_FALSE,
274                 chain,
275                 plContext);
276
277         testGetProcParams(goodObject, equalObject);
278         testGetCertChain(goodObject, equalObject);
279
280         PKIX_TEST_EQ_HASH_TOSTR_DUP
281                 (goodObject,
282                 equalObject,
283                 diffObject,
284                 NULL, /* expectedAscii, */
285                 ValidateParams,
286                 PKIX_FALSE);
287
288         testDestroy(goodObject, equalObject, diffObject);
289
290 cleanup:
291
292         PKIX_TEST_DECREF_AC(chain);
293
294         PKIX_Shutdown(plContext);
295
296         PKIX_TEST_RETURN();
297
298         endTests("ValidateParams");
299
300         return (0);
301 }