summaryrefslogtreecommitdiffstats
path: root/security/nss/cmd/libpkix/pkix_pl/pki/test_subjectinfoaccess.c
blob: 8f2ff9ec7e9a85dbba7090afde55d404b48373d3 (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
121
/* 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_subjectinfoaccess.c
 *
 * Test Subject InfoAccess Type
 *
 */

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

static void *plContext = NULL;

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

    PKIX_PL_Cert *cert = NULL;
    PKIX_PL_Cert *certDiff = NULL;
    PKIX_List *aiaList = NULL;
    PKIX_List *siaList = NULL;
    PKIX_PL_InfoAccess *sia = NULL;
    PKIX_PL_InfoAccess *siaDup = NULL;
    PKIX_PL_InfoAccess *siaDiff = NULL;
    PKIX_PL_GeneralName *location = NULL;
    char *certPathName = NULL;
    char *dirName = NULL;
    PKIX_UInt32 method = 0;
    PKIX_UInt32 actualMinorVersion;
    PKIX_UInt32 size, i;
    PKIX_UInt32 j = 0;
    char *expectedAscii = "[method:caRepository, "
                          "location:http://betty.nist.gov/pathdiscoverytestsuite/"
                          "p7cfiles/IssuedByTrustAnchor1.p7c]";

    PKIX_TEST_STD_VARS();

    startTests("SubjectInfoAccess");

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

    if (argc < 5 + j) {
        printf("Usage: %s <test-purpose> <cert> <diff-cert>\n", argv[0]);
    }

    dirName = argv[2 + j];
    certPathName = argv[3 + j];

    subTest("Creating Cert with Subject Info Access");
    cert = createCert(dirName, certPathName, plContext);

    certPathName = argv[4 + j];

    subTest("Creating Cert with Subject Info Access");
    certDiff = createCert(dirName, certPathName, plContext);

    subTest("Getting Subject Info Access");
    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubjectInfoAccess(cert, &siaList, plContext));

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength(siaList, &size, plContext));

    if (size != 1) {
        pkixTestErrorMsg = "unexpected number of AIA";
        goto cleanup;
    }

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem(siaList, 0, (PKIX_PL_Object **)&sia, plContext));

    subTest("PKIX_PL_InfoAccess_GetMethod");
    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetMethod(sia, &method, plContext));
    if (method != PKIX_INFOACCESS_CA_REPOSITORY) {
        pkixTestErrorMsg = "unexpected method of AIA";
        goto cleanup;
    }

    subTest("PKIX_PL_InfoAccess_GetLocation");
    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_InfoAccess_GetLocation(sia, &location, plContext));
    if (!location) {
        pkixTestErrorMsg = "Cannot get AIA location";
        goto cleanup;
    }

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem(siaList, 0, (PKIX_PL_Object **)&siaDup, plContext));

    subTest("Getting Authority Info Access as difference comparison");
    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetAuthorityInfoAccess(certDiff, &aiaList, plContext));

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength(aiaList, &size, plContext));

    if (size != 1) {
        pkixTestErrorMsg = "unexpected number of AIA";
        goto cleanup;
    }

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem(aiaList, 0, (PKIX_PL_Object **)&siaDiff, plContext));

    subTest("Checking: Equal, Hash and ToString");
    PKIX_TEST_EQ_HASH_TOSTR_DUP(sia, siaDup, siaDiff, expectedAscii, InfoAccess, PKIX_FALSE);

cleanup:

    PKIX_TEST_DECREF_AC(location);
    PKIX_TEST_DECREF_AC(sia);
    PKIX_TEST_DECREF_AC(siaDup);
    PKIX_TEST_DECREF_AC(siaDiff);
    PKIX_TEST_DECREF_AC(aiaList);
    PKIX_TEST_DECREF_AC(siaList);
    PKIX_TEST_DECREF_AC(cert);
    PKIX_TEST_DECREF_AC(certDiff);

    PKIX_Shutdown(plContext);

    PKIX_TEST_RETURN();

    endTests("Subjectinfoaccess");

    return (0);
}