1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
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.
36 * ***** END LICENSE BLOCK ***** */
45 #include "testutil_nss.h"
47 void *plContext
= NULL
;
49 void createCRLEntries(
53 PKIX_PL_CRLEntry
**goodObject
,
54 PKIX_PL_CRLEntry
**equalObject
,
55 PKIX_PL_CRLEntry
**diffObject
)
57 PKIX_PL_CRL
*crl
= NULL
;
58 PKIX_PL_BigInt
*firstSNBigInt
= NULL
;
59 PKIX_PL_BigInt
*secondSNBigInt
= NULL
;
60 PKIX_PL_String
*firstSNString
= NULL
;
61 PKIX_PL_String
*secondSNString
= NULL
;
62 char *firstSNAscii
= "010932";
63 char *secondSNAscii
= "3039";
67 subTest("PKIX_PL_CRL_Create <crl>");
68 crl
= createCRL(dataDir
, crlInput
, plContext
);
70 subTest("PKIX_PL_CRL_GetCRLEntryForSerialNumber");
71 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
74 PL_strlen(firstSNAscii
),
78 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
83 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
84 crl
, firstSNBigInt
, goodObject
, plContext
));
86 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
87 crl
, firstSNBigInt
, equalObject
, plContext
));
89 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
92 PL_strlen(secondSNAscii
),
96 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
101 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
102 crl
, secondSNBigInt
, diffObject
, plContext
));
109 PKIX_TEST_DECREF_AC(firstSNBigInt
);
110 PKIX_TEST_DECREF_AC(secondSNBigInt
);
111 PKIX_TEST_DECREF_AC(firstSNString
);
112 PKIX_TEST_DECREF_AC(secondSNString
);
116 static void testGetReasonCode(
117 PKIX_PL_CRLEntry
*goodObject
)
119 PKIX_Int32 reasonCode
= 0;
120 PKIX_Int32 expectedReasonCode
= 260;
122 PKIX_TEST_STD_VARS();
124 subTest("PKIX_PL_CRLEntry_GetCRLEntryReasonCode");
126 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCRLEntryReasonCode(
127 goodObject
, &reasonCode
, plContext
));
129 if (reasonCode
!= expectedReasonCode
) {
130 testError("unexpected value of CRL Entry Reason Code");
131 (void) printf("Actual value:\t%d\n", reasonCode
);
132 (void) printf("Expected value:\t%d\n", expectedReasonCode
);
141 testCritExtensionsAbsent(PKIX_PL_CRLEntry
*crlEntry
)
143 PKIX_List
*oidList
= NULL
;
144 PKIX_UInt32 numOids
= 0;
146 PKIX_TEST_STD_VARS();
148 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCriticalExtensionOIDs
149 (crlEntry
, &oidList
, plContext
));
151 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
152 (oidList
, &numOids
, plContext
));
154 pkixTestErrorMsg
= "unexpected mismatch";
159 PKIX_TEST_DECREF_AC(oidList
);
165 testGetCriticalExtensionOIDs(PKIX_PL_CRLEntry
*goodObject
)
167 subTest("PKIX_PL_CRL_GetCriticalExtensionOIDs "
168 "<CritExtensionsAbsent>");
169 testCritExtensionsAbsent(goodObject
);
173 void printUsage(void) {
174 (void) printf("\nUSAGE:\ttest_crlentry <data-dir>\n\n");
177 /* Functional tests for CRLENTRY public functions */
179 int main(int argc
, char *argv
[]) {
180 PKIX_PL_CRL
*crl
= NULL
;
181 PKIX_PL_CRLEntry
*goodObject
= NULL
;
182 PKIX_PL_CRLEntry
*equalObject
= NULL
;
183 PKIX_PL_CRLEntry
*diffObject
= NULL
;
184 PKIX_UInt32 actualMinorVersion
;
186 PKIX_Boolean useArenas
= PKIX_FALSE
;
188 char *dataDir
= NULL
;
189 char *goodInput
= "crlgood.crl";
190 char *expectedAscii
=
192 "\tSerialNumber: 010932\n"
193 "\tReasonCode: 260\n"
194 "\tRevocationDate: Fri Jan 07 15:09:10 2005\n"
195 "\tCritExtOIDs: (EMPTY)\n"
198 /* Note XXX serialnumber and reasoncode need debug */
200 PKIX_TEST_STD_VARS();
202 startTests("CRLEntry");
204 useArenas
= PKIX_TEST_ARENAS_ARG(argv
[1]);
206 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
207 (PKIX_TRUE
, /* nssInitNeeded */
223 (dataDir
, goodInput
, &crl
, &goodObject
, &equalObject
, &diffObject
);
225 PKIX_TEST_EQ_HASH_TOSTR_DUP
229 NULL
, /* expectedAscii, */
233 testGetReasonCode(goodObject
);
235 testGetCriticalExtensionOIDs(goodObject
);
239 PKIX_TEST_DECREF_AC(crl
);
240 PKIX_TEST_DECREF_AC(goodObject
);
241 PKIX_TEST_DECREF_AC(equalObject
);
242 PKIX_TEST_DECREF_AC(diffObject
);
244 PKIX_Shutdown(plContext
);
248 endTests("CRLEntry");