tor-browser

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

test_authorityinfoaccess.c (3163B)


      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_authorityinfoaccess.c
      6 *
      7 * Test Authority InfoAccess Type
      8 *
      9 */
     10 
     11 #include "testutil.h"
     12 #include "testutil_nss.h"
     13 
     14 static void *plContext = NULL;
     15 
     16 int
     17 test_authorityinfoaccess(int argc, char *argv[])
     18 {
     19 
     20    PKIX_PL_Cert *cert = NULL;
     21    PKIX_PL_Cert *certDiff = NULL;
     22    PKIX_List *aiaList = NULL;
     23    PKIX_List *siaList = NULL;
     24    PKIX_PL_InfoAccess *aia = NULL;
     25    PKIX_PL_InfoAccess *aiaDup = NULL;
     26    PKIX_PL_InfoAccess *aiaDiff = NULL;
     27    char *certPathName = NULL;
     28    char *dirName = NULL;
     29    PKIX_UInt32 actualMinorVersion;
     30    PKIX_UInt32 size, i;
     31    PKIX_UInt32 j = 0;
     32    char *expectedAscii = "[method:caIssuers, location:ldap:"
     33                          "//betty.nist.gov/cn=CA,ou=Basic%20LDAP%20URI%20OU1,"
     34                          "o=Test%20Certificates,c=US?cACertificate;binary,"
     35                          "crossCertificatePair;binary]";
     36 
     37    PKIX_TEST_STD_VARS();
     38 
     39    startTests("AuthorityInfoAccess");
     40 
     41    PKIX_TEST_EXPECT_NO_ERROR(
     42        PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
     43 
     44    if (argc < 5 + j) {
     45        printf("Usage: %s <test-purpose> <cert> <diff-cert>\n", argv[0]);
     46    }
     47 
     48    dirName = argv[2 + j];
     49    certPathName = argv[3 + j];
     50 
     51    subTest("Creating Cert with Authority Info Access");
     52    cert = createCert(dirName, certPathName, plContext);
     53 
     54    certPathName = argv[4 + j];
     55 
     56    subTest("Creating Cert with Subject Info Access");
     57    certDiff = createCert(dirName, certPathName, plContext);
     58 
     59    subTest("Getting Authority Info Access");
     60    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetAuthorityInfoAccess(cert, &aiaList, plContext));
     61 
     62    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength(aiaList, &size, plContext));
     63 
     64    if (size != 1) {
     65        pkixTestErrorMsg = "unexpected number of AIA";
     66        goto cleanup;
     67    }
     68 
     69    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem(aiaList, 0, (PKIX_PL_Object **)&aia, plContext));
     70 
     71    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem(aiaList, 0, (PKIX_PL_Object **)&aiaDup, plContext));
     72 
     73    subTest("Getting Subject Info Access as difference comparison");
     74    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubjectInfoAccess(certDiff, &siaList, plContext));
     75 
     76    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength(siaList, &size, plContext));
     77 
     78    if (size != 1) {
     79        pkixTestErrorMsg = "unexpected number of AIA";
     80        goto cleanup;
     81    }
     82 
     83    PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem(siaList, 0, (PKIX_PL_Object **)&aiaDiff, plContext));
     84 
     85    subTest("Checking: Equal, Hash and ToString");
     86    PKIX_TEST_EQ_HASH_TOSTR_DUP(aia, aiaDup, aiaDiff, expectedAscii, InfoAccess, PKIX_FALSE);
     87 
     88 cleanup:
     89 
     90    PKIX_TEST_DECREF_AC(aia);
     91    PKIX_TEST_DECREF_AC(aiaDup);
     92    PKIX_TEST_DECREF_AC(aiaDiff);
     93    PKIX_TEST_DECREF_AC(aiaList);
     94    PKIX_TEST_DECREF_AC(siaList);
     95    PKIX_TEST_DECREF_AC(cert);
     96    PKIX_TEST_DECREF_AC(certDiff);
     97 
     98    PKIX_Shutdown(plContext);
     99 
    100    PKIX_TEST_RETURN();
    101 
    102    endTests("Authorityinfoaccess");
    103 
    104    return (0);
    105 }