PageRenderTime 31ms CodeModel.GetById 16ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/security/nss/cmd/libpkix/pkix_pl/pki/test_crlentry.c

http://github.com/zpao/v8monkey
C | 244 lines | 149 code | 51 blank | 44 comment | 5 complexity | f7bf0e44779b6abe3da77aa8c5b62eac MD5 | raw file
  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_crlentry.c
 39 *
 40 * Test CRLENTRY Type
 41 *
 42 */
 43
 44#include "testutil.h"
 45#include "testutil_nss.h"
 46
 47static void *plContext = NULL;
 48
 49static
 50void createCRLEntries(
 51        char *dataDir,
 52        char *crlInput,
 53        PKIX_PL_CRL **pCrl,
 54        PKIX_PL_CRLEntry **goodObject,
 55        PKIX_PL_CRLEntry **equalObject,
 56        PKIX_PL_CRLEntry **diffObject)
 57{
 58        PKIX_PL_CRL *crl = NULL;
 59        PKIX_PL_BigInt *firstSNBigInt = NULL;
 60        PKIX_PL_BigInt *secondSNBigInt = NULL;
 61        PKIX_PL_String *firstSNString = NULL;
 62        PKIX_PL_String *secondSNString = NULL;
 63        char *firstSNAscii = "010932";
 64        char *secondSNAscii = "3039";
 65
 66        PKIX_TEST_STD_VARS();
 67
 68        subTest("PKIX_PL_CRL_Create <crl>");
 69        crl = createCRL(dataDir, crlInput, plContext);
 70
 71        subTest("PKIX_PL_CRL_GetCRLEntryForSerialNumber");
 72        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
 73                                    PKIX_ESCASCII,
 74                                    firstSNAscii,
 75                                    PL_strlen(firstSNAscii),
 76                                    &firstSNString,
 77                                    plContext));
 78
 79        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
 80                            firstSNString,
 81                            &firstSNBigInt,
 82                            plContext));
 83
 84        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
 85                            crl, firstSNBigInt, goodObject, plContext));
 86
 87        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
 88                            crl, firstSNBigInt, equalObject, plContext));
 89
 90        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
 91                                    PKIX_ESCASCII,
 92                                    secondSNAscii,
 93                                    PL_strlen(secondSNAscii),
 94                                    &secondSNString,
 95                                    plContext));
 96
 97        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
 98                            secondSNString,
 99                            &secondSNBigInt,
100                            plContext));
101
102        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
103                            crl, secondSNBigInt, diffObject, plContext));
104
105
106
107        *pCrl = crl;
108
109cleanup:
110        PKIX_TEST_DECREF_AC(firstSNBigInt);
111        PKIX_TEST_DECREF_AC(secondSNBigInt);
112        PKIX_TEST_DECREF_AC(firstSNString);
113        PKIX_TEST_DECREF_AC(secondSNString);
114        PKIX_TEST_RETURN();
115}
116
117static void testGetReasonCode(
118        PKIX_PL_CRLEntry *goodObject)
119{
120        PKIX_Int32 reasonCode = 0;
121        PKIX_Int32 expectedReasonCode = 260;
122
123        PKIX_TEST_STD_VARS();
124
125        subTest("PKIX_PL_CRLEntry_GetCRLEntryReasonCode");
126
127        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCRLEntryReasonCode(
128                            goodObject, &reasonCode, plContext));
129
130        if (reasonCode != expectedReasonCode) {
131                testError("unexpected value of CRL Entry Reason Code");
132                (void) printf("Actual value:\t%d\n", reasonCode);
133                (void) printf("Expected value:\t%d\n", expectedReasonCode);
134                goto cleanup;
135        }
136
137cleanup:
138        PKIX_TEST_RETURN();
139}
140
141static void
142testCritExtensionsAbsent(PKIX_PL_CRLEntry *crlEntry)
143{
144        PKIX_List *oidList = NULL;
145        PKIX_UInt32 numOids = 0;
146
147        PKIX_TEST_STD_VARS();
148
149        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCriticalExtensionOIDs
150                                    (crlEntry, &oidList, plContext));
151
152        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
153                                    (oidList, &numOids, plContext));
154        if (numOids != 0){
155                pkixTestErrorMsg = "unexpected mismatch";
156        }
157
158cleanup:
159
160        PKIX_TEST_DECREF_AC(oidList);
161
162        PKIX_TEST_RETURN();
163}
164
165static void
166testGetCriticalExtensionOIDs(PKIX_PL_CRLEntry *goodObject)
167{
168        subTest("PKIX_PL_CRL_GetCriticalExtensionOIDs "
169                "<CritExtensionsAbsent>");
170        testCritExtensionsAbsent(goodObject);
171
172}
173
174static
175void printUsage(void) {
176        (void) printf("\nUSAGE:\ttest_crlentry <data-dir>\n\n");
177}
178
179/* Functional tests for CRLENTRY public functions */
180
181int test_crlentry(int argc, char *argv[]) {
182        PKIX_PL_CRL *crl = NULL;
183        PKIX_PL_CRLEntry *goodObject = NULL;
184        PKIX_PL_CRLEntry *equalObject = NULL;
185        PKIX_PL_CRLEntry *diffObject = NULL;
186        PKIX_UInt32 actualMinorVersion;
187        PKIX_UInt32 j = 0;
188
189        char *dataDir = NULL;
190        char *goodInput = "crlgood.crl";
191        char *expectedAscii =
192                "\n\t[\n"
193                "\tSerialNumber:    010932\n"
194                "\tReasonCode:      260\n"
195                "\tRevocationDate:  Fri Jan 07 15:09:10 2005\n"
196                "\tCritExtOIDs:     (EMPTY)\n"
197                "\t]\n\t";
198
199        /* Note XXX serialnumber and reasoncode need debug */
200
201        PKIX_TEST_STD_VARS();
202
203        startTests("CRLEntry");
204
205        PKIX_TEST_EXPECT_NO_ERROR(
206            PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
207
208        if (argc < 1+j) {
209                printUsage();
210                return (0);
211        }
212
213        dataDir = argv[1+j];
214
215        createCRLEntries
216            (dataDir, goodInput, &crl, &goodObject, &equalObject, &diffObject);
217
218        PKIX_TEST_EQ_HASH_TOSTR_DUP
219                (goodObject,
220                equalObject,
221                diffObject,
222                NULL, /* expectedAscii, */
223                CRLENTRY,
224                PKIX_TRUE);
225
226        testGetReasonCode(goodObject);
227
228        testGetCriticalExtensionOIDs(goodObject);
229
230cleanup:
231
232        PKIX_TEST_DECREF_AC(crl);
233        PKIX_TEST_DECREF_AC(goodObject);
234        PKIX_TEST_DECREF_AC(equalObject);
235        PKIX_TEST_DECREF_AC(diffObject);
236
237        PKIX_Shutdown(plContext);
238
239        PKIX_TEST_RETURN();
240
241        endTests("CRLEntry");
242
243        return (0);
244}