~ubuntu-branches/ubuntu/precise/nss/precise-security

« back to all changes in this revision

Viewing changes to nss/cmd/libpkix/pkix/top/test_basicconstraintschecker.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-ay302kimn72ovt88
Tags: 3.15.3-0ubuntu0.12.04.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_basicconstraintschecker.c
 
6
 *
 
7
 * Test Basic Constraints Checking
 
8
 *
 
9
 */
 
10
 
 
11
#include "testutil.h"
 
12
#include "testutil_nss.h"
 
13
 
 
14
#define PKIX_TEST_MAX_CERTS     10
 
15
 
 
16
static void *plContext = NULL;
 
17
 
 
18
static
 
19
void printUsage1(char *pName){
 
20
        printf("\nUSAGE: %s test-name [ENE|EE] ", pName);
 
21
        printf("cert [certs].\n");
 
22
}
 
23
 
 
24
static
 
25
void printUsageMax(PKIX_UInt32 numCerts){
 
26
        printf("\nUSAGE ERROR: number of certs %d exceed maximum %d\n",
 
27
                numCerts, PKIX_TEST_MAX_CERTS);
 
28
}
 
29
 
 
30
int test_basicconstraintschecker(int argc, char *argv[]){
 
31
 
 
32
        PKIX_List *chain = NULL;
 
33
        PKIX_ValidateParams *valParams = NULL;
 
34
        PKIX_ValidateResult *valResult = NULL;
 
35
        PKIX_UInt32 actualMinorVersion;
 
36
        char *certNames[PKIX_TEST_MAX_CERTS];
 
37
        PKIX_PL_Cert *certs[PKIX_TEST_MAX_CERTS];
 
38
        PKIX_VerifyNode *verifyTree = NULL;
 
39
        PKIX_PL_String *verifyString = NULL;
 
40
        PKIX_UInt32 chainLength = 0;
 
41
        PKIX_UInt32 i = 0;
 
42
        PKIX_UInt32 j = 0;
 
43
        PKIX_Boolean testValid = PKIX_FALSE;
 
44
        char *dirName = NULL;
 
45
 
 
46
        PKIX_TEST_STD_VARS();
 
47
 
 
48
        if (argc < 4){
 
49
                printUsage1(argv[0]);
 
50
                return (0);
 
51
        }
 
52
 
 
53
        startTests("BasicConstraintsChecker");
 
54
 
 
55
        PKIX_TEST_EXPECT_NO_ERROR(
 
56
            PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
 
57
 
 
58
        /* ENE = expect no error; EE = expect error */
 
59
        if (PORT_Strcmp(argv[2+j], "ENE") == 0) {
 
60
                testValid = PKIX_TRUE;
 
61
        } else if (PORT_Strcmp(argv[2+j], "EE") == 0) {
 
62
                testValid = PKIX_FALSE;
 
63
        } else {
 
64
                printUsage1(argv[0]);
 
65
                return (0);
 
66
        }
 
67
 
 
68
        dirName = argv[3+j];
 
69
 
 
70
        chainLength = (argc - j) - 4;
 
71
        if (chainLength > PKIX_TEST_MAX_CERTS) {
 
72
                printUsageMax(chainLength);
 
73
        }
 
74
 
 
75
        for (i = 0; i < chainLength; i++) {
 
76
                certNames[i] = argv[(4+j)+i];
 
77
                certs[i] = NULL;
 
78
        }
 
79
 
 
80
        subTest(argv[1+j]);
 
81
 
 
82
        subTest("Basic-Constraints - Create Cert Chain");
 
83
 
 
84
        chain = createCertChainPlus
 
85
                (dirName, certNames, certs, chainLength, plContext);
 
86
 
 
87
        /*
 
88
         * Error occurs when creating Cert, this is critical and test
 
89
         * should not continue. Since we expect error, we assume this
 
90
         * error is the one that is expected, so undo the error count.
 
91
         *
 
92
         * This work needs future enhancement. We will introduce another
 
93
         * flag ESE, in addition to the existing EE(expect validation
 
94
         * error) and ENE(expect no validation error). ESE stands for
 
95
         * "expect setup error". When running with ESE, if any of the setup
 
96
         * calls such creating Cert Chain fails, the test can end and
 
97
         * considered to be successful.
 
98
         */
 
99
        if (testValid == PKIX_FALSE && chain == NULL) {
 
100
                testErrorUndo("Cert Error - Create failed");
 
101
                goto cleanup;
 
102
        }
 
103
 
 
104
        subTest("Basic-Constraints - Create Params");
 
105
 
 
106
        valParams = createValidateParams
 
107
                (dirName,
 
108
                argv[4+j],
 
109
                NULL,
 
110
                NULL,
 
111
                NULL,
 
112
                PKIX_FALSE,
 
113
                PKIX_FALSE,
 
114
                PKIX_FALSE,
 
115
                PKIX_FALSE,
 
116
                chain,
 
117
                plContext);
 
118
 
 
119
        subTest("Basic-Constraints - Validate Chain");
 
120
 
 
121
        if (testValid == PKIX_TRUE) {
 
122
                PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateChain
 
123
                        (valParams, &valResult, &verifyTree, plContext));
 
124
        } else {
 
125
                PKIX_TEST_EXPECT_ERROR(PKIX_ValidateChain
 
126
                        (valParams, &valResult, &verifyTree, plContext));
 
127
        }
 
128
 
 
129
cleanup:
 
130
 
 
131
        PKIX_TEST_DECREF_AC(verifyString);
 
132
        PKIX_TEST_DECREF_AC(verifyTree);
 
133
        PKIX_TEST_DECREF_AC(chain);
 
134
        PKIX_TEST_DECREF_AC(valParams);
 
135
        PKIX_TEST_DECREF_AC(valResult);
 
136
 
 
137
        PKIX_Shutdown(plContext);
 
138
 
 
139
        PKIX_TEST_RETURN();
 
140
 
 
141
        endTests("BasicConstraintsChecker");
 
142
 
 
143
        return (0);
 
144
}