tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_nameconstraints.c (2960B)


      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_nameconstraints.c
      6 *
      7 * Test CERT Name Constraints Type
      8 *
      9 */
     10 
     11 #include "testutil.h"
     12 #include "testutil_nss.h"
     13 
     14 static void *plContext = NULL;
     15 
     16 static char *
     17 catDirName(char *platform, char *dir, void *plContext)
     18 {
     19    char *pathName = NULL;
     20    PKIX_UInt32 dirLen;
     21    PKIX_UInt32 platformLen;
     22 
     23    PKIX_TEST_STD_VARS();
     24 
     25    dirLen = PL_strlen(dir);
     26    platformLen = PL_strlen(platform);
     27 
     28    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc(platformLen +
     29                                                 dirLen +
     30                                                 2,
     31                                             (void **)&pathName, plContext));
     32 
     33    PL_strcpy(pathName, platform);
     34    PL_strcat(pathName, "/");
     35    PL_strcat(pathName, dir);
     36 
     37 cleanup:
     38 
     39    PKIX_TEST_RETURN();
     40 
     41    return (pathName);
     42 }
     43 
     44 static void
     45 testNameConstraints(char *dataDir)
     46 {
     47    char *goodPname = "nameConstraintsDN5CACert.crt";
     48    PKIX_PL_Cert *goodCert = NULL;
     49    PKIX_PL_CertNameConstraints *goodNC = NULL;
     50    char *expectedAscii =
     51        "[\n"
     52        "\t\tPermitted Name:  (OU=permittedSubtree1,"
     53        "O=Test Certificates,C=US)\n"
     54        "\t\tExcluded Name:   (OU=excludedSubtree1,"
     55        "OU=permittedSubtree1,O=Test Certificates,C=US)\n"
     56        "\t]\n";
     57 
     58    PKIX_TEST_STD_VARS();
     59 
     60    subTest("PKIX_PL_CertNameConstraints");
     61 
     62    goodCert = createCert(dataDir, goodPname, plContext);
     63 
     64    subTest("PKIX_PL_Cert_GetNameConstraints");
     65 
     66    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetNameConstraints(goodCert, &goodNC, plContext));
     67 
     68    testToStringHelper((PKIX_PL_Object *)goodNC, expectedAscii, plContext);
     69 
     70 cleanup:
     71 
     72    PKIX_TEST_DECREF_AC(goodNC);
     73    PKIX_TEST_DECREF_AC(goodCert);
     74 
     75    PKIX_TEST_RETURN();
     76 }
     77 
     78 static void
     79 printUsage(void)
     80 {
     81    (void)printf("\nUSAGE:\ttest_nameconstraints <test-purpose>"
     82                 " <data-dir> <platform-prefix>\n\n");
     83 }
     84 
     85 /* Functional tests for CRL public functions */
     86 
     87 int
     88 test_nameconstraints(int argc, char *argv[])
     89 {
     90    PKIX_UInt32 actualMinorVersion;
     91    PKIX_UInt32 j = 0;
     92    char *platformDir = NULL;
     93    char *dataDir = NULL;
     94    char *combinedDir = NULL;
     95 
     96    /* Note XXX serialnumber and reasoncode need debug */
     97 
     98    PKIX_TEST_STD_VARS();
     99 
    100    startTests("NameConstraints");
    101 
    102    PKIX_TEST_EXPECT_NO_ERROR(
    103        PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
    104 
    105    if (argc < 3 + j) {
    106        printUsage();
    107        return (0);
    108    }
    109 
    110    dataDir = argv[2 + j];
    111    platformDir = argv[3 + j];
    112    combinedDir = catDirName(platformDir, dataDir, plContext);
    113 
    114    testNameConstraints(combinedDir);
    115 
    116 cleanup:
    117 
    118    pkixTestErrorResult = PKIX_PL_Free(combinedDir, plContext);
    119 
    120    PKIX_Shutdown(plContext);
    121 
    122    PKIX_TEST_RETURN();
    123 
    124    endTests("NameConstraints");
    125 
    126    return (0);
    127 }