summaryrefslogtreecommitdiff
path: root/security/nss/cmd/libpkix/pkix/results/test_verifynode.c
blob: 2b8e1c3f768c4d8003511463ef16979cfa985514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
 * test_verifynode.c
 *
 * Test VerifyNode Type
 *
 */

#include "testutil.h"
#include "testutil_nss.h"

static void *plContext =  NULL;

static
void printUsage(void) {
        (void) printf("\nUSAGE:\ttest_verifynode path cert1 cert2 cert3\n\n");
}

int test_verifynode(int argc, char *argv[]) {

        /*
         * Create a tree with parent = cert1, child=cert2, grandchild=cert3
         */
        PKIX_PL_Cert *cert1 = NULL;
        PKIX_PL_Cert *cert2 = NULL;
	PKIX_PL_Cert *cert3 = NULL;
        PKIX_VerifyNode *parentNode = NULL;
        PKIX_VerifyNode *childNode = NULL;
        PKIX_VerifyNode *grandChildNode = NULL;
        PKIX_PL_String *parentString = NULL;

        PKIX_UInt32 actualMinorVersion;
        PKIX_UInt32 j = 0;
        char *dirName = NULL;
	char *twoNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Cert"
		"ificates,C=US, Subject:CN=Trust Anchor,O=Test Certif"
		"icates,C=US], depth=0, error=(null)\n. CERT[Issuer:C"
		"N=Trust Anchor,O=Test Certificates,C=US, Subject:CN="
		"Good CA,O=Test Certificates,C=US], depth=1, error=(null)";
	char *threeNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Ce"
		"rtificates,C=US, Subject:CN=Trust Anchor,O=Test Cert"
		"ificates,C=US], depth=0, error=(null)\n. CERT[Issuer"
		":CN=Trust Anchor,O=Test Certificates,C=US, Subject:C"
		"N=Good CA,O=Test Certificates,C=US], depth=1, error="
		"(null)\n. . CERT[Issuer:CN=Good CA,O=Test Certificat"
		"es,C=US, Subject:CN=Valid EE Certificate Test1,O=Tes"
		"t Certificates,C=US], depth=2, error=(null)";

        PKIX_TEST_STD_VARS();

        if (argc < 3) {
                printUsage();
                return (0);
        }

        startTests("VerifyNode");

        PKIX_TEST_EXPECT_NO_ERROR(
            PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));

        dirName = argv[++j];

        subTest("Creating Certs");

        cert1 = createCert
                (dirName, argv[++j], plContext);

        cert2 = createCert
                (dirName, argv[++j], plContext);

        cert3 = createCert
                (dirName, argv[++j], plContext);

        subTest("Creating VerifyNode objects");

        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
		(cert1, 0, NULL, &parentNode, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
		(cert2, 1, NULL, &childNode, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
		(cert3, 2, NULL, &grandChildNode, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain
		(parentNode, childNode, plContext));

        subTest("Creating VerifyNode ToString objects");

	testToStringHelper
		((PKIX_PL_Object *)parentNode, twoNodeAscii, plContext);

        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain
		(parentNode, grandChildNode, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
                ((PKIX_PL_Object*)parentNode, &parentString, plContext));
        (void) printf("parentNode is\n\t%s\n", parentString->escAsciiString);

	testToStringHelper
		((PKIX_PL_Object *)parentNode, threeNodeAscii, plContext);

cleanup:

        PKIX_TEST_DECREF_AC(cert1);
        PKIX_TEST_DECREF_AC(cert2);
        PKIX_TEST_DECREF_AC(parentNode);
        PKIX_TEST_DECREF_AC(childNode);
        PKIX_TEST_DECREF_AC(parentString);

        PKIX_Shutdown(plContext);

        PKIX_TEST_RETURN();

        endTests("VerifyNode");

        return (0);
}