~ubuntu-branches/ubuntu/quantal/nss/quantal-updates

« back to all changes in this revision

Viewing changes to mozilla/security/nss/cmd/libpkix/pkix/top/test_validatechain.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-11-14 14:58:07 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20131114145807-vj6v4erz8xj6kwz3
Tags: 3.15.3-0ubuntu0.12.10.1
* SECURITY UPDATE: New upstream release to fix multiple security issues
  and add TLSv1.2 support.
  - CVE-2013-1739
  - CVE-2013-1741
  - CVE-2013-5605
  - CVE-2013-5606
* Adjusted packaging for 3.15.3:
  - debian/patches/*: refreshed.
  - debian/patches/lower-dhe-priority.patch: removed, no longer needed,
    was a workaround for an old version of firefox.
  - debian/libnss3.symbols: added new symbols.
  - debian/rules: updated for new source layout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
 
/*
5
 
 * test_validatechain.c
6
 
 *
7
 
 * Test ValidateChain function
8
 
 *
9
 
 */
10
 
 
11
 
#include "testutil.h"
12
 
#include "testutil_nss.h"
13
 
 
14
 
static void *plContext = NULL;
15
 
 
16
 
static
17
 
void printUsage(void){
18
 
        (void) printf("\nUSAGE:\nvalidateChain TestName [ENE|EE] "
19
 
                    "<certStoreDirectory> <trustedCert> <targetCert>\n\n");
20
 
        (void) printf
21
 
                ("Validates a chain of certificates between "
22
 
                "<trustedCert> and <targetCert>\n"
23
 
                "using the certs and CRLs in <certStoreDirectory>. "
24
 
                "If ENE is specified,\n"
25
 
                "then an Error is Not Expected. "
26
 
                "If EE is specified, an Error is Expected.\n");
27
 
}
28
 
 
29
 
static
30
 
char *createFullPathName(
31
 
        char *dirName,
32
 
        char *certFile,
33
 
        void *plContext)
34
 
{
35
 
        PKIX_UInt32 certFileLen;
36
 
        PKIX_UInt32 dirNameLen;
37
 
        char *certPathName = NULL;
38
 
 
39
 
        PKIX_TEST_STD_VARS();
40
 
 
41
 
        certFileLen = PL_strlen(certFile);
42
 
        dirNameLen = PL_strlen(dirName);
43
 
 
44
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc
45
 
                (dirNameLen + certFileLen + 2,
46
 
                (void **)&certPathName,
47
 
                plContext));
48
 
 
49
 
        PL_strcpy(certPathName, dirName);
50
 
        PL_strcat(certPathName, "/");
51
 
        PL_strcat(certPathName, certFile);
52
 
        printf("certPathName = %s\n", certPathName);
53
 
 
54
 
cleanup:
55
 
 
56
 
        PKIX_TEST_RETURN();
57
 
 
58
 
        return (certPathName);
59
 
}
60
 
 
61
 
static PKIX_Error *
62
 
testDefaultCertStore(PKIX_ValidateParams *valParams, char *crlDir)
63
 
{
64
 
        PKIX_PL_String *dirString = NULL;
65
 
        PKIX_CertStore *certStore = NULL;
66
 
        PKIX_ProcessingParams *procParams = NULL;
67
 
        PKIX_PL_Date *validity = NULL; 
68
 
        PKIX_List *revCheckers = NULL;
69
 
        PKIX_RevocationChecker *ocspChecker = NULL;
70
 
 
71
 
        PKIX_TEST_STD_VARS();
72
 
 
73
 
        subTest("PKIX_PL_CollectionCertStoreContext_Create");
74
 
 
75
 
        /* Create CollectionCertStore */
76
 
 
77
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
78
 
                (PKIX_ESCASCII, crlDir, 0, &dirString, plContext));
79
 
 
80
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CollectionCertStore_Create
81
 
                (dirString, &certStore, plContext));
82
 
 
83
 
        /* Create CertStore */
84
 
 
85
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetProcessingParams
86
 
                (valParams, &procParams, plContext));
87
 
 
88
 
        subTest("PKIX_ProcessingParams_AddCertStore");
89
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_AddCertStore
90
 
                (procParams, certStore, plContext));
91
 
 
92
 
        subTest("PKIX_ProcessingParams_SetRevocationEnabled");
93
 
 
94
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetRevocationEnabled
95
 
                (procParams, PKIX_TRUE, plContext));
96
 
 
97
 
        /* create current Date */
98
 
        PKIX_TEST_EXPECT_NO_ERROR(pkix_pl_Date_CreateFromPRTime
99
 
                (PR_Now(), &validity, plContext));
100
 
 
101
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&revCheckers, plContext));
102
 
 
103
 
        /* create revChecker */
104
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_OcspChecker_Initialize
105
 
                (validity,
106
 
                NULL,        /* pwArg */
107
 
                NULL,        /* Use default responder */
108
 
                &ocspChecker,
109
 
                plContext));
