Imported Upstream version 3.13.6
[platform/upstream/nss.git] / mozilla / security / nss / cmd / libpkix / pkix_pl / pki / test_authorityinfoaccess.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_authorityinfoaccess.c
39  *
40  * Test Authority InfoAccess Type
41  *
42  */
43
44
45
46 #include "testutil.h"
47 #include "testutil_nss.h"
48
49 static void *plContext = NULL;
50
51 int test_authorityinfoaccess(int argc, char *argv[]) {
52
53         PKIX_PL_Cert *cert = NULL;
54         PKIX_PL_Cert *certDiff = NULL;
55         PKIX_List *aiaList = NULL;
56         PKIX_List *siaList = NULL;
57         PKIX_PL_InfoAccess *aia = NULL;
58         PKIX_PL_InfoAccess *aiaDup = NULL;
59         PKIX_PL_InfoAccess *aiaDiff = NULL;
60         char *certPathName = NULL;
61         char *dirName = NULL;
62         PKIX_UInt32 actualMinorVersion;
63         PKIX_UInt32 size, i;
64         PKIX_UInt32 j = 0;
65         char *expectedAscii = "[method:caIssuers, location:ldap:"
66                 "//betty.nist.gov/cn=CA,ou=Basic%20LDAP%20URI%20OU1,"
67                 "o=Test%20Certificates,c=US?cACertificate;binary,"
68                 "crossCertificatePair;binary]";
69
70         PKIX_TEST_STD_VARS();
71
72         startTests("AuthorityInfoAccess");
73
74         PKIX_TEST_EXPECT_NO_ERROR(
75             PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
76
77         if (argc < 5+j) {
78                 printf("Usage: %s <test-purpose> <cert> <diff-cert>\n", argv[0]);
79         }
80
81         dirName = argv[2+j];
82         certPathName = argv[3+j];
83
84         subTest("Creating Cert with Authority Info Access");
85         cert = createCert(dirName, certPathName, plContext);
86
87         certPathName = argv[4+j];
88
89         subTest("Creating Cert with Subject Info Access");
90         certDiff = createCert(dirName, certPathName, plContext);
91
92         subTest("Getting Authority Info Access");
93         PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetAuthorityInfoAccess
94                 (cert, &aiaList, plContext));
95
96         PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
97                 (aiaList, &size, plContext));
98
99         if (size != 1) {
100                 pkixTestErrorMsg = "unexpected number of AIA";
101                 goto cleanup;
102         }
103  
104         PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem
105                 (aiaList, 0, (PKIX_PL_Object **) &aia, plContext));
106
107         PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem
108                 (aiaList, 0, (PKIX_PL_Object **) &aiaDup, plContext));
109
110         subTest("Getting Subject Info Access as difference comparison");
111         PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubjectInfoAccess
112                 (certDiff, &siaList, plContext));
113
114         PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
115                 (siaList, &size, plContext));
116
117         if (size != 1) {
118                 pkixTestErrorMsg = "unexpected number of AIA";
119                 goto cleanup;
120         }
121  
122         PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem
123                 (siaList, 0, (PKIX_PL_Object **) &aiaDiff, plContext));
124
125         subTest("Checking: Equal, Hash and ToString");
126         PKIX_TEST_EQ_HASH_TOSTR_DUP
127                 (aia, aiaDup, aiaDiff, expectedAscii, InfoAccess, PKIX_FALSE);
128
129
130
131 cleanup:
132
133         PKIX_TEST_DECREF_AC(aia);
134         PKIX_TEST_DECREF_AC(aiaDup);
135         PKIX_TEST_DECREF_AC(aiaDiff);
136         PKIX_TEST_DECREF_AC(aiaList);
137         PKIX_TEST_DECREF_AC(siaList);
138         PKIX_TEST_DECREF_AC(cert);
139         PKIX_TEST_DECREF_AC(certDiff);
140      
141         PKIX_Shutdown(plContext);
142
143         PKIX_TEST_RETURN();
144
145         endTests("Authorityinfoaccess");
146
147         return (0);
148 }