Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | /* |
michael@0 | 5 | * testutil_nss.c |
michael@0 | 6 | * |
michael@0 | 7 | * NSS-specific utility functions for handling test errors |
michael@0 | 8 | * |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include <stdio.h> |
michael@0 | 12 | #include <string.h> |
michael@0 | 13 | #include <stddef.h> |
michael@0 | 14 | |
michael@0 | 15 | #include "pkix_pl_generalname.h" |
michael@0 | 16 | #include "pkix_pl_cert.h" |
michael@0 | 17 | #include "pkix.h" |
michael@0 | 18 | #include "testutil.h" |
michael@0 | 19 | #include "prlong.h" |
michael@0 | 20 | #include "plstr.h" |
michael@0 | 21 | #include "prthread.h" |
michael@0 | 22 | #include "secutil.h" |
michael@0 | 23 | #include "nspr.h" |
michael@0 | 24 | #include "prtypes.h" |
michael@0 | 25 | #include "prtime.h" |
michael@0 | 26 | #include "pk11func.h" |
michael@0 | 27 | #include "secasn1.h" |
michael@0 | 28 | #include "cert.h" |
michael@0 | 29 | #include "cryptohi.h" |
michael@0 | 30 | #include "secoid.h" |
michael@0 | 31 | #include "certdb.h" |
michael@0 | 32 | #include "secitem.h" |
michael@0 | 33 | #include "keythi.h" |
michael@0 | 34 | #include "nss.h" |
michael@0 | 35 | |
michael@0 | 36 | static char *catDirName(char *dir, char *name, void *plContext) |
michael@0 | 37 | { |
michael@0 | 38 | char *pathName = NULL; |
michael@0 | 39 | PKIX_UInt32 nameLen; |
michael@0 | 40 | PKIX_UInt32 dirLen; |
michael@0 | 41 | |
michael@0 | 42 | PKIX_TEST_STD_VARS(); |
michael@0 | 43 | |
michael@0 | 44 | nameLen = PL_strlen(name); |
michael@0 | 45 | dirLen = PL_strlen(dir); |
michael@0 | 46 | |
michael@0 | 47 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc |
michael@0 | 48 | (dirLen + nameLen + 2, |
michael@0 | 49 | (void **)&pathName, |
michael@0 | 50 | plContext)); |
michael@0 | 51 | |
michael@0 | 52 | PL_strcpy(pathName, dir); |
michael@0 | 53 | PL_strcat(pathName, "/"); |
michael@0 | 54 | PL_strcat(pathName, name); |
michael@0 | 55 | printf("pathName = %s\n", pathName); |
michael@0 | 56 | |
michael@0 | 57 | cleanup: |
michael@0 | 58 | |
michael@0 | 59 | PKIX_TEST_RETURN(); |
michael@0 | 60 | |
michael@0 | 61 | return (pathName); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | PKIX_PL_Cert * |
michael@0 | 65 | createCert( |
michael@0 | 66 | char *dirName, |
michael@0 | 67 | char *certFileName, |
michael@0 | 68 | void *plContext) |
michael@0 | 69 | { |
michael@0 | 70 | PKIX_PL_ByteArray *byteArray = NULL; |
michael@0 | 71 | void *buf = NULL; |
michael@0 | 72 | PRFileDesc *certFile = NULL; |
michael@0 | 73 | PKIX_UInt32 len; |
michael@0 | 74 | SECItem certDER; |
michael@0 | 75 | SECStatus rv; |
michael@0 | 76 | /* default: NULL cert (failure case) */ |
michael@0 | 77 | PKIX_PL_Cert *cert = NULL; |
michael@0 | 78 | char *pathName = NULL; |
michael@0 | 79 | |
michael@0 | 80 | PKIX_TEST_STD_VARS(); |
michael@0 | 81 | |
michael@0 | 82 | |
michael@0 | 83 | certDER.data = NULL; |
michael@0 | 84 | |
michael@0 | 85 | pathName = catDirName(dirName, certFileName, plContext); |
michael@0 | 86 | certFile = PR_Open(pathName, PR_RDONLY, 0); |
michael@0 | 87 | |
michael@0 | 88 | if (!certFile){ |
michael@0 | 89 | pkixTestErrorMsg = "Unable to open cert file"; |
michael@0 | 90 | goto cleanup; |
michael@0 | 91 | } else { |
michael@0 | 92 | rv = SECU_ReadDERFromFile(&certDER, certFile, PR_FALSE, PR_FALSE); |
michael@0 | 93 | if (!rv){ |
michael@0 | 94 | buf = (void *)certDER.data; |
michael@0 | 95 | len = certDER.len; |
michael@0 | 96 | |
michael@0 | 97 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 98 | (PKIX_PL_ByteArray_Create |
michael@0 | 99 | (buf, len, &byteArray, plContext)); |
michael@0 | 100 | |
michael@0 | 101 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_Create |
michael@0 | 102 | (byteArray, &cert, plContext)); |
michael@0 | 103 | |
michael@0 | 104 | SECITEM_FreeItem(&certDER, PR_FALSE); |
michael@0 | 105 | } else { |
michael@0 | 106 | pkixTestErrorMsg = "Unable to read DER from cert file"; |
michael@0 | 107 | goto cleanup; |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | cleanup: |
michael@0 | 112 | |
michael@0 | 113 | pkixTestErrorResult = PKIX_PL_Free(pathName, plContext); |
michael@0 | 114 | |
michael@0 | 115 | if (certFile){ |
michael@0 | 116 | PR_Close(certFile); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 120 | SECITEM_FreeItem(&certDER, PR_FALSE); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | PKIX_TEST_DECREF_AC(byteArray); |
michael@0 | 124 | |
michael@0 | 125 | PKIX_TEST_RETURN(); |
michael@0 | 126 | |
michael@0 | 127 | return (cert); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | PKIX_PL_CRL * |
michael@0 | 131 | createCRL( |
michael@0 | 132 | char *dirName, |
michael@0 | 133 | char *crlFileName, |
michael@0 | 134 | void *plContext) |
michael@0 | 135 | { |
michael@0 | 136 | PKIX_PL_ByteArray *byteArray = NULL; |
michael@0 | 137 | PKIX_PL_CRL *crl = NULL; |
michael@0 | 138 | PKIX_Error *error = NULL; |
michael@0 | 139 | PRFileDesc *inFile = NULL; |
michael@0 | 140 | SECItem crlDER; |
michael@0 | 141 | void *buf = NULL; |
michael@0 | 142 | PKIX_UInt32 len; |
michael@0 | 143 | SECStatus rv; |
michael@0 | 144 | char *pathName = NULL; |
michael@0 | 145 | |
michael@0 | 146 | PKIX_TEST_STD_VARS(); |
michael@0 | 147 | |
michael@0 | 148 | crlDER.data = NULL; |
michael@0 | 149 | |
michael@0 | 150 | pathName = catDirName(dirName, crlFileName, plContext); |
michael@0 | 151 | inFile = PR_Open(pathName, PR_RDONLY, 0); |
michael@0 | 152 | |
michael@0 | 153 | if (!inFile){ |
michael@0 | 154 | pkixTestErrorMsg = "Unable to open crl file"; |
michael@0 | 155 | goto cleanup; |
michael@0 | 156 | } else { |
michael@0 | 157 | rv = SECU_ReadDERFromFile(&crlDER, inFile, PR_FALSE, PR_FALSE); |
michael@0 | 158 | if (!rv){ |
michael@0 | 159 | buf = (void *)crlDER.data; |
michael@0 | 160 | len = crlDER.len; |
michael@0 | 161 | |
michael@0 | 162 | error = PKIX_PL_ByteArray_Create |
michael@0 | 163 | (buf, len, &byteArray, plContext); |
michael@0 | 164 | |
michael@0 | 165 | if (error){ |
michael@0 | 166 | pkixTestErrorMsg = |
michael@0 | 167 | "PKIX_PL_ByteArray_Create failed"; |
michael@0 | 168 | goto cleanup; |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | error = PKIX_PL_CRL_Create(byteArray, &crl, plContext); |
michael@0 | 172 | if (error){ |
michael@0 | 173 | pkixTestErrorMsg = "PKIX_PL_Crl_Create failed"; |
michael@0 | 174 | goto cleanup; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | SECITEM_FreeItem(&crlDER, PR_FALSE); |
michael@0 | 178 | } else { |
michael@0 | 179 | pkixTestErrorMsg = "Unable to read DER from crl file"; |
michael@0 | 180 | goto cleanup; |
michael@0 | 181 | } |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | cleanup: |
michael@0 | 185 | |
michael@0 | 186 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(pathName, plContext)); |
michael@0 | 187 | |
michael@0 | 188 | if (inFile){ |
michael@0 | 189 | PR_Close(inFile); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | if (error){ |
michael@0 | 193 | SECITEM_FreeItem(&crlDER, PR_FALSE); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | PKIX_TEST_DECREF_AC(byteArray); |
michael@0 | 197 | |
michael@0 | 198 | PKIX_TEST_RETURN(); |
michael@0 | 199 | |
michael@0 | 200 | return (crl); |
michael@0 | 201 | |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | PKIX_TrustAnchor * |
michael@0 | 205 | createTrustAnchor( |
michael@0 | 206 | char *dirName, |
michael@0 | 207 | char *certFileName, |
michael@0 | 208 | PKIX_Boolean useCert, |
michael@0 | 209 | void *plContext) |
michael@0 | 210 | { |
michael@0 | 211 | PKIX_TrustAnchor *anchor = NULL; |
michael@0 | 212 | PKIX_PL_Cert *cert = NULL; |
michael@0 | 213 | PKIX_PL_X500Name *name = NULL; |
michael@0 | 214 | PKIX_PL_PublicKey *pubKey = NULL; |
michael@0 | 215 | PKIX_PL_CertNameConstraints *nameConstraints = NULL; |
michael@0 | 216 | |
michael@0 | 217 | PKIX_TEST_STD_VARS(); |
michael@0 | 218 | |
michael@0 | 219 | cert = createCert(dirName, certFileName, plContext); |
michael@0 | 220 | |
michael@0 | 221 | if (useCert){ |
michael@0 | 222 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_TrustAnchor_CreateWithCert |
michael@0 | 223 | (cert, &anchor, plContext)); |
michael@0 | 224 | } else { |
michael@0 | 225 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubject |
michael@0 | 226 | (cert, &name, plContext)); |
michael@0 | 227 | |
michael@0 | 228 | if (name == NULL){ |
michael@0 | 229 | goto cleanup; |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubjectPublicKey |
michael@0 | 233 | (cert, &pubKey, plContext)); |
michael@0 | 234 | |
michael@0 | 235 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetNameConstraints |
michael@0 | 236 | (cert, &nameConstraints, NULL)); |
michael@0 | 237 | |
michael@0 | 238 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 239 | (PKIX_TrustAnchor_CreateWithNameKeyPair |
michael@0 | 240 | (name, pubKey, nameConstraints, &anchor, plContext)); |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | cleanup: |
michael@0 | 244 | |
michael@0 | 245 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 246 | PKIX_TEST_DECREF_AC(anchor); |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | PKIX_TEST_DECREF_AC(cert); |
michael@0 | 250 | PKIX_TEST_DECREF_AC(name); |
michael@0 | 251 | PKIX_TEST_DECREF_AC(pubKey); |
michael@0 | 252 | PKIX_TEST_DECREF_AC(nameConstraints); |
michael@0 | 253 | |
michael@0 | 254 | PKIX_TEST_RETURN(); |
michael@0 | 255 | |
michael@0 | 256 | return (anchor); |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | PKIX_List * |
michael@0 | 260 | createCertChain( |
michael@0 | 261 | char *dirName, |
michael@0 | 262 | char *firstCertFileName, |
michael@0 | 263 | char *secondCertFileName, |
michael@0 | 264 | void *plContext) |
michael@0 | 265 | { |
michael@0 | 266 | PKIX_PL_Cert *firstCert = NULL; |
michael@0 | 267 | PKIX_PL_Cert *secondCert = NULL; |
michael@0 | 268 | PKIX_List *certList = NULL; |
michael@0 | 269 | |
michael@0 | 270 | PKIX_TEST_STD_VARS(); |
michael@0 | 271 | |
michael@0 | 272 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&certList, plContext)); |
michael@0 | 273 | |
michael@0 | 274 | firstCert = createCert(dirName, firstCertFileName, plContext); |
michael@0 | 275 | |
michael@0 | 276 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem |
michael@0 | 277 | (certList, (PKIX_PL_Object *)firstCert, plContext)); |
michael@0 | 278 | |
michael@0 | 279 | if (secondCertFileName){ |
michael@0 | 280 | secondCert = createCert(dirName, secondCertFileName, plContext); |
michael@0 | 281 | |
michael@0 | 282 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem |
michael@0 | 283 | (certList, (PKIX_PL_Object *)secondCert, plContext)); |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_SetImmutable |
michael@0 | 287 | (certList, plContext)); |
michael@0 | 288 | |
michael@0 | 289 | cleanup: |
michael@0 | 290 | |
michael@0 | 291 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 292 | PKIX_TEST_DECREF_AC(certList); |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | PKIX_TEST_DECREF_AC(firstCert); |
michael@0 | 296 | PKIX_TEST_DECREF_AC(secondCert); |
michael@0 | 297 | |
michael@0 | 298 | PKIX_TEST_RETURN(); |
michael@0 | 299 | |
michael@0 | 300 | return (certList); |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | PKIX_List * |
michael@0 | 304 | createCertChainPlus( |
michael@0 | 305 | char *dirName, |
michael@0 | 306 | char *certNames[], |
michael@0 | 307 | PKIX_PL_Cert *certs[], |
michael@0 | 308 | PKIX_UInt32 numCerts, |
michael@0 | 309 | void *plContext) |
michael@0 | 310 | { |
michael@0 | 311 | PKIX_List *certList = NULL; |
michael@0 | 312 | PKIX_UInt32 i; |
michael@0 | 313 | |
michael@0 | 314 | PKIX_TEST_STD_VARS(); |
michael@0 | 315 | |
michael@0 | 316 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&certList, plContext)); |
michael@0 | 317 | |
michael@0 | 318 | for (i = 0; i < numCerts; i++) { |
michael@0 | 319 | |
michael@0 | 320 | certs[i] = createCert(dirName, certNames[i], plContext); |
michael@0 | 321 | |
michael@0 | 322 | /* Create Cert may fail */ |
michael@0 | 323 | if (certs[i] == NULL) { |
michael@0 | 324 | PKIX_TEST_DECREF_BC(certList); |
michael@0 | 325 | goto cleanup; |
michael@0 | 326 | } |
michael@0 | 327 | |
michael@0 | 328 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem |
michael@0 | 329 | (certList, |
michael@0 | 330 | (PKIX_PL_Object *)certs[i], |
michael@0 | 331 | plContext)); |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_SetImmutable |
michael@0 | 335 | (certList, plContext)); |
michael@0 | 336 | |
michael@0 | 337 | cleanup: |
michael@0 | 338 | |
michael@0 | 339 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 340 | PKIX_TEST_DECREF_AC(certList); |
michael@0 | 341 | } |
michael@0 | 342 | |
michael@0 | 343 | for (i = 0; i < numCerts; i++) { |
michael@0 | 344 | PKIX_TEST_DECREF_AC(certs[i]); |
michael@0 | 345 | } |
michael@0 | 346 | |
michael@0 | 347 | PKIX_TEST_RETURN(); |
michael@0 | 348 | |
michael@0 | 349 | return (certList); |
michael@0 | 350 | |
michael@0 | 351 | } |
michael@0 | 352 | |
michael@0 | 353 | PKIX_PL_Date * |
michael@0 | 354 | createDate( |
michael@0 | 355 | char *asciiDate, |
michael@0 | 356 | void *plContext) |
michael@0 | 357 | { |
michael@0 | 358 | PKIX_PL_Date *date = NULL; |
michael@0 | 359 | PKIX_PL_String *plString = NULL; |
michael@0 | 360 | |
michael@0 | 361 | PKIX_TEST_STD_VARS(); |
michael@0 | 362 | |
michael@0 | 363 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create |
michael@0 | 364 | (PKIX_ESCASCII, asciiDate, 0, &plString, plContext)); |
michael@0 | 365 | |
michael@0 | 366 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Date_Create_UTCTime |
michael@0 | 367 | (plString, &date, plContext)); |
michael@0 | 368 | |
michael@0 | 369 | cleanup: |
michael@0 | 370 | |
michael@0 | 371 | PKIX_TEST_DECREF_AC(plString); |
michael@0 | 372 | |
michael@0 | 373 | PKIX_TEST_RETURN(); |
michael@0 | 374 | |
michael@0 | 375 | return (date); |
michael@0 | 376 | } |
michael@0 | 377 | |
michael@0 | 378 | PKIX_ProcessingParams * |
michael@0 | 379 | createProcessingParams( |
michael@0 | 380 | char *dirName, |
michael@0 | 381 | char *firstAnchorFileName, |
michael@0 | 382 | char *secondAnchorFileName, |
michael@0 | 383 | char *dateAscii, |
michael@0 | 384 | PKIX_List *initialPolicies, /* List of PKIX_PL_OID */ |
michael@0 | 385 | PKIX_Boolean isCrlEnabled, |
michael@0 | 386 | void *plContext) |
michael@0 | 387 | { |
michael@0 | 388 | |
michael@0 | 389 | PKIX_TrustAnchor *firstAnchor = NULL; |
michael@0 | 390 | PKIX_TrustAnchor *secondAnchor = NULL; |
michael@0 | 391 | PKIX_List *anchorsList = NULL; |
michael@0 | 392 | PKIX_ProcessingParams *procParams = NULL; |
michael@0 | 393 | PKIX_PL_String *dateString = NULL; |
michael@0 | 394 | PKIX_PL_Date *testDate = NULL; |
michael@0 | 395 | |
michael@0 | 396 | PKIX_TEST_STD_VARS(); |
michael@0 | 397 | |
michael@0 | 398 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&anchorsList, plContext)); |
michael@0 | 399 | |
michael@0 | 400 | firstAnchor = createTrustAnchor |
michael@0 | 401 | (dirName, firstAnchorFileName, PKIX_FALSE, plContext); |
michael@0 | 402 | |
michael@0 | 403 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem |
michael@0 | 404 | (anchorsList, |
michael@0 | 405 | (PKIX_PL_Object *)firstAnchor, |
michael@0 | 406 | plContext)); |
michael@0 | 407 | |
michael@0 | 408 | if (secondAnchorFileName){ |
michael@0 | 409 | secondAnchor = |
michael@0 | 410 | createTrustAnchor |
michael@0 | 411 | (dirName, secondAnchorFileName, PKIX_FALSE, plContext); |
michael@0 | 412 | |
michael@0 | 413 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem |
michael@0 | 414 | (anchorsList, |
michael@0 | 415 | (PKIX_PL_Object *)secondAnchor, |
michael@0 | 416 | plContext)); |
michael@0 | 417 | } |
michael@0 | 418 | |
michael@0 | 419 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_Create |
michael@0 | 420 | (anchorsList, &procParams, plContext)); |
michael@0 | 421 | |
michael@0 | 422 | if (dateAscii){ |
michael@0 | 423 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 424 | (PKIX_PL_String_Create |
michael@0 | 425 | (PKIX_ESCASCII, |
michael@0 | 426 | dateAscii, |
michael@0 | 427 | 0, |
michael@0 | 428 | &dateString, |
michael@0 | 429 | plContext)); |
michael@0 | 430 | |
michael@0 | 431 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 432 | (PKIX_PL_Date_Create_UTCTime |
michael@0 | 433 | (dateString, &testDate, plContext)); |
michael@0 | 434 | |
michael@0 | 435 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 436 | (PKIX_ProcessingParams_SetDate |
michael@0 | 437 | (procParams, testDate, plContext)); |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetInitialPolicies |
michael@0 | 441 | (procParams, initialPolicies, plContext)); |
michael@0 | 442 | |
michael@0 | 443 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetRevocationEnabled |
michael@0 | 444 | (procParams, isCrlEnabled, plContext)); |
michael@0 | 445 | |
michael@0 | 446 | cleanup: |
michael@0 | 447 | |
michael@0 | 448 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 449 | PKIX_TEST_DECREF_AC(procParams); |
michael@0 | 450 | } |
michael@0 | 451 | |
michael@0 | 452 | PKIX_TEST_DECREF_AC(dateString); |
michael@0 | 453 | PKIX_TEST_DECREF_AC(testDate); |
michael@0 | 454 | PKIX_TEST_DECREF_AC(anchorsList); |
michael@0 | 455 | PKIX_TEST_DECREF_AC(firstAnchor); |
michael@0 | 456 | PKIX_TEST_DECREF_AC(secondAnchor); |
michael@0 | 457 | |
michael@0 | 458 | PKIX_TEST_RETURN(); |
michael@0 | 459 | |
michael@0 | 460 | return (procParams); |
michael@0 | 461 | } |
michael@0 | 462 | |
michael@0 | 463 | PKIX_ValidateParams * |
michael@0 | 464 | createValidateParams( |
michael@0 | 465 | char *dirName, |
michael@0 | 466 | char *firstAnchorFileName, |
michael@0 | 467 | char *secondAnchorFileName, |
michael@0 | 468 | char *dateAscii, |
michael@0 | 469 | PKIX_List *initialPolicies, /* List of PKIX_PL_OID */ |
michael@0 | 470 | PKIX_Boolean initialPolicyMappingInhibit, |
michael@0 | 471 | PKIX_Boolean initialAnyPolicyInhibit, |
michael@0 | 472 | PKIX_Boolean initialExplicitPolicy, |
michael@0 | 473 | PKIX_Boolean isCrlEnabled, |
michael@0 | 474 | PKIX_List *chain, |
michael@0 | 475 | void *plContext) |
michael@0 | 476 | { |
michael@0 | 477 | |
michael@0 | 478 | PKIX_ProcessingParams *procParams = NULL; |
michael@0 | 479 | PKIX_ValidateParams *valParams = NULL; |
michael@0 | 480 | |
michael@0 | 481 | PKIX_TEST_STD_VARS(); |
michael@0 | 482 | |
michael@0 | 483 | procParams = |
michael@0 | 484 | createProcessingParams |
michael@0 | 485 | (dirName, |
michael@0 | 486 | firstAnchorFileName, |
michael@0 | 487 | secondAnchorFileName, |
michael@0 | 488 | dateAscii, |
michael@0 | 489 | NULL, |
michael@0 | 490 | isCrlEnabled, |
michael@0 | 491 | plContext); |
michael@0 | 492 | |
michael@0 | 493 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetInitialPolicies |
michael@0 | 494 | (procParams, initialPolicies, plContext)); |
michael@0 | 495 | |
michael@0 | 496 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 497 | (PKIX_ProcessingParams_SetPolicyMappingInhibited |
michael@0 | 498 | (procParams, initialPolicyMappingInhibit, NULL)); |
michael@0 | 499 | |
michael@0 | 500 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetAnyPolicyInhibited |
michael@0 | 501 | (procParams, initialAnyPolicyInhibit, NULL)); |
michael@0 | 502 | |
michael@0 | 503 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 504 | (PKIX_ProcessingParams_SetExplicitPolicyRequired |
michael@0 | 505 | (procParams, initialExplicitPolicy, NULL)); |
michael@0 | 506 | |
michael@0 | 507 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_Create |
michael@0 | 508 | (procParams, chain, &valParams, plContext)); |
michael@0 | 509 | |
michael@0 | 510 | cleanup: |
michael@0 | 511 | |
michael@0 | 512 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 513 | PKIX_TEST_DECREF_AC(valParams); |
michael@0 | 514 | } |
michael@0 | 515 | |
michael@0 | 516 | PKIX_TEST_DECREF_AC(procParams); |
michael@0 | 517 | |
michael@0 | 518 | PKIX_TEST_RETURN(); |
michael@0 | 519 | |
michael@0 | 520 | return (valParams); |
michael@0 | 521 | } |
michael@0 | 522 | |
michael@0 | 523 | PKIX_ValidateResult * |
michael@0 | 524 | createValidateResult( |
michael@0 | 525 | char *dirName, |
michael@0 | 526 | char *anchorFileName, |
michael@0 | 527 | char *pubKeyCertFileName, |
michael@0 | 528 | void *plContext) |
michael@0 | 529 | { |
michael@0 | 530 | |
michael@0 | 531 | PKIX_TrustAnchor *anchor = NULL; |
michael@0 | 532 | PKIX_ValidateResult *valResult = NULL; |
michael@0 | 533 | PKIX_PL_Cert *cert = NULL; |
michael@0 | 534 | PKIX_PL_PublicKey *pubKey = NULL; |
michael@0 | 535 | |
michael@0 | 536 | PKIX_TEST_STD_VARS(); |
michael@0 | 537 | |
michael@0 | 538 | anchor = createTrustAnchor |
michael@0 | 539 | (dirName, anchorFileName, PKIX_FALSE, plContext); |
michael@0 | 540 | cert = createCert(dirName, pubKeyCertFileName, plContext); |
michael@0 | 541 | |
michael@0 | 542 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetSubjectPublicKey |
michael@0 | 543 | (cert, &pubKey, plContext)); |
michael@0 | 544 | |
michael@0 | 545 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 546 | (pkix_ValidateResult_Create |
michael@0 | 547 | (pubKey, anchor, NULL, &valResult, plContext)); |
michael@0 | 548 | |
michael@0 | 549 | cleanup: |
michael@0 | 550 | |
michael@0 | 551 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 552 | PKIX_TEST_DECREF_AC(valResult); |
michael@0 | 553 | } |
michael@0 | 554 | |
michael@0 | 555 | PKIX_TEST_DECREF_AC(anchor); |
michael@0 | 556 | PKIX_TEST_DECREF_AC(cert); |
michael@0 | 557 | PKIX_TEST_DECREF_AC(pubKey); |
michael@0 | 558 | |
michael@0 | 559 | PKIX_TEST_RETURN(); |
michael@0 | 560 | |
michael@0 | 561 | return (valResult); |
michael@0 | 562 | } |
michael@0 | 563 | |
michael@0 | 564 | PKIX_PL_GeneralName * |
michael@0 | 565 | createGeneralName( |
michael@0 | 566 | PKIX_UInt32 nameType, |
michael@0 | 567 | char *asciiName, |
michael@0 | 568 | void *plContext) |
michael@0 | 569 | { |
michael@0 | 570 | |
michael@0 | 571 | PKIX_PL_GeneralName *generalName = NULL; |
michael@0 | 572 | PKIX_PL_String *plString = NULL; |
michael@0 | 573 | |
michael@0 | 574 | PKIX_TEST_STD_VARS(); |
michael@0 | 575 | |
michael@0 | 576 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create |
michael@0 | 577 | (PKIX_ESCASCII, asciiName, 0, &plString, plContext)); |
michael@0 | 578 | |
michael@0 | 579 | PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_GeneralName_Create |
michael@0 | 580 | (nameType, plString, &generalName, plContext)); |
michael@0 | 581 | |
michael@0 | 582 | cleanup: |
michael@0 | 583 | |
michael@0 | 584 | PKIX_TEST_DECREF_AC(plString); |
michael@0 | 585 | |
michael@0 | 586 | PKIX_TEST_RETURN(); |
michael@0 | 587 | |
michael@0 | 588 | return (generalName); |
michael@0 | 589 | } |
michael@0 | 590 | |
michael@0 | 591 | PKIX_BuildResult * |
michael@0 | 592 | createBuildResult( |
michael@0 | 593 | char *dirName, |
michael@0 | 594 | char *anchorFileName, |
michael@0 | 595 | char *pubKeyCertFileName, |
michael@0 | 596 | char *firstChainCertFileName, |
michael@0 | 597 | char *secondChainCertFileName, |
michael@0 | 598 | void *plContext) |
michael@0 | 599 | { |
michael@0 | 600 | PKIX_BuildResult *buildResult = NULL; |
michael@0 | 601 | PKIX_ValidateResult *valResult = NULL; |
michael@0 | 602 | PKIX_List *certChain = NULL; |
michael@0 | 603 | |
michael@0 | 604 | PKIX_TEST_STD_VARS(); |
michael@0 | 605 | |
michael@0 | 606 | valResult = createValidateResult |
michael@0 | 607 | (dirName, anchorFileName, pubKeyCertFileName, plContext); |
michael@0 | 608 | certChain = createCertChain |
michael@0 | 609 | (dirName, |
michael@0 | 610 | firstChainCertFileName, |
michael@0 | 611 | secondChainCertFileName, |
michael@0 | 612 | plContext); |
michael@0 | 613 | |
michael@0 | 614 | PKIX_TEST_EXPECT_NO_ERROR |
michael@0 | 615 | (pkix_BuildResult_Create |
michael@0 | 616 | (valResult, certChain, &buildResult, plContext)); |
michael@0 | 617 | |
michael@0 | 618 | cleanup: |
michael@0 | 619 | |
michael@0 | 620 | if (PKIX_TEST_ERROR_RECEIVED){ |
michael@0 | 621 | PKIX_TEST_DECREF_AC(buildResult); |
michael@0 | 622 | } |
michael@0 | 623 | |
michael@0 | 624 | PKIX_TEST_DECREF_AC(valResult); |
michael@0 | 625 | PKIX_TEST_DECREF_AC(certChain); |
michael@0 | 626 | |
michael@0 | 627 | PKIX_TEST_RETURN(); |
michael@0 | 628 | |
michael@0 | 629 | return (buildResult); |
michael@0 | 630 | } |