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 static void *plContext
= NULL
;
45 void printUsage(char *testname
)
48 "USAGE: %s [-arenas] certDir certName\n";
49 printf(fmt
, "test_httpcertstore");
52 /* Functional tests for Socket public functions */
54 void do_other_work(void) { /* while waiting for nonblocking I/O to complete */
55 (void) PR_Sleep(2*60);
59 PKIX_PL_HttpCertStore_Create(
60 PKIX_PL_HttpClient
*client
, /* if NULL, use default Client */
61 PKIX_PL_GeneralName
*location
,
62 PKIX_CertStore
**pCertStore
,
66 pkix_pl_HttpCertStore_CreateWithAsciiName(
67 PKIX_PL_HttpClient
*client
, /* if NULL, use default Client */
69 PKIX_CertStore
**pCertStore
,
74 PKIX_PL_Cert
*certWithAia
,
75 PKIX_PL_GeneralName
**pLocation
,
78 PKIX_List
*aiaList
= NULL
;
80 PKIX_PL_InfoAccess
*aia
= NULL
;
81 PKIX_UInt32 iaType
= PKIX_INFOACCESS_LOCATION_UNKNOWN
;
82 PKIX_PL_GeneralName
*location
= NULL
;
86 subTest("Getting Authority Info Access");
88 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetAuthorityInfoAccess
89 (certWithAia
, &aiaList
, plContext
));
91 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
92 (aiaList
, &size
, plContext
));
95 pkixTestErrorMsg
= "unexpected number of AIA";
99 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem
100 (aiaList
, 0, (PKIX_PL_Object
**) &aia
, plContext
));
102 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetLocationType
103 (aia
, &iaType
, plContext
));
105 if (iaType
!= PKIX_INFOACCESS_LOCATION_HTTP
) {
106 pkixTestErrorMsg
= "unexpected location type in AIA";
111 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetLocation
112 (aia
, &location
, plContext
));
114 *pLocation
= location
;
117 PKIX_TEST_DECREF_AC(aiaList
);
118 PKIX_TEST_DECREF_AC(aia
);
125 int test_httpcertstore(int argc
, char *argv
[])
129 PKIX_UInt32 numCerts
= 0;
130 PKIX_UInt32 numCrls
= 0;
132 PKIX_UInt32 actualMinorVersion
;
133 PKIX_UInt32 length
= 0;
135 char *certName
= NULL
;
136 char *certDir
= NULL
;
137 PKIX_PL_Cert
*cmdLineCert
= NULL
;
138 PKIX_PL_Cert
*cert
= NULL
;
139 PKIX_CertSelector
*certSelector
= NULL
;
140 PKIX_CertStore
*certStore
= NULL
;
141 PKIX_CertStore
*crlStore
= NULL
;
142 PKIX_PL_GeneralName
*location
= NULL
;
143 PKIX_CertStore_CertCallback getCerts
= NULL
;
144 PKIX_List
*certs
= NULL
;
145 char *asciiResult
= NULL
;
148 PKIX_PL_CRL
*crl
= NULL
;
149 PKIX_CRLSelector
*crlSelector
= NULL
;
150 char *crlLocation
= "http://betty.nist.gov/pathdiscoverytestsuite/CRL"
151 "files/BasicHTTPURIPeer2CACRL.crl";
152 PKIX_CertStore_CRLCallback getCrls
= NULL
;
153 PKIX_List
*crls
= NULL
;
154 PKIX_PL_String
*crlString
= NULL
;
156 PKIX_TEST_STD_VARS();
158 startTests("HttpCertStore");
160 PKIX_TEST_EXPECT_NO_ERROR(
161 PKIX_PL_NssContext_Create(0, PKIX_FALSE
, NULL
, &plContext
));
163 if (argc
!= (j
+ 3)) {
165 pkixTestErrorMsg
= "Missing command line argument.";
170 certName
= argv
[++j
];
172 cmdLineCert
= createCert(certDir
, certName
, plContext
);
173 if (cmdLineCert
== NULL
) {
174 pkixTestErrorMsg
= "Unable to create Cert";
178 /* muster arguments to create HttpCertStore */
179 PKIX_TEST_EXPECT_NO_ERROR(getLocation
180 (cmdLineCert
, &location
, plContext
));
182 if (location
== NULL
) {
183 pkixTestErrorMsg
= "Give me a cert with an HTTP URI!";
187 /* create HttpCertStore */
188 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HttpCertStore_Create
189 (NULL
, location
, &certStore
, plContext
));
191 /* get the GetCerts callback */
192 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCertCallback
193 (certStore
, &getCerts
, plContext
));
195 /* create a CertSelector */
196 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertSelector_Create
197 (NULL
, NULL
, &certSelector
, plContext
));
200 PKIX_TEST_EXPECT_NO_ERROR(getCerts
201 (certStore
, certSelector
, &nbio
, &certs
, plContext
));
203 while (nbio
!= NULL
) {
204 /* poll for a completion */
206 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CertContinue
207 (certStore
, certSelector
, &nbio
, &certs
, plContext
));
212 PKIX_TEST_EXPECT_NO_ERROR
213 (PKIX_List_GetLength(certs
, &numCerts
, plContext
));
216 printf("HttpCertStore returned an empty Cert list\n");
220 for (i
= 0; i
< numCerts
; i
++) {
221 PKIX_TEST_EXPECT_NO_ERROR
225 (PKIX_PL_Object
**)&cert
,
228 asciiResult
= PKIX_Cert2ASCII(cert
);
230 printf("CERT[%d]:\n%s\n", i
, asciiResult
);
232 /* PKIX_Cert2ASCII used PKIX_PL_Malloc(...,,NULL) */
233 PKIX_TEST_EXPECT_NO_ERROR
234 (PKIX_PL_Free(asciiResult
, NULL
));
237 PKIX_TEST_DECREF_BC(cert
);
240 printf("HttpCertStore returned a NULL Cert list\n");
243 /* create HttpCertStore */
244 PKIX_TEST_EXPECT_NO_ERROR(pkix_pl_HttpCertStore_CreateWithAsciiName
245 (NULL
, crlLocation
, &crlStore
, plContext
));
247 /* get the GetCrls callback */
248 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCRLCallback
249 (crlStore
, &getCrls
, plContext
));
251 /* create a CrlSelector */
252 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_Create
253 (NULL
, NULL
, &crlSelector
, plContext
));
256 PKIX_TEST_EXPECT_NO_ERROR(getCrls
257 (crlStore
, crlSelector
, &nbio
, &crls
, plContext
));
259 while (nbio
!= NULL
) {
260 /* poll for a completion */
262 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_CrlContinue
263 (crlStore
, crlSelector
, &nbio
, &crls
, plContext
));
268 PKIX_TEST_EXPECT_NO_ERROR
269 (PKIX_List_GetLength(crls
, &numCrls
, plContext
));
272 printf("HttpCertStore returned an empty CRL list\n");
276 for (i
= 0; i
< numCrls
; i
++) {
277 PKIX_TEST_EXPECT_NO_ERROR
281 (PKIX_PL_Object
**)&crl
,
284 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString(
285 (PKIX_PL_Object
*)crl
,
289 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded
292 (void **)&asciiResult
,
296 printf("CRL[%d]:\n%s\n", i
, asciiResult
);
298 PKIX_TEST_EXPECT_NO_ERROR
299 (PKIX_PL_Free(asciiResult
, plContext
));
300 PKIX_TEST_DECREF_BC(crlString
);
301 PKIX_TEST_DECREF_BC(crl
);
304 printf("HttpCertStore returned a NULL CRL list\n");
309 PKIX_TEST_DECREF_AC(cert
);
310 PKIX_TEST_DECREF_AC(cmdLineCert
);
311 PKIX_TEST_DECREF_AC(certStore
);
312 PKIX_TEST_DECREF_AC(crlStore
);
313 PKIX_TEST_DECREF_AC(location
);
314 PKIX_TEST_DECREF_AC(certs
);
315 PKIX_TEST_DECREF_AC(crl
);
316 PKIX_TEST_DECREF_AC(crlString
);
317 PKIX_TEST_DECREF_AC(crls
);
321 endTests("HttpDefaultClient");