4 * Test Httpcertstore Type
6 * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistribution of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * 2. Redistribution in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
19 * be used to endorse or promote products derived from this software without
20 * specific prior written permission.
22 * This software is provided "AS IS," without a warranty of any kind. ALL
23 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
24 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
25 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
26 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
27 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
28 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
29 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
30 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
31 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
32 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
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.
39 #include "testutil_nss.h"
40 #include "pkix_pl_common.h"
42 void *plContext
= NULL
;
44 void printUsage(char *testname
) {
46 "USAGE: %s [-arenas] certDir certName\n";
47 printf(fmt
, "test_httpcertstore");
50 /* Functional tests for Socket public functions */
51 void do_other_work(void) { /* while waiting for nonblocking I/O to complete */
52 (void) PR_Sleep(2*60);
56 PKIX_PL_HttpCertStore_Create(
57 PKIX_PL_HttpClient
*client
, /* if NULL, use default Client */
58 PKIX_PL_GeneralName
*location
,
59 PKIX_CertStore
**pCertStore
,
63 pkix_pl_HttpCertStore_CreateWithAsciiName(
64 PKIX_PL_HttpClient
*client
, /* if NULL, use default Client */
66 PKIX_CertStore
**pCertStore
,
71 PKIX_PL_Cert
*certWithAia
,
72 PKIX_PL_GeneralName
**pLocation
,
75 PKIX_List
*aiaList
= NULL
;
77 PKIX_PL_InfoAccess
*aia
= NULL
;
78 PKIX_UInt32 iaType
= PKIX_INFOACCESS_LOCATION_UNKNOWN
;
79 PKIX_PL_GeneralName
*location
= NULL
;
83 subTest("Getting Authority Info Access");
85 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetAuthorityInfoAccess
86 (certWithAia
, &aiaList
, plContext
));
88 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
89 (aiaList
, &size
, plContext
));
92 pkixTestErrorMsg
= "unexpected number of AIA";
96 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem
97 (aiaList
, 0, (PKIX_PL_Object
**) &aia
, plContext
));
99 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetLocationType
100 (aia
, &iaType
, plContext
));
102 if (iaType
!= PKIX_INFOACCESS_LOCATION_HTTP
) {
103 pkixTestErrorMsg
= "unexpected location type in AIA";
108 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetLocation
109 (aia
, &location
, plContext
));
111 *pLocation
= location
;
114 PKIX_TEST_DECREF_AC(aiaList
);
115 PKIX_TEST_DECREF_AC(aia
);
122 int main(int argc
, char *argv
[]) {
125 PKIX_UInt32 numCerts
= 0;
126 PKIX_UInt32 numCrls
= 0;
128 PKIX_Boolean useArenas
= PKIX_FALSE
;
129 PKIX_UInt32 actualMinorVersion
;
130 PKIX_UInt32 length
= 0;
132 char *certName
= NULL
;
133 char *certDir
= NULL
;
134 PKIX_PL_Cert
*cmdLineCert
= NULL
;
135 PKIX_PL_Cert
*cert
= NULL
;
136 PKIX_CertSelector
*certSelector
= NULL
;
137 PKIX_CertStore
*certStore
= NULL
;
138 PKIX_CertStore
*crlStore
= NULL
;
139 PKIX_PL_GeneralName
*location
= NULL
;
140 PKIX_CertStore_CertCallback getCerts
= NULL
;
141 PKIX_List
*certs
= NULL
;
142 char *asciiResult
= NULL
;
145 PKIX_PL_CRL
*crl
= NULL
;
146 PKIX_CRLSelector
*crlSelector
= NULL
;
147 char *crlLocation
= "http://betty.nist.gov/pathdiscoverytestsuite/CRL"
148 "files/BasicHTTPURIPeer2CACRL.crl";
149 PKIX_CertStore_CRLCallback getCrls
= NULL
;
150 PKIX_List
*crls
= NULL
;
151 PKIX_PL_String
*crlString
= NULL
;
153 PKIX_TEST_STD_VARS();
155 startTests("HttpCertStore");
157 useArenas
= PKIX_TEST_ARENAS_ARG(argv
[1]);
159 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
160 (PKIX_TRUE
, /* nssInitNeeded */
168 if (argc
!= (j
+ 3)) {
170 pkixTestErrorMsg
= "Missing command line argument.";
175 certName
= argv
[++j
];
177 cmdLineCert
= createCert(certDir
, certName
, plContext
);
178 if (cmdLineCert
== NULL
) {
179 pkixTestErrorMsg
= "Unable to create Cert";
183 /* muster arguments to create HttpCertStore */
184 PKIX_TEST_EXPECT_NO_ERROR(getLocation
185 (cmdLineCert
, &location
, plContext
));
187 if (location
== NULL
) {
188 pkixTestErrorMsg
= "Give me a cert with an HTTP URI!";
192 /* create HttpCertStore */
193 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HttpCertStore_Create
194 (NULL
, location
, &certStore
, plContext
));
196 /* get the GetCerts callback */
197 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCertCallback
198 (certStore
, &getCerts
, plContext
));
200 /* create a CertSelector */
201 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertSelector_Create
202 (NULL
, NULL
, &certSelector
, plContext
));
205 PKIX_TEST_EXPECT_NO_ERROR(getCerts
206 (certStore
, certSelector
, &nbio
, &certs
, plContext
));
208 while (nbio
!= NULL
) {
209 /* poll for a completion */
211 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CertContinue
212 (certStore
, certSelector
, &nbio
, &certs
, plContext
));
217 PKIX_TEST_EXPECT_NO_ERROR
218 (PKIX_List_GetLength(certs
, &numCerts
, plContext
));
221 printf("HttpCertStore returned an empty Cert list\n");
225 for (i
= 0; i
< numCerts
; i
++) {
226 PKIX_TEST_EXPECT_NO_ERROR
230 (PKIX_PL_Object
**)&cert
,
233 asciiResult
= PKIX_Cert2ASCII(cert
);
235 printf("CERT[%d]:\n%s\n", i
, asciiResult
);
237 /* PKIX_Cert2ASCII used PKIX_PL_Malloc(...,,NULL) */
238 PKIX_TEST_EXPECT_NO_ERROR
239 (PKIX_PL_Free(asciiResult
, NULL
));
242 PKIX_TEST_DECREF_BC(cert
);
245 printf("HttpCertStore returned a NULL Cert list\n");
248 /* create HttpCertStore */
249 PKIX_TEST_EXPECT_NO_ERROR(pkix_pl_HttpCertStore_CreateWithAsciiName
250 (NULL
, crlLocation
, &crlStore
, plContext
));
252 /* get the GetCrls callback */
253 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCRLCallback
254 (crlStore
, &getCrls
, plContext
));
256 /* create a CrlSelector */
257 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_Create
258 (NULL
, NULL
, &crlSelector
, plContext
));
261 PKIX_TEST_EXPECT_NO_ERROR(getCrls
262 (crlStore
, crlSelector
, &nbio
, &crls
, plContext
));
264 while (nbio
!= NULL
) {
265 /* poll for a completion */
267 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CrlContinue
268 (crlStore
, crlSelector
, &nbio
, &crls
, plContext
));
273 PKIX_TEST_EXPECT_NO_ERROR
274 (PKIX_List_GetLength(crls
, &numCrls
, plContext
));
277 printf("HttpCertStore returned an empty CRL list\n");
281 for (i
= 0; i
< numCrls
; i
++) {
282 PKIX_TEST_EXPECT_NO_ERROR
286 (PKIX_PL_Object
**)&crl
,
289 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString(
290 (PKIX_PL_Object
*)crl
,
294 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded
297 (void **)&asciiResult
,
301 printf("CRL[%d]:\n%s\n", i
, asciiResult
);
303 PKIX_TEST_EXPECT_NO_ERROR
304 (PKIX_PL_Free(asciiResult
, plContext
));
305 PKIX_TEST_DECREF_BC(crlString
);
306 PKIX_TEST_DECREF_BC(crl
);
309 printf("HttpCertStore returned a NULL CRL list\n");
314 PKIX_TEST_DECREF_AC(cert
);
315 PKIX_TEST_DECREF_AC(cmdLineCert
);
316 PKIX_TEST_DECREF_AC(certStore
);
317 PKIX_TEST_DECREF_AC(crlStore
);
318 PKIX_TEST_DECREF_AC(location
);
319 PKIX_TEST_DECREF_AC(certs
);
320 PKIX_TEST_DECREF_AC(crl
);
321 PKIX_TEST_DECREF_AC(crlString
);
322 PKIX_TEST_DECREF_AC(crls
);
326 endTests("HttpDefaultClient");