security/nss/cmd/libpkix/testutil/testutil_nss.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/cmd/libpkix/testutil/testutil_nss.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,630 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +/*
     1.8 + * testutil_nss.c
     1.9 + *
    1.10 + * NSS-specific utility functions for handling test errors
    1.11 + *
    1.12 + */
    1.13 +
    1.14 +#include <stdio.h>
    1.15 +#include <string.h>
    1.16 +#include <stddef.h>
    1.17 +
    1.18 +#include "pkix_pl_generalname.h"
    1.19 +#include "pkix_pl_cert.h"
    1.20 +#include "pkix.h"
    1.21 +#include "testutil.h"
    1.22 +#include "prlong.h"
    1.23 +#include "plstr.h"
    1.24 +#include "prthread.h"
    1.25 +#include "secutil.h"
    1.26 +#include "nspr.h"
    1.27 +#include "prtypes.h"
    1.28 +#include "prtime.h"
    1.29 +#include "pk11func.h"
    1.30 +#include "secasn1.h"
    1.31 +#include "cert.h"
    1.32 +#include "cryptohi.h"
    1.33 +#include "secoid.h"
    1.34 +#include "certdb.h"
    1.35 +#include "secitem.h"
    1.36 +#include "keythi.h"
    1.37 +#include "nss.h"
    1.38 +
    1.39 +static char *catDirName(char *dir, char *name, void *plContext)
    1.40 +{
    1.41 +        char *pathName = NULL;
    1.42 +        PKIX_UInt32 nameLen;
    1.43 +        PKIX_UInt32 dirLen;
    1.44 +
    1.45 +        PKIX_TEST_STD_VARS();
    1.46 +
    1.47 +        nameLen = PL_strlen(name);
    1.48 +        dirLen = PL_strlen(dir);
    1.49 +
    1.50 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc
    1.51 +                                    (dirLen + nameLen + 2,
    1.52 +                                    (void **)&pathName,
    1.53 +                                    plContext));
    1.54 +
    1.55 +        PL_strcpy(pathName, dir);
    1.56 +        PL_strcat(pathName, "/");
    1.57 +        PL_strcat(pathName, name);
    1.58 +        printf("pathName = %s\n", pathName);
    1.59 +
    1.60 +cleanup:
    1.61 +
    1.62 +        PKIX_TEST_RETURN();
    1.63 +
    1.64 +        return (pathName);
    1.65 +}
    1.66 +
    1.67 +PKIX_PL_Cert *
    1.68 +createCert(
    1.69 +        char *dirName,
    1.70 +        char *certFileName,
    1.71 +        void *plContext)
    1.72 +{
    1.73 +        PKIX_PL_ByteArray *byteArray = NULL;
    1.74 +        void *buf = NULL;
    1.75 +        PRFileDesc *certFile = NULL;
    1.76 +        PKIX_UInt32 len;
    1.77 +        SECItem certDER;
    1.78 +        SECStatus rv;
    1.79 +        /* default: NULL cert (failure case) */
    1.80 +        PKIX_PL_Cert *cert = NULL;
    1.81 +        char *pathName = NULL;
    1.82 +
    1.83 +        PKIX_TEST_STD_VARS();
    1.84 +
    1.85 +
    1.86 +        certDER.data = NULL;
    1.87 +
    1.88 +        pathName = catDirName(dirName, certFileName, plContext);
    1.89 +        certFile = PR_Open(pathName, PR_RDONLY, 0);
    1.90 +
    1.91 +        if (!certFile){
    1.92 +                pkixTestErrorMsg = "Unable to open cert file";
    1.93 +                goto cleanup;
    1.94 +        } else {
    1.95 +                rv = SECU_ReadDERFromFile(&certDER, certFile, PR_FALSE, PR_FALSE);
    1.96 +                if (!rv){
    1.97 +                        buf = (void *)certDER.data;
    1.98 +                        len = certDER.len;
    1.99 +
   1.100 +                        PKIX_TEST_EXPECT_NO_ERROR
   1.101 +                                (PKIX_PL_ByteArray_Create
   1.102 +                                (buf, len, &byteArray, plContext));
   1.103 +
   1.104 +                        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_Create
   1.105 +                                                (byteArray, &cert, plContext));
   1.106 +
   1.107 +                        SECITEM_FreeItem(&certDER, PR_FALSE);
   1.108 +                } else {
   1.109 +                        pkixTestErrorMsg = "Unable to read DER from cert file";
   1.110 +                        goto cleanup;
   1.111 +                }
   1.112 +        }
   1.113 +
   1.114 +cleanup:
   1.115 +
   1.116 +        pkixTestErrorResult = PKIX_PL_Free(pathName, plContext);
   1.117 +
   1.118 +        if (certFile){
   1.119 +                PR_Close(certFile);
   1.120 +        }
   1.121 +
   1.122 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.123 +                SECITEM_FreeItem(&certDER, PR_FALSE);
   1.124 +        }
   1.125 +
   1.126 +        PKIX_TEST_DECREF_AC(byteArray);
   1.127 +
   1.128 +        PKIX_TEST_RETURN();
   1.129 +
   1.130 +        return (cert);
   1.131 +}
   1.132 +
   1.133 +PKIX_PL_CRL *
   1.134 +createCRL(
   1.135 +        char *dirName,
   1.136 +        char *crlFileName,
   1.137 +        void *plContext)
   1.138 +{
   1.139 +        PKIX_PL_ByteArray *byteArray = NULL;
   1.140 +        PKIX_PL_CRL *crl = NULL;
   1.141 +        PKIX_Error *error = NULL;
   1.142 +        PRFileDesc *inFile = NULL;
   1.143 +        SECItem crlDER;
   1.144 +        void *buf = NULL;
   1.145 +        PKIX_UInt32 len;
   1.146 +        SECStatus rv;
   1.147 +        char *pathName = NULL;
   1.148 +
   1.149 +        PKIX_TEST_STD_VARS();
   1.150 +
   1.151 +        crlDER.data = NULL;
   1.152 +
   1.153 +        pathName = catDirName(dirName, crlFileName, plContext);
   1.154 +        inFile = PR_Open(pathName, PR_RDONLY, 0);
   1.155 +
   1.156 +        if (!inFile){
   1.157 +                pkixTestErrorMsg = "Unable to open crl file";
   1.158 +                goto cleanup;
   1.159 +        } else {
   1.160 +                rv = SECU_ReadDERFromFile(&crlDER, inFile, PR_FALSE, PR_FALSE);
   1.161 +                if (!rv){
   1.162 +                        buf = (void *)crlDER.data;
   1.163 +                        len = crlDER.len;
   1.164 +
   1.165 +                        error = PKIX_PL_ByteArray_Create
   1.166 +                                (buf, len, &byteArray, plContext);
   1.167 +
   1.168 +                        if (error){
   1.169 +                                pkixTestErrorMsg =
   1.170 +                                        "PKIX_PL_ByteArray_Create failed";
   1.171 +                                goto cleanup;
   1.172 +                        }
   1.173 +
   1.174 +                        error = PKIX_PL_CRL_Create(byteArray, &crl, plContext);
   1.175 +                        if (error){
   1.176 +                                pkixTestErrorMsg = "PKIX_PL_Crl_Create failed";
   1.177 +                                goto cleanup;
   1.178 +                        }
   1.179 +
   1.180 +                        SECITEM_FreeItem(&crlDER, PR_FALSE);
   1.181 +                } else {
   1.182 +                        pkixTestErrorMsg = "Unable to read DER from crl file";
   1.183 +                        goto cleanup;
   1.184 +                }
   1.185 +        }
   1.186 +
   1.187 +cleanup:
   1.188 +
   1.189 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(pathName, plContext));
   1.190 +
   1.191 +        if (inFile){
   1.192 +                PR_Close(inFile);
   1.193 +        }
   1.194 +
   1.195 +        if (error){
   1.196 +                SECITEM_FreeItem(&crlDER, PR_FALSE);
   1.197 +        }
   1.198 +
   1.199 +        PKIX_TEST_DECREF_AC(byteArray);
   1.200 +
   1.201 +        PKIX_TEST_RETURN();
   1.202 +
   1.203 +        return (crl);
   1.204 +
   1.205 +}
   1.206 +
   1.207 +PKIX_TrustAnchor *
   1.208 +createTrustAnchor(
   1.209 +        char *dirName,
   1.210 +        char *certFileName,
   1.211 +        PKIX_Boolean useCert,
   1.212 +        void *plContext)
   1.213 +{
   1.214 +        PKIX_TrustAnchor *anchor = NULL;
   1.215 +        PKIX_PL_Cert *cert = NULL;
   1.216 +        PKIX_PL_X500Name *name = NULL;
   1.217 +        PKIX_PL_PublicKey *pubKey = NULL;
   1.218 +        PKIX_PL_CertNameConstraints *nameConstraints = NULL;
   1.219 +
   1.220 +        PKIX_TEST_STD_VARS();
   1.221 +
   1.222 +        cert = createCert(dirName, certFileName, plContext);
   1.223 +
   1.224 +        if (useCert){
   1.225 +                PKIX_TEST_EXPECT_NO_ERROR(PKIX_TrustAnchor_CreateWithCert
   1.226 +                                        (cert, &anchor, plContext));
   1.227 +        } else {
   1.228 +                PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubject
   1.229 +                                        (cert, &name, plContext));
   1.230 +
   1.231 +                if (name == NULL){
   1.232 +                        goto cleanup;
   1.233 +                }
   1.234 +
   1.235 +                PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubjectPublicKey
   1.236 +                                        (cert, &pubKey, plContext));
   1.237 +
   1.238 +                PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetNameConstraints
   1.239 +                                        (cert, &nameConstraints, NULL));
   1.240 +
   1.241 +                PKIX_TEST_EXPECT_NO_ERROR
   1.242 +                        (PKIX_TrustAnchor_CreateWithNameKeyPair
   1.243 +                        (name, pubKey, nameConstraints, &anchor, plContext));
   1.244 +        }
   1.245 +
   1.246 +cleanup:
   1.247 +
   1.248 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.249 +                PKIX_TEST_DECREF_AC(anchor);
   1.250 +        }
   1.251 +
   1.252 +        PKIX_TEST_DECREF_AC(cert);
   1.253 +        PKIX_TEST_DECREF_AC(name);
   1.254 +        PKIX_TEST_DECREF_AC(pubKey);
   1.255 +        PKIX_TEST_DECREF_AC(nameConstraints);
   1.256 +
   1.257 +        PKIX_TEST_RETURN();
   1.258 +
   1.259 +        return (anchor);
   1.260 +}
   1.261 +
   1.262 +PKIX_List *
   1.263 +createCertChain(
   1.264 +        char *dirName,
   1.265 +        char *firstCertFileName,
   1.266 +        char *secondCertFileName,
   1.267 +        void *plContext)
   1.268 +{
   1.269 +        PKIX_PL_Cert *firstCert = NULL;
   1.270 +        PKIX_PL_Cert *secondCert = NULL;
   1.271 +        PKIX_List *certList = NULL;
   1.272 +
   1.273 +        PKIX_TEST_STD_VARS();
   1.274 +
   1.275 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&certList, plContext));
   1.276 +
   1.277 +        firstCert = createCert(dirName, firstCertFileName, plContext);
   1.278 +
   1.279 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
   1.280 +                (certList, (PKIX_PL_Object *)firstCert, plContext));
   1.281 +
   1.282 +        if (secondCertFileName){
   1.283 +                secondCert = createCert(dirName, secondCertFileName, plContext);
   1.284 +
   1.285 +                PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
   1.286 +                        (certList, (PKIX_PL_Object *)secondCert, plContext));
   1.287 +        }
   1.288 +
   1.289 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_SetImmutable
   1.290 +                                    (certList, plContext));
   1.291 +
   1.292 +cleanup:
   1.293 +
   1.294 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.295 +                PKIX_TEST_DECREF_AC(certList);
   1.296 +        }
   1.297 +
   1.298 +        PKIX_TEST_DECREF_AC(firstCert);
   1.299 +        PKIX_TEST_DECREF_AC(secondCert);
   1.300 +
   1.301 +        PKIX_TEST_RETURN();
   1.302 +
   1.303 +        return (certList);
   1.304 +}
   1.305 +
   1.306 +PKIX_List *
   1.307 +createCertChainPlus(
   1.308 +        char *dirName,
   1.309 +        char *certNames[],
   1.310 +        PKIX_PL_Cert *certs[],
   1.311 +        PKIX_UInt32 numCerts,
   1.312 +        void *plContext)
   1.313 +{
   1.314 +        PKIX_List *certList = NULL;
   1.315 +        PKIX_UInt32 i;
   1.316 +
   1.317 +        PKIX_TEST_STD_VARS();
   1.318 +
   1.319 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&certList, plContext));
   1.320 +
   1.321 +        for (i = 0; i < numCerts; i++) {
   1.322 +
   1.323 +                certs[i] = createCert(dirName, certNames[i], plContext);
   1.324 +
   1.325 +                /* Create Cert may fail */
   1.326 +                if (certs[i] == NULL) {
   1.327 +                        PKIX_TEST_DECREF_BC(certList);
   1.328 +                        goto cleanup;
   1.329 +                }
   1.330 +
   1.331 +                PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
   1.332 +                                            (certList,
   1.333 +                                            (PKIX_PL_Object *)certs[i],
   1.334 +                                            plContext));
   1.335 +        }
   1.336 +
   1.337 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_SetImmutable
   1.338 +                                    (certList, plContext));
   1.339 +
   1.340 +cleanup:
   1.341 +
   1.342 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.343 +                PKIX_TEST_DECREF_AC(certList);
   1.344 +        }
   1.345 +
   1.346 +        for (i = 0; i < numCerts; i++) {
   1.347 +                PKIX_TEST_DECREF_AC(certs[i]);
   1.348 +        }
   1.349 +
   1.350 +        PKIX_TEST_RETURN();
   1.351 +
   1.352 +        return (certList);
   1.353 +
   1.354 +}
   1.355 +
   1.356 +PKIX_PL_Date *
   1.357 +createDate(
   1.358 +        char *asciiDate,
   1.359 +        void *plContext)
   1.360 +{
   1.361 +        PKIX_PL_Date *date = NULL;
   1.362 +        PKIX_PL_String *plString = NULL;
   1.363 +
   1.364 +        PKIX_TEST_STD_VARS();
   1.365 +
   1.366 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
   1.367 +            (PKIX_ESCASCII, asciiDate, 0, &plString, plContext));
   1.368 +
   1.369 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Date_Create_UTCTime
   1.370 +                                    (plString, &date, plContext));
   1.371 +
   1.372 +cleanup:
   1.373 +
   1.374 +        PKIX_TEST_DECREF_AC(plString);
   1.375 +
   1.376 +        PKIX_TEST_RETURN();
   1.377 +
   1.378 +        return (date);
   1.379 +}
   1.380 +
   1.381 +PKIX_ProcessingParams *
   1.382 +createProcessingParams(
   1.383 +        char *dirName,
   1.384 +        char *firstAnchorFileName,
   1.385 +        char *secondAnchorFileName,
   1.386 +        char *dateAscii,
   1.387 +        PKIX_List *initialPolicies, /* List of PKIX_PL_OID */
   1.388 +        PKIX_Boolean isCrlEnabled,
   1.389 +        void *plContext)
   1.390 +{
   1.391 +
   1.392 +        PKIX_TrustAnchor *firstAnchor = NULL;
   1.393 +        PKIX_TrustAnchor *secondAnchor = NULL;
   1.394 +        PKIX_List *anchorsList = NULL;
   1.395 +        PKIX_ProcessingParams *procParams = NULL;
   1.396 +        PKIX_PL_String *dateString = NULL;
   1.397 +        PKIX_PL_Date *testDate = NULL;
   1.398 +
   1.399 +        PKIX_TEST_STD_VARS();
   1.400 +
   1.401 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&anchorsList, plContext));
   1.402 +
   1.403 +        firstAnchor = createTrustAnchor
   1.404 +                (dirName, firstAnchorFileName, PKIX_FALSE, plContext);
   1.405 +
   1.406 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
   1.407 +                                    (anchorsList,
   1.408 +                                    (PKIX_PL_Object *)firstAnchor,
   1.409 +                                    plContext));
   1.410 +
   1.411 +        if (secondAnchorFileName){
   1.412 +                secondAnchor =
   1.413 +                        createTrustAnchor
   1.414 +                        (dirName, secondAnchorFileName, PKIX_FALSE, plContext);
   1.415 +
   1.416 +                PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
   1.417 +                                            (anchorsList,
   1.418 +                                            (PKIX_PL_Object *)secondAnchor,
   1.419 +                                            plContext));
   1.420 +        }
   1.421 +
   1.422 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_Create
   1.423 +                                    (anchorsList, &procParams, plContext));
   1.424 +
   1.425 +        if (dateAscii){
   1.426 +                PKIX_TEST_EXPECT_NO_ERROR
   1.427 +                        (PKIX_PL_String_Create
   1.428 +                        (PKIX_ESCASCII,
   1.429 +                        dateAscii,
   1.430 +                        0,
   1.431 +                        &dateString,
   1.432 +                        plContext));
   1.433 +
   1.434 +                PKIX_TEST_EXPECT_NO_ERROR
   1.435 +                        (PKIX_PL_Date_Create_UTCTime
   1.436 +                        (dateString, &testDate, plContext));
   1.437 +
   1.438 +                PKIX_TEST_EXPECT_NO_ERROR
   1.439 +                        (PKIX_ProcessingParams_SetDate
   1.440 +                        (procParams, testDate, plContext));
   1.441 +        }
   1.442 +
   1.443 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetInitialPolicies
   1.444 +                (procParams, initialPolicies, plContext));
   1.445 +
   1.446 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetRevocationEnabled
   1.447 +                                    (procParams, isCrlEnabled, plContext));
   1.448 +
   1.449 +cleanup:
   1.450 +
   1.451 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.452 +                PKIX_TEST_DECREF_AC(procParams);
   1.453 +        }
   1.454 +
   1.455 +        PKIX_TEST_DECREF_AC(dateString);
   1.456 +        PKIX_TEST_DECREF_AC(testDate);
   1.457 +        PKIX_TEST_DECREF_AC(anchorsList);
   1.458 +        PKIX_TEST_DECREF_AC(firstAnchor);
   1.459 +        PKIX_TEST_DECREF_AC(secondAnchor);
   1.460 +
   1.461 +        PKIX_TEST_RETURN();
   1.462 +
   1.463 +        return (procParams);
   1.464 +}
   1.465 +
   1.466 +PKIX_ValidateParams *
   1.467 +createValidateParams(
   1.468 +        char *dirName,
   1.469 +        char *firstAnchorFileName,
   1.470 +        char *secondAnchorFileName,
   1.471 +        char *dateAscii,
   1.472 +        PKIX_List *initialPolicies, /* List of PKIX_PL_OID */
   1.473 +        PKIX_Boolean initialPolicyMappingInhibit,
   1.474 +        PKIX_Boolean initialAnyPolicyInhibit,
   1.475 +        PKIX_Boolean initialExplicitPolicy,
   1.476 +        PKIX_Boolean isCrlEnabled,
   1.477 +        PKIX_List *chain,
   1.478 +        void *plContext)
   1.479 +{
   1.480 +
   1.481 +        PKIX_ProcessingParams *procParams = NULL;
   1.482 +        PKIX_ValidateParams *valParams = NULL;
   1.483 +
   1.484 +        PKIX_TEST_STD_VARS();
   1.485 +
   1.486 +        procParams =
   1.487 +                createProcessingParams
   1.488 +                    (dirName,
   1.489 +                    firstAnchorFileName,
   1.490 +                    secondAnchorFileName,
   1.491 +                    dateAscii,
   1.492 +                    NULL,
   1.493 +                    isCrlEnabled,
   1.494 +                    plContext);
   1.495 +
   1.496 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetInitialPolicies
   1.497 +                (procParams, initialPolicies, plContext));
   1.498 +
   1.499 +        PKIX_TEST_EXPECT_NO_ERROR
   1.500 +                (PKIX_ProcessingParams_SetPolicyMappingInhibited
   1.501 +                (procParams, initialPolicyMappingInhibit, NULL));
   1.502 +
   1.503 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetAnyPolicyInhibited
   1.504 +                (procParams, initialAnyPolicyInhibit, NULL));
   1.505 +
   1.506 +        PKIX_TEST_EXPECT_NO_ERROR
   1.507 +                (PKIX_ProcessingParams_SetExplicitPolicyRequired
   1.508 +                (procParams, initialExplicitPolicy, NULL));
   1.509 +
   1.510 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_Create
   1.511 +                (procParams, chain, &valParams, plContext));
   1.512 +
   1.513 +cleanup:
   1.514 +
   1.515 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.516 +                PKIX_TEST_DECREF_AC(valParams);
   1.517 +        }
   1.518 +
   1.519 +        PKIX_TEST_DECREF_AC(procParams);
   1.520 +
   1.521 +        PKIX_TEST_RETURN();
   1.522 +
   1.523 +        return (valParams);
   1.524 +}
   1.525 +
   1.526 +PKIX_ValidateResult *
   1.527 +createValidateResult(
   1.528 +        char *dirName,
   1.529 +        char *anchorFileName,
   1.530 +        char *pubKeyCertFileName,
   1.531 +        void *plContext)
   1.532 +{
   1.533 +
   1.534 +        PKIX_TrustAnchor *anchor = NULL;
   1.535 +        PKIX_ValidateResult *valResult = NULL;
   1.536 +        PKIX_PL_Cert *cert = NULL;
   1.537 +        PKIX_PL_PublicKey *pubKey = NULL;
   1.538 +
   1.539 +        PKIX_TEST_STD_VARS();
   1.540 +
   1.541 +        anchor = createTrustAnchor
   1.542 +                    (dirName, anchorFileName, PKIX_FALSE, plContext);
   1.543 +        cert = createCert(dirName, pubKeyCertFileName, plContext);
   1.544 +
   1.545 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubjectPublicKey
   1.546 +                                    (cert, &pubKey, plContext));
   1.547 +
   1.548 +        PKIX_TEST_EXPECT_NO_ERROR
   1.549 +                (pkix_ValidateResult_Create
   1.550 +                (pubKey, anchor, NULL, &valResult, plContext));
   1.551 +
   1.552 +cleanup:
   1.553 +
   1.554 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.555 +                PKIX_TEST_DECREF_AC(valResult);
   1.556 +        }
   1.557 +
   1.558 +        PKIX_TEST_DECREF_AC(anchor);
   1.559 +        PKIX_TEST_DECREF_AC(cert);
   1.560 +        PKIX_TEST_DECREF_AC(pubKey);
   1.561 +
   1.562 +        PKIX_TEST_RETURN();
   1.563 +
   1.564 +        return (valResult);
   1.565 +}
   1.566 +
   1.567 +PKIX_PL_GeneralName *
   1.568 +createGeneralName(
   1.569 +        PKIX_UInt32 nameType,
   1.570 +        char *asciiName,
   1.571 +        void *plContext)
   1.572 +{
   1.573 +
   1.574 +        PKIX_PL_GeneralName *generalName = NULL;
   1.575 +        PKIX_PL_String *plString = NULL;
   1.576 +
   1.577 +        PKIX_TEST_STD_VARS();
   1.578 +
   1.579 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
   1.580 +            (PKIX_ESCASCII, asciiName, 0, &plString, plContext));
   1.581 +
   1.582 +        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_GeneralName_Create
   1.583 +            (nameType, plString, &generalName, plContext));
   1.584 +
   1.585 +cleanup:
   1.586 +
   1.587 +        PKIX_TEST_DECREF_AC(plString);
   1.588 +
   1.589 +        PKIX_TEST_RETURN();
   1.590 +
   1.591 +        return (generalName);
   1.592 +}
   1.593 +
   1.594 +PKIX_BuildResult *
   1.595 +createBuildResult(
   1.596 +        char *dirName,
   1.597 +        char *anchorFileName,
   1.598 +        char *pubKeyCertFileName,
   1.599 +        char *firstChainCertFileName,
   1.600 +        char *secondChainCertFileName,
   1.601 +        void *plContext)
   1.602 +{
   1.603 +        PKIX_BuildResult *buildResult = NULL;
   1.604 +        PKIX_ValidateResult *valResult = NULL;
   1.605 +        PKIX_List *certChain = NULL;
   1.606 +
   1.607 +        PKIX_TEST_STD_VARS();
   1.608 +
   1.609 +        valResult = createValidateResult
   1.610 +                (dirName, anchorFileName, pubKeyCertFileName, plContext);
   1.611 +        certChain = createCertChain
   1.612 +                        (dirName,
   1.613 +                        firstChainCertFileName,
   1.614 +                        secondChainCertFileName,
   1.615 +                        plContext);
   1.616 +
   1.617 +        PKIX_TEST_EXPECT_NO_ERROR
   1.618 +                (pkix_BuildResult_Create
   1.619 +                (valResult, certChain, &buildResult, plContext));
   1.620 +
   1.621 +cleanup:
   1.622 +
   1.623 +        if (PKIX_TEST_ERROR_RECEIVED){
   1.624 +                PKIX_TEST_DECREF_AC(buildResult);
   1.625 +        }
   1.626 +
   1.627 +        PKIX_TEST_DECREF_AC(valResult);
   1.628 +        PKIX_TEST_DECREF_AC(certChain);
   1.629 +
   1.630 +        PKIX_TEST_RETURN();
   1.631 +
   1.632 +        return (buildResult);
   1.633 +}

mercurial