OLD | NEW |
1 /* | 1 /* |
2 * test_httpcertstore.c | 2 * test_httpcertstore.c |
3 * | 3 * |
4 * Test Httpcertstore Type | 4 * Test Httpcertstore Type |
5 * | 5 * |
6 * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved. | 6 * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions are met: | 9 * modification, are permitted provided that the following conditions are met: |
10 * | 10 * |
(...skipping 23 matching lines...) Expand all Loading... |
34 * You acknowledge that this software is not designed or intended for use in | 34 * You acknowledge that this software is not designed or intended for use in |
35 * the design, construction, operation or maintenance of any nuclear facility. | 35 * the design, construction, operation or maintenance of any nuclear facility. |
36 */ | 36 */ |
37 | 37 |
38 #include "testutil.h" | 38 #include "testutil.h" |
39 #include "testutil_nss.h" | 39 #include "testutil_nss.h" |
40 #include "pkix_pl_common.h" | 40 #include "pkix_pl_common.h" |
41 | 41 |
42 static void *plContext = NULL; | 42 static void *plContext = NULL; |
43 | 43 |
44 static | 44 static void printUsage(char *testname) { |
45 void printUsage(char *testname) | 45 char *fmt = "USAGE: %s [-arenas] certDir certName\n"; |
46 { | 46 printf(fmt, "test_httpcertstore"); |
47 char *fmt = | |
48 » » "USAGE: %s [-arenas] certDir certName\n"; | |
49 printf(fmt, "test_httpcertstore"); | |
50 } | 47 } |
51 | 48 |
52 /* Functional tests for Socket public functions */ | 49 /* Functional tests for Socket public functions */ |
53 static | 50 static void do_other_work(void) {/* while waiting for nonblocking I/O to |
54 void do_other_work(void) { /* while waiting for nonblocking I/O to complete */ | 51 complete */ |
55 (void) PR_Sleep(2*60); | 52 (void)PR_Sleep(2 * 60); |
56 } | 53 } |
57 | 54 |
58 PKIX_Error * | 55 PKIX_Error *PKIX_PL_HttpCertStore_Create( |
59 PKIX_PL_HttpCertStore_Create( | 56 PKIX_PL_HttpClient *client, /* if NULL, use default Client */ |
60 PKIX_PL_HttpClient *client, /* if NULL, use default Client */ | 57 PKIX_PL_GeneralName *location, PKIX_CertStore **pCertStore, |
61 PKIX_PL_GeneralName *location, | 58 void *plContext); |
62 PKIX_CertStore **pCertStore, | 59 |
63 void *plContext); | 60 PKIX_Error *pkix_pl_HttpCertStore_CreateWithAsciiName( |
64 | 61 PKIX_PL_HttpClient *client, /* if NULL, use default Client */ |
65 PKIX_Error * | 62 char *location, PKIX_CertStore **pCertStore, void *plContext); |
66 pkix_pl_HttpCertStore_CreateWithAsciiName( | 63 |
67 PKIX_PL_HttpClient *client, /* if NULL, use default Client */ | 64 static PKIX_Error *getLocation(PKIX_PL_Cert *certWithAia, |
68 char *location, | 65 PKIX_PL_GeneralName **pLocation, |
69 PKIX_CertStore **pCertStore, | 66 void *plContext) { |
70 void *plContext); | 67 PKIX_List *aiaList = NULL; |
71 | 68 PKIX_UInt32 size = 0; |
72 static PKIX_Error * | 69 PKIX_PL_InfoAccess *aia = NULL; |
73 getLocation( | 70 PKIX_UInt32 iaType = PKIX_INFOACCESS_LOCATION_UNKNOWN; |
74 » PKIX_PL_Cert *certWithAia, | 71 PKIX_PL_GeneralName *location = NULL; |
75 » PKIX_PL_GeneralName **pLocation, | 72 |
76 » void *plContext) | 73 PKIX_TEST_STD_VARS(); |
77 { | 74 |
78 » PKIX_List *aiaList = NULL; | 75 subTest("Getting Authority Info Access"); |
79 » PKIX_UInt32 size = 0; | 76 |
80 PKIX_PL_InfoAccess *aia = NULL; | 77 PKIX_TEST_EXPECT_NO_ERROR( |
81 PKIX_UInt32 iaType = PKIX_INFOACCESS_LOCATION_UNKNOWN; | 78 PKIX_PL_Cert_GetAuthorityInfoAccess(certWithAia, &aiaList, plContext)); |
82 » PKIX_PL_GeneralName *location = NULL; | 79 |
83 | 80 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength(aiaList, &size, plContext)); |
84 PKIX_TEST_STD_VARS(); | 81 |
85 | 82 if (size != 1) { |
86 subTest("Getting Authority Info Access"); | 83 pkixTestErrorMsg = "unexpected number of AIA"; |
87 | 84 goto cleanup; |
88 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetAuthorityInfoAccess | 85 } |
89 (certWithAia, &aiaList, plContext)); | 86 |
90 | 87 PKIX_TEST_EXPECT_NO_ERROR( |
91 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength | 88 PKIX_List_GetItem(aiaList, 0, (PKIX_PL_Object **)&aia, plContext)); |
92 (aiaList, &size, plContext)); | 89 |
93 | 90 PKIX_TEST_EXPECT_NO_ERROR( |
94 if (size != 1) { | 91 PKIX_PL_InfoAccess_GetLocationType(aia, &iaType, plContext)); |
95 pkixTestErrorMsg = "unexpected number of AIA"; | 92 |
96 goto cleanup; | 93 if (iaType != PKIX_INFOACCESS_LOCATION_HTTP) { |
97 } | 94 pkixTestErrorMsg = "unexpected location type in AIA"; |
98 | 95 goto cleanup; |
99 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem | 96 } |
100 (aiaList, 0, (PKIX_PL_Object **) &aia, plContext)); | 97 |
101 | 98 PKIX_TEST_EXPECT_NO_ERROR( |
102 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetLocationType | 99 PKIX_PL_InfoAccess_GetLocation(aia, &location, plContext)); |
103 (aia, &iaType, plContext)); | 100 |
104 | 101 *pLocation = location; |
105 if (iaType != PKIX_INFOACCESS_LOCATION_HTTP) { | |
106 pkixTestErrorMsg = "unexpected location type in AIA"; | |
107 goto cleanup; | |
108 | |
109 » } | |
110 | |
111 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetLocation | |
112 (aia, &location, plContext)); | |
113 | |
114 » *pLocation = location; | |
115 | 102 |
116 cleanup: | 103 cleanup: |
117 PKIX_TEST_DECREF_AC(aiaList); | 104 PKIX_TEST_DECREF_AC(aiaList); |
118 PKIX_TEST_DECREF_AC(aia); | 105 PKIX_TEST_DECREF_AC(aia); |
119 | 106 |
120 PKIX_TEST_RETURN(); | 107 PKIX_TEST_RETURN(); |
121 | 108 |
122 return (NULL); | 109 return (NULL); |
123 } | 110 } |
124 | 111 |
125 int test_httpcertstore(int argc, char *argv[])· | 112 int test_httpcertstore(int argc, char *argv[]) { |
126 { | 113 |
127 | 114 PKIX_UInt32 i = 0; |
128 PKIX_UInt32 i = 0; | 115 PKIX_UInt32 numCerts = 0; |
129 PKIX_UInt32 numCerts = 0; | 116 PKIX_UInt32 numCrls = 0; |
130 PKIX_UInt32 numCrls = 0; | 117 int j = 0; |
131 int j = 0; | 118 PKIX_UInt32 actualMinorVersion; |
132 PKIX_UInt32 actualMinorVersion; | 119 PKIX_UInt32 length = 0; |
133 PKIX_UInt32 length = 0; | 120 |
134 | 121 char *certName = NULL; |
135 char *certName = NULL; | 122 char *certDir = NULL; |
136 char *certDir = NULL; | 123 PKIX_PL_Cert *cmdLineCert = NULL; |
137 PKIX_PL_Cert *cmdLineCert = NULL; | 124 PKIX_PL_Cert *cert = NULL; |
138 PKIX_PL_Cert *cert = NULL; | 125 PKIX_CertSelector *certSelector = NULL; |
139 PKIX_CertSelector *certSelector = NULL; | 126 PKIX_CertStore *certStore = NULL; |
140 PKIX_CertStore *certStore = NULL; | 127 PKIX_CertStore *crlStore = NULL; |
141 PKIX_CertStore *crlStore = NULL; | 128 PKIX_PL_GeneralName *location = NULL; |
142 PKIX_PL_GeneralName *location = NULL; | 129 PKIX_CertStore_CertCallback getCerts = NULL; |
143 PKIX_CertStore_CertCallback getCerts = NULL; | 130 PKIX_List *certs = NULL; |
144 PKIX_List *certs = NULL; | 131 char *asciiResult = NULL; |
145 char *asciiResult = NULL; | 132 void *nbio = NULL; |
146 void *nbio = NULL; | 133 |
147 | 134 PKIX_PL_CRL *crl = NULL; |
148 PKIX_PL_CRL *crl = NULL; | 135 PKIX_CRLSelector *crlSelector = NULL; |
149 PKIX_CRLSelector *crlSelector = NULL; | 136 char *crlLocation = |
150 char *crlLocation = "http://betty.nist.gov/pathdiscoverytestsuite/CRL" | 137 "http://betty.nist.gov/pathdiscoverytestsuite/CRL" |
151 "files/BasicHTTPURIPeer2CACRL.crl"; | 138 "files/BasicHTTPURIPeer2CACRL.crl"; |
152 PKIX_CertStore_CRLCallback getCrls = NULL; | 139 PKIX_CertStore_CRLCallback getCrls = NULL; |
153 PKIX_List *crls = NULL; | 140 PKIX_List *crls = NULL; |
154 PKIX_PL_String *crlString = NULL; | 141 PKIX_PL_String *crlString = NULL; |
155 | 142 |
156 PKIX_TEST_STD_VARS(); | 143 PKIX_TEST_STD_VARS(); |
157 | 144 |
158 startTests("HttpCertStore"); | 145 startTests("HttpCertStore"); |
159 | 146 |
160 PKIX_TEST_EXPECT_NO_ERROR( | 147 PKIX_TEST_EXPECT_NO_ERROR( |
161 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); | 148 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); |
162 | 149 |
163 if (argc != (j + 3)) { | 150 if (argc != (j + 3)) { |
164 printUsage(argv[0]); | 151 printUsage(argv[0]); |
165 pkixTestErrorMsg = "Missing command line argument."; | 152 pkixTestErrorMsg = "Missing command line argument."; |
166 goto cleanup; | 153 goto cleanup; |
167 } | 154 } |
168 | 155 |
169 certDir = argv[++j]; | 156 certDir = argv[++j]; |
170 certName = argv[++j]; | 157 certName = argv[++j]; |
171 | 158 |
172 cmdLineCert = createCert(certDir, certName, plContext); | 159 cmdLineCert = createCert(certDir, certName, plContext); |
173 if (cmdLineCert == NULL) { | 160 if (cmdLineCert == NULL) { |
174 pkixTestErrorMsg = "Unable to create Cert"; | 161 pkixTestErrorMsg = "Unable to create Cert"; |
175 goto cleanup; | 162 goto cleanup; |
176 } | 163 } |
177 | 164 |
178 /* muster arguments to create HttpCertStore */ | 165 /* muster arguments to create HttpCertStore */ |
179 PKIX_TEST_EXPECT_NO_ERROR(getLocation | 166 PKIX_TEST_EXPECT_NO_ERROR(getLocation(cmdLineCert, &location, plContext)); |
180 (cmdLineCert, &location, plContext)); | 167 |
181 | 168 if (location == NULL) { |
182 if (location == NULL) { | 169 pkixTestErrorMsg = "Give me a cert with an HTTP URI!"; |
183 pkixTestErrorMsg = "Give me a cert with an HTTP URI!"; | 170 goto cleanup; |
184 goto cleanup; | 171 } |
185 } | 172 |
186 | 173 /* create HttpCertStore */ |
187 /* create HttpCertStore */ | 174 PKIX_TEST_EXPECT_NO_ERROR( |
188 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HttpCertStore_Create | 175 PKIX_PL_HttpCertStore_Create(NULL, location, &certStore, plContext)); |
189 (NULL, location, &certStore, plContext)); | 176 |
190 | 177 /* get the GetCerts callback */ |
191 /* get the GetCerts callback */ | 178 PKIX_TEST_EXPECT_NO_ERROR( |
192 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCertCallback | 179 PKIX_CertStore_GetCertCallback(certStore, &getCerts, plContext)); |
193 (certStore, &getCerts, plContext)); | 180 |
194 | 181 /* create a CertSelector */ |
195 /* create a CertSelector */ | 182 PKIX_TEST_EXPECT_NO_ERROR( |
196 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertSelector_Create | 183 PKIX_CertSelector_Create(NULL, NULL, &certSelector, plContext)); |
197 (NULL, NULL, &certSelector, plContext)); | 184 |
198 | 185 /* Get the certs */ |
199 /* Get the certs */ | 186 PKIX_TEST_EXPECT_NO_ERROR( |
200 PKIX_TEST_EXPECT_NO_ERROR(getCerts | 187 getCerts(certStore, certSelector, &nbio, &certs, plContext)); |
201 (certStore, certSelector, &nbio, &certs, plContext)); | 188 |
202 | 189 while (nbio != NULL) { |
203 while (nbio != NULL) { | 190 /* poll for a completion */ |
204 /* poll for a completion */ | 191 |
205 | 192 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CertContinue( |
206 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CertContinue | 193 certStore, certSelector, &nbio, &certs, plContext)); |
207 (certStore, certSelector, &nbio, &certs, plContext)); | 194 } |
208 } | 195 |
209 | 196 if (certs) { |
210 if (certs) { | 197 |
211 | 198 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength(certs, &numCerts, plContext)); |
212 PKIX_TEST_EXPECT_NO_ERROR | 199 |
213 (PKIX_List_GetLength(certs, &numCerts, plContext)); | 200 if (numCerts == 0) { |
214 | 201 printf("HttpCertStore returned an empty Cert list\n"); |
215 if (numCerts == 0) { | 202 goto cleanup; |
216 printf("HttpCertStore returned an empty Cert list\n"); | 203 } |
217 goto cleanup; | 204 |
218 } | 205 for (i = 0; i < numCerts; i++) { |
219 | 206 PKIX_TEST_EXPECT_NO_ERROR( |
220 for (i = 0; i < numCerts; i++) { | 207 PKIX_List_GetItem(certs, i, (PKIX_PL_Object **)&cert, plContext)); |
221 PKIX_TEST_EXPECT_NO_ERROR | 208 |
222 (PKIX_List_GetItem | 209 asciiResult = PKIX_Cert2ASCII(cert); |
223 (certs, | 210 |
224 i, | 211 printf("CERT[%d]:\n%s\n", i, asciiResult); |
225 (PKIX_PL_Object**)&cert, | 212 |
226 plContext)); | 213 /* PKIX_Cert2ASCII used PKIX_PL_Malloc(...,,NULL) */ |
227 | 214 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(asciiResult, NULL)); |
228 asciiResult = PKIX_Cert2ASCII(cert); | 215 asciiResult = NULL; |
229 | 216 |
230 printf("CERT[%d]:\n%s\n", i, asciiResult); | 217 PKIX_TEST_DECREF_BC(cert); |
231 | 218 } |
232 /* PKIX_Cert2ASCII used PKIX_PL_Malloc(...,,NULL) */ | 219 } else { |
233 PKIX_TEST_EXPECT_NO_ERROR | 220 printf("HttpCertStore returned a NULL Cert list\n"); |
234 (PKIX_PL_Free(asciiResult, NULL)); | 221 } |
235 asciiResult = NULL; | 222 |
236 | 223 /* create HttpCertStore */ |
237 PKIX_TEST_DECREF_BC(cert); | 224 PKIX_TEST_EXPECT_NO_ERROR(pkix_pl_HttpCertStore_CreateWithAsciiName( |
238 } | 225 NULL, crlLocation, &crlStore, plContext)); |
239 } else { | 226 |
240 printf("HttpCertStore returned a NULL Cert list\n"); | 227 /* get the GetCrls callback */ |
241 } | 228 PKIX_TEST_EXPECT_NO_ERROR( |
242 | 229 PKIX_CertStore_GetCRLCallback(crlStore, &getCrls, plContext)); |
243 /* create HttpCertStore */ | 230 |
244 PKIX_TEST_EXPECT_NO_ERROR(pkix_pl_HttpCertStore_CreateWithAsciiName | 231 /* create a CrlSelector */ |
245 (NULL, crlLocation, &crlStore, plContext)); | 232 PKIX_TEST_EXPECT_NO_ERROR( |
246 | 233 PKIX_CRLSelector_Create(NULL, NULL, &crlSelector, plContext)); |
247 /* get the GetCrls callback */ | 234 |
248 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCRLCallback | 235 /* Get the crls */ |
249 (crlStore, &getCrls, plContext)); | 236 PKIX_TEST_EXPECT_NO_ERROR( |
250 | 237 getCrls(crlStore, crlSelector, &nbio, &crls, plContext)); |
251 /* create a CrlSelector */ | 238 |
252 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_Create | 239 while (nbio != NULL) { |
253 (NULL, NULL, &crlSelector, plContext)); | 240 /* poll for a completion */ |
254 | 241 |
255 /* Get the crls */ | 242 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CrlContinue( |
256 PKIX_TEST_EXPECT_NO_ERROR(getCrls | 243 crlStore, crlSelector, &nbio, &crls, plContext)); |
257 (crlStore, crlSelector, &nbio, &crls, plContext)); | 244 } |
258 | 245 |
259 while (nbio != NULL) { | 246 if (crls) { |
260 /* poll for a completion */ | 247 |
261 | 248 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength(crls, &numCrls, plContext)); |
262 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CrlContinue | 249 |
263 (crlStore, crlSelector, &nbio, &crls, plContext)); | 250 if (numCrls == 0) { |
264 } | 251 printf("HttpCertStore returned an empty CRL list\n"); |
265 | 252 goto cleanup; |
266 if (crls) { | 253 } |
267 | 254 |
268 PKIX_TEST_EXPECT_NO_ERROR | 255 for (i = 0; i < numCrls; i++) { |
269 (PKIX_List_GetLength(crls, &numCrls, plContext)); | 256 PKIX_TEST_EXPECT_NO_ERROR( |
270 | 257 PKIX_List_GetItem(crls, i, (PKIX_PL_Object **)&crl, plContext)); |
271 if (numCrls == 0) { | 258 |
272 printf("HttpCertStore returned an empty CRL list\n"); | 259 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString((PKIX_PL_Object *)crl, |
273 goto cleanup; | 260 &crlString, plContext)); |
274 } | 261 |
275 | 262 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded( |
276 for (i = 0; i < numCrls; i++) { | 263 crlString, PKIX_ESCASCII, (void **)&asciiResult, &length, plContext)); |
277 PKIX_TEST_EXPECT_NO_ERROR | 264 |
278 (PKIX_List_GetItem | 265 printf("CRL[%d]:\n%s\n", i, asciiResult); |
279 (crls, | 266 |
280 i, | 267 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(asciiResult, plContext)); |
281 (PKIX_PL_Object**)&crl, | 268 PKIX_TEST_DECREF_BC(crlString); |
282 plContext)); | 269 PKIX_TEST_DECREF_BC(crl); |
283 | 270 } |
284 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString( | 271 } else { |
285 (PKIX_PL_Object *)crl, | 272 printf("HttpCertStore returned a NULL CRL list\n"); |
286 &crlString, | 273 } |
287 plContext)); | |
288 | |
289 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded | |
290 (crlString, | |
291 PKIX_ESCASCII, | |
292 (void **)&asciiResult, | |
293 &length, | |
294 plContext)); | |
295 | |
296 printf("CRL[%d]:\n%s\n", i, asciiResult); | |
297 | |
298 PKIX_TEST_EXPECT_NO_ERROR | |
299 (PKIX_PL_Free(asciiResult, plContext)); | |
300 PKIX_TEST_DECREF_BC(crlString); | |
301 PKIX_TEST_DECREF_BC(crl); | |
302 } | |
303 } else { | |
304 printf("HttpCertStore returned a NULL CRL list\n"); | |
305 } | |
306 | 274 |
307 cleanup: | 275 cleanup: |
308 | 276 |
309 PKIX_TEST_DECREF_AC(cert); | 277 PKIX_TEST_DECREF_AC(cert); |
310 » PKIX_TEST_DECREF_AC(cmdLineCert); | 278 PKIX_TEST_DECREF_AC(cmdLineCert); |
311 » PKIX_TEST_DECREF_AC(certStore); | 279 PKIX_TEST_DECREF_AC(certStore); |
312 » PKIX_TEST_DECREF_AC(crlStore); | 280 PKIX_TEST_DECREF_AC(crlStore); |
313 » PKIX_TEST_DECREF_AC(location); | 281 PKIX_TEST_DECREF_AC(location); |
314 » PKIX_TEST_DECREF_AC(certs); | 282 PKIX_TEST_DECREF_AC(certs); |
315 PKIX_TEST_DECREF_AC(crl); | 283 PKIX_TEST_DECREF_AC(crl); |
316 PKIX_TEST_DECREF_AC(crlString); | 284 PKIX_TEST_DECREF_AC(crlString); |
317 » PKIX_TEST_DECREF_AC(crls); | 285 PKIX_TEST_DECREF_AC(crls); |
318 | 286 |
319 PKIX_TEST_RETURN(); | 287 PKIX_TEST_RETURN(); |
320 | 288 |
321 endTests("HttpDefaultClient"); | 289 endTests("HttpDefaultClient"); |
322 | 290 |
323 return (0); | 291 return (0); |
324 } | 292 } |
OLD | NEW |