110
 
 
111
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
112
 
                (revCheckers, (PKIX_PL_Object *)ocspChecker, plContext));
113
 
 
114
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetRevocationCheckers
115
 
                (procParams, revCheckers, plContext));
116
 
 
117
 
cleanup:
118
 
 
119
 
        PKIX_TEST_DECREF_AC(dirString);
120
 
        PKIX_TEST_DECREF_AC(procParams);
121
 
        PKIX_TEST_DECREF_AC(certStore);
122
 
        PKIX_TEST_DECREF_AC(revCheckers);
123
 
        PKIX_TEST_DECREF_AC(ocspChecker);
124
 
 
125
 
        PKIX_TEST_RETURN();
126
 
 
127
 
        return (0);
128
 
}
129
 
 
130
 
int test_validatechain(int argc, char *argv[]){
131
 
 
132
 
        PKIX_ValidateParams *valParams = NULL;
133
 
        PKIX_ValidateResult *valResult = NULL;
134
 
        PKIX_UInt32 actualMinorVersion;
135
 
        PKIX_UInt32 j = 0;
136
 
        PKIX_UInt32 k = 0;
137
 
        PKIX_UInt32 chainLength = 0;
138
 
        PKIX_Boolean testValid = PKIX_TRUE;
139
 
        PKIX_List *chainCerts = NULL;
140
 
        PKIX_PL_Cert *dirCert = NULL;
141
 
        PKIX_VerifyNode *verifyTree = NULL;
142
 
        PKIX_PL_String *verifyString = NULL;
143
 
        char *dirCertName = NULL;
144
 
        char *anchorCertName = NULL;
145
 
        char *dirName = NULL;
146
 
 
147
 
        PKIX_TEST_STD_VARS();
148
 
 
149
 
        if (argc < 5) {
150
 
                printUsage();
151
 
                return (0);
152
 
        }
153
 
 
154
 
        startTests("ValidateChain");
155
 
 
156
 
        PKIX_TEST_EXPECT_NO_ERROR(
157
 
            PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
158
 
 
159
 
        /* ENE = expect no error; EE = expect error */
160
 
        if (PORT_Strcmp(argv[2+j], "ENE") == 0) {
161
 
                testValid = PKIX_TRUE;
162
 
        } else if (PORT_Strcmp(argv[2+j], "EE") == 0) {
163
 
                testValid = PKIX_FALSE;
164
 
        } else {
165
 
                printUsage();
166
 
                return (0);
167
 
        }
168
 
 
169
 
        subTest(argv[1+j]);
170
 
 
171
 
        dirName = argv[3+j];
172
 
 
173
 
        chainLength = argc - j - 5;
174
 
 
175
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&chainCerts, plContext));
176
 
 
177
 
        for (k = 0; k < chainLength; k++) {
178
 
 
179
 
                dirCert = createCert(dirName, argv[5+k+j], plContext);
180
 
 
181
 
                PKIX_TEST_EXPECT_NO_ERROR
182
 
                        (PKIX_List_AppendItem
183
 
                        (chainCerts, (PKIX_PL_Object *)dirCert, plContext));
184
 
 
185
 
                PKIX_TEST_DECREF_BC(dirCert);
186
 
        }
187
 
 
188
 
        valParams = createValidateParams
189
 
                (dirName,
190
 
                argv[4+j],
191
 
                NULL,
192
 
                NULL,
193
 
                NULL,
194
 
                PKIX_FALSE,
195
 
                PKIX_FALSE,
196
 
                PKIX_FALSE,
197
 
                PKIX_FALSE,
198
 
                chainCerts,
199
 
                plContext);
200
 
 
201
 
        testDefaultCertStore(valParams, dirName);
202
 
 
203
 
        if (testValid == PKIX_TRUE) {
204
 
                PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateChain
205
 
                        (valParams, &valResult, &verifyTree, plContext));
206
 
        } else {
207
 
                PKIX_TEST_EXPECT_ERROR(PKIX_ValidateChain
208
 
                        (valParams, &valResult, &verifyTree, plContext));
209
 
        }
210
 
 
211
 
        subTest("Displaying VerifyNode objects");
212
 
 
213
 
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
214
 
                ((PKIX_PL_Object*)verifyTree, &verifyString, plContext));
215
 
        (void) printf("verifyTree is\n%s\n", verifyString->escAsciiString);
216
 
 
217
 
cleanup:
218
 
        PKIX_TEST_DECREF_AC(verifyString);
219
 
        PKIX_TEST_DECREF_AC(verifyTree);
220
 
 
221
 
        PKIX_TEST_DECREF_AC(chainCerts);
222
 
        PKIX_TEST_DECREF_AC(valParams);
223
 
        PKIX_TEST_DECREF_AC(valResult);
224
 
 
225
 
        PKIX_Shutdown(plContext);
226
 
 
227
 
        PKIX_TEST_RETURN();
228
 
 
229
 
        endTests("ValidateChain");
230
 
 
231
 
        return (0);
232
 
}