00001
00010
00011 #include "AlgorithmIdentifier.h"
00012 #include "ASN1Helper.h"
00013 #include "Buffer.h"
00014 #include "Certificate.h"
00015 #include "CRL.h"
00016 #include "Duration.h"
00017 #include "IPKIFCryptoMisc.h"
00018 #include "IPKIFHashContext.h"
00019 #include "KeyUsage.h"
00020 #include "Name.h"
00021 #include "OID.h"
00022 #include "Period.h"
00023 #include "PKIFAlgorithm.h"
00024 #include "PKIFCertificatePath.h"
00025 #include "PKIFMediators.h"
00026 #include "PKIFCryptUtils.h"
00027 #include "PKIFPathSettings.h"
00028 #include "PKIFTime.h"
00029 #include "PolicyInformation.h"
00030 #include "ToolkitUtils.h"
00031
00032
00033 #include "PKIFSCVP.h"
00034 #include "private/SCVPUtils.h"
00035
00036
00037 #include "ContentInfo.h"
00038 #include "EncapsulatedContentInfo.h"
00039 #include "PKIFCMSUtils.h"
00040 #include "SignedData.h"
00041 #include "SignerInfo.h"
00042
00050 void PopulateKeyAgreePublicKey(CACX509V3AlgorithmIdentifier* objAlgID, CPKIFAlgorithmIdentifierPtr algID)
00051 {
00052 CPKIFStringPtr str(new std::string(algID->oid()->ToString()));
00053 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
00054 CopyOID(&objAlgID->algorithm, tmpOid);
00055
00056 if(NULL != tmpOid)
00057 delete tmpOid;
00058
00059 if(algID->hasParameters())
00060 {
00061 objAlgID->m.parametersPresent = 1;
00062
00063 objAlgID->parameters.data = algID->parameters()->GetBuffer();
00064 objAlgID->parameters.numocts = algID->parameters()->GetLength();
00065 }
00066 }
00074 void PopulateKeyUsage(
00076 CACX509V3KeyUsage* keyUsageStruct,
00078 CPKIFKeyUsagePtr& keyUsage)
00079 {
00080 int num = 0;
00081 if(keyUsage->DigitalSignature())
00082 {
00083 keyUsageStruct->data[0] |= BitMCACX509V3digitalSignature;
00084 if(num == 0 || num < 1)
00085 num = 1;
00086 }
00087 if(keyUsage->NonRepudiation())
00088 {
00089 keyUsageStruct->data[0] |= BitMCACX509V3nonRepudiation;
00090 if(num == 0 || num < 2)
00091 num = 2;
00092 }
00093 if(keyUsage->KeyEncipherment())
00094 {
00095 keyUsageStruct->data[0] |= BitMCACX509V3keyEncipherment;
00096 if(num == 0 || num > 3)
00097 num = 3;
00098 }
00099 if(keyUsage->DataEncipherment())
00100 {
00101 keyUsageStruct->data[0] |= BitMCACX509V3dataEncipherment;
00102 if(num == 0 || num < 4)
00103 num = 4;
00104 }
00105 if(keyUsage->KeyAgreement())
00106 {
00107 keyUsageStruct->data[0] |= BitMCACX509V3keyAgreement;
00108 if(num == 0 || num < 5)
00109 num = 5;
00110 }
00111 if(keyUsage->KeyCertSign())
00112 {
00113 keyUsageStruct->data[0] |= BitMCACX509V3keyCertSign;
00114 if(num == 0 || num < 6)
00115 num = 6;
00116 }
00117 if(keyUsage->CRLSign())
00118 {
00119 keyUsageStruct->data[0] |= BitMCACX509V3cRLSign;
00120 if(num == 0 || num < 7)
00121 num = 7;
00122 }
00123 if(keyUsage->EncipherOnly())
00124 {
00125 keyUsageStruct->data[0] |= BitMCACX509V3encipherOnly;
00126 if(num == 0 || num < 8)
00127 num = 8;
00128 }
00129 if(keyUsage->DecipherOnly())
00130 {
00131 keyUsageStruct->data[1] |= BitMCACX509V3decipherOnly;
00132 if(num == 0 || num < 9)
00133 num = 9;
00134 }
00135
00136 keyUsageStruct->numbits = num;
00137 }
00138
00139
00147 void PopulateValidationPolicy(ValidationPolicy* valPolResponse, CPKIFValidationPolicyPtr valPol, OOCTXT& ctxt)
00148 {
00149
00150
00151 CPKIFValidationPolRefPtr valPolRef = valPol->GetValidationPolRef();
00152 if(valPolRef == (CPKIFValidationPolRef*)NULL)
00153 {
00154 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "ValidationPolRef value not specified.");
00155 }
00156 else
00157 {
00158
00159 valPolResponse->validationPolRef.m.valPolParamsPresent = valPolRef->hasParameters();
00160 if(valPolRef->hasParameters())
00161 {
00162 valPolResponse->validationPolRef.valPolParams.data = valPolRef->parameters()->GetBuffer();
00163 valPolResponse->validationPolRef.valPolParams.numocts = valPolRef->parameters()->GetLength();
00164 }
00165 CPKIFStringPtr str2(new std::string(valPolRef->oid()->ToString()));
00166 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str2);
00167
00168 CopyOID(&valPolResponse->validationPolRef.valPolId, tmpOid);
00169 if(tmpOid != NULL)
00170 delete tmpOid;
00171 }
00172
00173
00174 CPKIFValidationAlgPtr valAlg = valPol->GetValidationAlg();
00175 if(valAlg != (CPKIFValidationAlg*)NULL)
00176 {
00177 valPolResponse->validationAlg.m.parametersPresent = valAlg->hasParameters();
00178 if(valAlg->hasParameters())
00179 {
00180 valPolResponse->validationAlg.parameters.data = valAlg->parameters()->GetBuffer();
00181 valPolResponse->validationAlg.parameters.numocts = valAlg->parameters()->GetLength();
00182 }
00183 CPKIFStringPtr str2(new std::string(valAlg->oid()->ToString()));
00184 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str2);
00185
00186 CopyOID(&valPolResponse->validationAlg.valAlgId, tmpOid);
00187 if(tmpOid != NULL)
00188 delete tmpOid;
00189
00190 valPolResponse->m.validationAlgPresent = 1;
00191 }
00192
00193 CPKIFPolicyInformationListPtr userPolicyList;
00194 valPol->GetInitialPolicySet(userPolicyList);
00195 if(userPolicyList != (CPKIFOIDList*)NULL && !userPolicyList->empty())
00196 {
00197 DListNode* curPol = NULL;
00198
00199 CPKIFPolicyInformationList::iterator oidPos;
00200 CPKIFPolicyInformationList::iterator oidEnd = userPolicyList->end();
00201 for(oidPos = userPolicyList->begin(); oidPos != oidEnd; ++oidPos)
00202 {
00203 if(NULL == curPol)
00204 {
00205 NEW_NODE(curPol)
00206 }
00207 else
00208 {
00209 NEW_NEXT_AND_ADVANCE(curPol)
00210 }
00211
00212 ASN1OBJID* tmpOid = new ASN1OBJID;
00213
00214 CPKIFStringPtr str(new std::string((*oidPos)->PolicyOID()->ToString()));
00215 ASN1OBJID* tmpOid2 = ConvertStringToASN1OBJID(str);
00216 CopyOID(tmpOid, tmpOid2);
00217
00218 if(NULL != tmpOid2)
00219 delete tmpOid2;
00220
00221 curPol->data = tmpOid;
00222
00223 SET_HEAD_TAIL_INCREMENT(valPolResponse->userPolicySet, curPol)
00224 }
00225 valPolResponse->m.userPolicySetPresent = 1;
00226 }
00227
00228
00229
00230 if(valPol->GetInitialPolicyMappingInhibitIndicator())
00231 {
00232 valPolResponse->inhibitPolicyMapping = true;
00233 valPolResponse->m.inhibitPolicyMappingPresent = 1;
00234 }
00235
00236 if(valPol->GetInitialExplicitPolicyIndicator())
00237 {
00238 valPolResponse->requireExplicitPolicy = true;
00239 valPolResponse->m.requireExplicitPolicyPresent = 1;
00240 }
00241
00242 if(valPol->GetInitialInhibitAnyPolicyIndicator())
00243 {
00244 valPolResponse->inhibitAnyPolicy = true;
00245 valPolResponse->m.inhibitAnyPolicyPresent = 1;
00246 }
00247
00248
00249 CPKIFPKCReferenceListPtr taList;
00250 valPol->GetTAs(taList);
00251 if(taList != (CPKIFPKCReferenceList*)NULL && !taList->empty())
00252 {
00253 DListNode* curTA = NULL;
00254
00255 CPKIFPKCReferenceList::iterator taPos;
00256 CPKIFPKCReferenceList::iterator taEnd = taList->end();
00257 for(taPos = taList->begin(); taPos != taEnd; ++taPos)
00258 {
00259 if(NULL == curTA)
00260 {
00261 NEW_NODE(curTA)
00262 }
00263 else
00264 {
00265 NEW_NEXT_AND_ADVANCE(curTA)
00266 }
00267
00268 PKCReference* tmpTA = new PKCReference;
00269 memset(tmpTA, 0, sizeof(PKCReference));
00270
00271 if((*taPos)->GetCert() != (CPKIFCertificate*)NULL)
00272 {
00273 tmpTA->t = T_PKCReference_cert;
00274
00275 tmpTA->u.cert = new CACX509V3Certificate;
00276 setBERDecBufPtr(&ctxt, (unsigned char*)(*taPos)->GetCert()->Encoded()->GetBuffer(), (*taPos)->GetCert()->Encoded()->GetLength(), NULL, NULL);
00277 BERDecCACX509V3Certificate(&ctxt, tmpTA->u.cert, ASN1EXPL, NULL);
00278
00279 }
00280 else
00281 {
00282 CPKIFSCVPCertIDPtr sCVPCertID = (*taPos)->GetSCVPCertID();
00283
00284 if(sCVPCertID != (CPKIFSCVPCertID*)NULL)
00285 {
00286 tmpTA->t = T_PKCReference_pkcRef;
00287
00288 tmpTA->u.pkcRef = new SCVPCertID;
00289 memset(tmpTA->u.pkcRef, 0, sizeof(SCVPCertID));
00290
00291
00292 tmpTA->u.pkcRef->certHash.data = sCVPCertID->GetCertHash()->GetBuffer();
00293 tmpTA->u.pkcRef->certHash.numocts = sCVPCertID->GetCertHash()->GetLength();
00294
00295 tmpTA->u.pkcRef->issuerSerial.serialNumber = new char[strlen(sCVPCertID->GetSerialNumber())];
00296 memcpy((void*)tmpTA->u.pkcRef->issuerSerial.serialNumber, sCVPCertID->GetSerialNumber(),
00297 strlen(sCVPCertID->GetSerialNumber()));
00298
00299 CPKIFGeneralNameListPtr nameList;
00300 sCVPCertID->GetIssuerName(nameList);
00301 if(nameList == (CPKIFGeneralNameList*)NULL)
00302 {
00303 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "Issuer Names value not specified.");
00304 }
00305 DListNode* curName = NULL;
00306 CPKIFGeneralNameList::iterator namePos;
00307 CPKIFGeneralNameList::iterator nameEnd = nameList->end();
00308 for(namePos = nameList->begin(); namePos != nameEnd; ++namePos)
00309 {
00310
00311 if(NULL == curName)
00312 {
00313 NEW_NODE(curName)
00314 }
00315 else
00316 {
00317 NEW_NEXT_AND_ADVANCE(curName)
00318 }
00319
00320 CACX509V3GeneralName *name = new CACX509V3GeneralName;
00321 memset(name, 0, sizeof(CACX509V3GeneralName));
00322
00323 CopyGeneralName((*name), (*namePos));
00324
00325 curName->data = name;
00326
00327 SET_HEAD_TAIL_INCREMENT(tmpTA->u.pkcRef->issuerSerial.issuer, curName)
00328 }
00329
00330 CPKIFAlgorithmIdentifierPtr algID = sCVPCertID->GetHashAlgorithm();
00331 if(algID != (CPKIFAlgorithmIdentifier*)NULL)
00332 {
00333 CPKIFStringPtr str(new std::string(algID->oid()->ToString()));
00334 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
00335 CopyOID(&tmpTA->u.pkcRef->hashAlgorithm.algorithm, tmpOid);
00336
00337 if(NULL != tmpOid)
00338 delete tmpOid;
00339
00340 if(algID->hasParameters())
00341 {
00342 tmpTA->u.pkcRef->hashAlgorithm.m.parametersPresent = 1;
00343
00344 tmpTA->u.pkcRef->hashAlgorithm.parameters.data = algID->parameters()->GetBuffer();
00345 tmpTA->u.pkcRef->hashAlgorithm.parameters.numocts = algID->parameters()->GetLength();
00346 }
00347 tmpTA->u.pkcRef->m.hashAlgorithmPresent = 1;
00348 }
00349
00350
00351 }
00352 }
00353
00354 curTA->data = tmpTA;
00355
00356 SET_HEAD_TAIL_INCREMENT(valPolResponse->trustAnchors, curTA)
00357 }
00358 valPolResponse->m.trustAnchorsPresent = 1;
00359 }
00360
00361
00362 CPKIFKeyUsageListPtr keyUsageList;
00363 valPol->GetKeyUsages(keyUsageList);
00364 if(keyUsageList != (CPKIFKeyUsageList*)NULL && !keyUsageList->empty())
00365 {
00366 DListNode* curKeyUsage = NULL;
00367
00368 CPKIFKeyUsageList::iterator keyUsagePos;
00369 CPKIFKeyUsageList::iterator keyUsageEnd = keyUsageList->end();
00370 for(keyUsagePos = keyUsageList->begin(); keyUsagePos != keyUsageEnd; ++keyUsagePos)
00371 {
00372 if(NULL == curKeyUsage)
00373 {
00374 NEW_NODE(curKeyUsage)
00375 }
00376 else
00377 {
00378 NEW_NEXT_AND_ADVANCE(curKeyUsage)
00379 }
00380
00381 CACX509V3KeyUsage* tmpKeyUsage = new CACX509V3KeyUsage;
00382 memset(tmpKeyUsage, 0, sizeof(CACX509V3KeyUsage));
00383
00384 PopulateKeyUsage(tmpKeyUsage, (*keyUsagePos));
00385
00386
00387 curKeyUsage->data = tmpKeyUsage;
00388
00389 SET_HEAD_TAIL_INCREMENT(valPolResponse->keyUsages, curKeyUsage)
00390 }
00391 valPolResponse->m.keyUsagesPresent = 1;
00392 }
00393
00394
00395 CPKIFOIDListPtr eKUList;
00396 valPol->GetEKUs(eKUList);
00397 PopulateDListWithASN1OBJID(&valPolResponse->extendedKeyUsages, eKUList);
00398 if(eKUList != (CPKIFOIDList*)NULL && !eKUList->empty())
00399 {
00400 valPolResponse->m.extendedKeyUsagesPresent = 1;
00401 }
00402
00403
00404 CPKIFOIDListPtr sKUList;
00405 valPol->GetSKUs(sKUList);
00406 PopulateDListWithASN1OBJID(&valPolResponse->specifiedKeyUsages, sKUList);
00407 if(sKUList != (CPKIFOIDList*)NULL && !sKUList->empty())
00408 {
00409 valPolResponse->m.specifiedKeyUsagesPresent = 1;
00410 }
00411
00412 }
00413
00421 CPKIFGeneralNameListPtr PopulatePKIFGeneralNameList(DList* list)
00422 {
00423 CPKIFGeneralNameListPtr tmpList(new CPKIFGeneralNameList());
00424 DListNode* cur = list->head;
00425 while(NULL != cur)
00426 {
00427 CACX509V3GeneralName* tmp = (CACX509V3GeneralName*)cur->data;
00428 CACASNWRAPPER_CREATE(CACX509V3GeneralName, objPDU);
00429 ASN1OpenType* data1 = objPDU.Encode(tmp);
00430 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00431 CPKIFGeneralNamePtr tmpName(new CPKIFGeneralName(tmpBuf));
00432
00433 if(NULL != data1)
00434 delete data1;
00435
00436 tmpList->push_back(tmpName);
00437
00438 cur = cur->next;
00439 }
00440 return tmpList;
00441 }
00442
00450 CPKIFOIDListPtr PopulatePKIFOIDList(DList* list)
00451 {
00452 CPKIFOIDListPtr tmpList(new CPKIFOIDList());
00453 DListNode* cur = list->head;
00454 while(NULL != cur)
00455 {
00456 ASN1OBJID* tmp = (ASN1OBJID*)cur->data;
00457 CPKIFOIDPtr tmpOID(new CPKIFOID(tmp->subid, tmp->numids));
00458 tmpList->push_back(tmpOID);
00459 cur = cur->next;
00460 }
00461 return tmpList;
00462 }
00470 void PopulateDListWithCACX509V3GeneralName(DList* list, CPKIFGeneralNameListPtr pkifGenNameList)
00471 {
00472 if(pkifGenNameList != (CPKIFGeneralNameList*)NULL && !pkifGenNameList->empty())
00473 {
00474 DListNode* curName = NULL;
00475 CPKIFGeneralNameList::iterator namePos;
00476 CPKIFGeneralNameList::iterator nameEnd = pkifGenNameList->end();
00477 for(namePos = pkifGenNameList->begin(); namePos != nameEnd; ++namePos)
00478 {
00479 if(NULL == curName)
00480 {
00481 NEW_NODE(curName)
00482 }
00483 else
00484 {
00485 NEW_NEXT_AND_ADVANCE(curName)
00486 }
00487
00488 CACX509V3GeneralName* tmpName= new CACX509V3GeneralName;
00489 memset(tmpName, 0, sizeof(CACX509V3GeneralName));
00490
00491
00492 CopyGeneralName((*tmpName), (*namePos));
00493
00494 curName->data = tmpName;
00495
00496 SET_HEAD_TAIL_INCREMENT((*list), curName)
00497 }
00498
00499 }
00500 }
00501
00509 void PopulateDListWithASN1OBJID(DList* list, CPKIFOIDListPtr pkifOIDList)
00510 {
00511 if(pkifOIDList != (CPKIFOIDList*)NULL && !pkifOIDList->empty())
00512 {
00513 DListNode* cur = NULL;
00514
00515 CPKIFOIDList::iterator pos;
00516 CPKIFOIDList::iterator end = pkifOIDList->end();
00517 for(pos = pkifOIDList->begin(); pos != end; ++pos)
00518 {
00519 if(NULL == cur)
00520 {
00521 NEW_NODE(cur)
00522 }
00523 else
00524 {
00525 NEW_NEXT_AND_ADVANCE(cur)
00526 }
00527
00528 ASN1OBJID* tmpOID = new ASN1OBJID;
00529 memset(tmpOID, 0, sizeof(ASN1OBJID));
00530
00531 CPKIFStringPtr str(new std::string((*pos)->ToString()));
00532 ASN1OBJID* tmpOid2 = ConvertStringToASN1OBJID(str);
00533 CopyOID(tmpOID, tmpOid2);
00534
00535 if(NULL != tmpOid2)
00536 delete tmpOid2;
00537
00538 cur->data = tmpOID;
00539
00540 SET_HEAD_TAIL_INCREMENT((*list), cur)
00541 }
00542 }
00543 }
00544
00545
00553 void PopulateDListWithCACX509V3AlgorithmIdentifier(DList* list, CPKIFAlgorithmIdentifierListPtr pkifOIDList)
00554 {
00555 if(pkifOIDList!= (CPKIFAlgorithmIdentifierList*)NULL && !pkifOIDList->empty())
00556 {
00557 DListNode* cur = NULL;
00558
00559 CPKIFAlgorithmIdentifierList::iterator pos;
00560 CPKIFAlgorithmIdentifierList::iterator end = pkifOIDList->end();
00561 for(pos = pkifOIDList->begin(); pos != end; ++pos)
00562 {
00563 if(NULL == cur)
00564 {
00565 NEW_NODE(cur)
00566 }
00567 else
00568 {
00569 NEW_NEXT_AND_ADVANCE(cur)
00570 }
00571 CACX509V3AlgorithmIdentifier* tmpAlgID = new CACX509V3AlgorithmIdentifier;
00572 memset(tmpAlgID, 0, sizeof(CACX509V3AlgorithmIdentifier));
00573
00574 CPKIFStringPtr str(new std::string((*pos)->oid()->ToString()));
00575 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
00576 CopyOID(&tmpAlgID->algorithm, tmpOid);
00577
00578 if(NULL != tmpOid)
00579 delete tmpOid;
00580
00581 if((*pos)->hasParameters())
00582 {
00583 tmpAlgID->m.parametersPresent = 1;
00584
00585 tmpAlgID->parameters.data = (*pos)->parameters()->GetBuffer();
00586 tmpAlgID->parameters.numocts = (*pos)->parameters()->GetLength();
00587 }
00588
00589 cur->data = tmpAlgID;
00590
00591 SET_HEAD_TAIL_INCREMENT((*list), cur)
00592 }
00593 }
00594 }
00595
00603 CPKIFAlgorithmIdentifierListPtr PopulatePKIFAlgorithmIdentifierList(DList* list)
00604 {
00605
00606 CPKIFAlgorithmIdentifierListPtr tmpList(new CPKIFAlgorithmIdentifierList());
00607 DListNode* cur = list->head;
00608 while(NULL != cur)
00609 {
00610
00611 CACX509V3AlgorithmIdentifier* tmp = (CACX509V3AlgorithmIdentifier*)cur->data;
00612 CPKIFOIDPtr algOID(new CPKIFOID(tmp->algorithm.subid, tmp->algorithm.numids));
00613
00614 CPKIFBufferPtr algParams;
00615 if(tmp->m.parametersPresent == 1)
00616 {
00617 CPKIFBufferPtr tmpAlgParams(new CPKIFBuffer(tmp->parameters.data, tmp->parameters.numocts));
00618
00619 algParams = tmpAlgParams;
00620 }
00621 CPKIFAlgorithmIdentifierPtr tmpAlg(new CPKIFAlgorithmIdentifier(algOID, algParams));
00622
00623 tmpList->push_back(tmpAlg);
00624 cur = cur->next;
00625 }
00626
00627 return tmpList;
00628 }
00629
00637 void PopulateACReference(ACReference* pACReference, CPKIFACReferencePtr& acRef, OOCTXT& ctxt)
00638 {
00639
00640 if(NULL == pACReference)
00641 {
00642 throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00643 }
00644
00645 if(acRef->GetACCert() != (CPKIFBuffer*)NULL)
00646 {
00647 pACReference->t = T_ACReference_attrCert;
00648
00649 pACReference->u.attrCert = new AttributeCertificate;
00650
00651 setBERDecBufPtr(&ctxt, (unsigned char*)acRef->GetACCert()->GetBuffer(), acRef->GetACCert()->GetLength(), NULL, NULL);
00652 BERDecAttributeCertificate(&ctxt, pACReference->u.attrCert, ASN1EXPL, NULL);
00653
00654
00655 }
00656 else if(acRef->GetSCVPCertID() != (CPKIFSCVPCertIDPtr*)NULL)
00657 {
00658 CPKIFSCVPCertIDPtr sCVPCertID = acRef->GetSCVPCertID();
00659
00660 if(sCVPCertID != (CPKIFSCVPCertID*)NULL)
00661 {
00662 pACReference->t = T_ACReference_acRef;
00663
00664 pACReference->u.acRef = new SCVPCertID;
00665 memset(pACReference->u.acRef, 0, sizeof(SCVPCertID));
00666
00667
00668 pACReference->u.acRef->certHash.data = sCVPCertID->GetCertHash()->GetBuffer();
00669 pACReference->u.acRef->certHash.numocts = sCVPCertID->GetCertHash()->GetLength();
00670
00671 pACReference->u.acRef->issuerSerial.serialNumber = new char[strlen(sCVPCertID->GetSerialNumber())];
00672 memcpy((void*)pACReference->u.acRef->issuerSerial.serialNumber, sCVPCertID->GetSerialNumber(),
00673 strlen(sCVPCertID->GetSerialNumber()));
00674
00675 CPKIFGeneralNameListPtr nameList;
00676 sCVPCertID->GetIssuerName(nameList);
00677 if(nameList == (CPKIFGeneralNameList*)NULL)
00678 {
00679 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "Issuer Names value not specified.");
00680 }
00681 DListNode* curName = NULL;
00682 CPKIFGeneralNameList::iterator namePos;
00683 CPKIFGeneralNameList::iterator nameEnd = nameList->end();
00684 for(namePos = nameList->begin(); namePos != nameEnd; ++namePos)
00685 {
00686
00687 if(NULL == curName)
00688 {
00689 NEW_NODE(curName)
00690 }
00691 else
00692 {
00693 NEW_NEXT_AND_ADVANCE(curName)
00694 }
00695
00696 CACX509V3GeneralName *name = new CACX509V3GeneralName;
00697 memset(name, 0, sizeof(CACX509V3GeneralName));
00698
00699 CopyGeneralName((*name), (*namePos));
00700
00701 curName->data = name;
00702
00703 SET_HEAD_TAIL_INCREMENT(pACReference->u.acRef->issuerSerial.issuer, curName)
00704 }
00705
00706 CPKIFAlgorithmIdentifierPtr algID = sCVPCertID->GetHashAlgorithm();
00707 if(algID != (CPKIFAlgorithmIdentifier*)NULL)
00708 {
00709 CPKIFStringPtr str(new std::string(algID->oid()->ToString()));
00710 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
00711 CopyOID(&pACReference->u.acRef->hashAlgorithm.algorithm, tmpOid);
00712
00713 if(NULL != tmpOid)
00714 delete tmpOid;
00715
00716 if(algID->hasParameters())
00717 {
00718 pACReference->u.acRef->hashAlgorithm.m.parametersPresent = 1;
00719
00720 pACReference->u.acRef->hashAlgorithm.parameters.data = algID->parameters()->GetBuffer();
00721 pACReference->u.acRef->hashAlgorithm.parameters.numocts = algID->parameters()->GetLength();
00722 }
00723 pACReference->u.acRef->m.hashAlgorithmPresent = 1;
00724 }
00725
00726
00727 }
00728 }
00729 }
00737 void PopulatePKCReference(
00739 PKCReference* pkcReferenceStruct,
00741 CPKIFPKCReferencePtr& pkcRef,
00742 OOCTXT& ctxt)
00743 {
00744
00745 if(NULL == pkcReferenceStruct)
00746 {
00747 throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00748 }
00749
00750 if(pkcRef->GetCert() != (CPKIFCertificate*)NULL)
00751 {
00752 pkcReferenceStruct->t = T_PKCReference_cert;
00753
00754 pkcReferenceStruct->u.cert = new CACX509V3Certificate;
00755 setBERDecBufPtr(&ctxt, (unsigned char*)pkcRef->GetCert()->Encoded()->GetBuffer(), pkcRef->GetCert()->Encoded()->GetLength(), NULL, NULL);
00756 BERDecCACX509V3Certificate(&ctxt, pkcReferenceStruct->u.cert, ASN1EXPL, NULL);
00757 }
00758 else if(pkcRef->GetSCVPCertID() != (CPKIFSCVPCertIDPtr*)NULL)
00759 {
00760 CPKIFSCVPCertIDPtr sCVPCertID = pkcRef->GetSCVPCertID();
00761
00762 if(sCVPCertID != (CPKIFSCVPCertID*)NULL)
00763 {
00764 pkcReferenceStruct->t = T_PKCReference_pkcRef;
00765
00766 pkcReferenceStruct->u.pkcRef = new SCVPCertID;
00767 memset(pkcReferenceStruct->u.pkcRef, 0, sizeof(SCVPCertID));
00768
00769
00770 pkcReferenceStruct->u.pkcRef->certHash.data = sCVPCertID->GetCertHash()->GetBuffer();
00771 pkcReferenceStruct->u.pkcRef->certHash.numocts = sCVPCertID->GetCertHash()->GetLength();
00772
00773 pkcReferenceStruct->u.pkcRef->issuerSerial.serialNumber = new char[strlen(sCVPCertID->GetSerialNumber()) + 1];
00774 memcpy((void*)pkcReferenceStruct->u.pkcRef->issuerSerial.serialNumber, sCVPCertID->GetSerialNumber(),
00775 strlen(sCVPCertID->GetSerialNumber()) + 1);
00776
00777 CPKIFGeneralNameListPtr nameList;
00778 sCVPCertID->GetIssuerName(nameList);
00779 if(nameList == (CPKIFGeneralNameList*)NULL)
00780 {
00781 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "Issuer Names value not specified.");
00782 }
00783 DListNode* curName = NULL;
00784 CPKIFGeneralNameList::iterator namePos;
00785 CPKIFGeneralNameList::iterator nameEnd = nameList->end();
00786 for(namePos = nameList->begin(); namePos != nameEnd; ++namePos)
00787 {
00788
00789 if(NULL == curName)
00790 {
00791 NEW_NODE(curName)
00792 }
00793 else
00794 {
00795 NEW_NEXT_AND_ADVANCE(curName)
00796 }
00797
00798 CACX509V3GeneralName *name = new CACX509V3GeneralName;
00799 memset(name, 0, sizeof(CACX509V3GeneralName));
00800
00801 CopyGeneralName((*name), (*namePos));
00802
00803 curName->data = name;
00804
00805 SET_HEAD_TAIL_INCREMENT(pkcReferenceStruct->u.pkcRef->issuerSerial.issuer, curName)
00806 }
00807
00808 CPKIFAlgorithmIdentifierPtr algID = sCVPCertID->GetHashAlgorithm();
00809 if(algID != (CPKIFAlgorithmIdentifier*)NULL)
00810 {
00811 CPKIFStringPtr str(new std::string(algID->oid()->ToString()));
00812 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
00813 CopyOID(&pkcReferenceStruct->u.pkcRef->hashAlgorithm.algorithm, tmpOid);
00814
00815 if(NULL != tmpOid)
00816 delete tmpOid;
00817
00818 if(algID->hasParameters())
00819 {
00820 pkcReferenceStruct->u.pkcRef->hashAlgorithm.m.parametersPresent = 1;
00821
00822 pkcReferenceStruct->u.pkcRef->hashAlgorithm.parameters.data = algID->parameters()->GetBuffer();
00823 pkcReferenceStruct->u.pkcRef->hashAlgorithm.parameters.numocts = algID->parameters()->GetLength();
00824 }
00825 pkcReferenceStruct->u.pkcRef->m.hashAlgorithmPresent = 1;
00826 }
00827
00828
00829 }
00830 }
00831 }
00832
00840 void PopulateQuery(
00842 Query* queryOut,
00844 CPKIFQueryPtr query,
00845 OOCTXT& ctxt
00846 )
00847 {
00848
00849 if(query == (CPKIFQuery*)NULL)
00850 {
00851 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "Query value not specified.");
00852 }
00853
00854 PopulateValidationPolicy(&queryOut->validationPolicy, query->GetValidationPolicy(), ctxt);
00855
00856
00857 CPKIFCertReferencesPtr certReferences;
00858 query->GetCertRef(certReferences);
00859 if(certReferences != (CPKIFCertReferences*)NULL)
00860 {
00861 CPKIFPKCReferenceListPtr pkcReferenceList;
00862 certReferences->GetPKCList(pkcReferenceList);
00863 CPKIFACReferenceListPtr acReferenceList;
00864 certReferences->GetACList(acReferenceList);
00865 if(pkcReferenceList != (CPKIFPKCReferenceList*)NULL)
00866 {
00867 queryOut->queriedCerts.t = T_CertReferences_pkcRefs;
00868 queryOut->queriedCerts.u.pkcRefs = new CertReferences_pkcRefs;
00869 memset(queryOut->queriedCerts.u.pkcRefs, 0, sizeof(CertReferences_pkcRefs));
00870
00871 DListNode* curCertRef = NULL;
00872 CPKIFPKCReferenceList::iterator certRefPos;
00873 CPKIFPKCReferenceList::iterator certRefEnd = pkcReferenceList->end();
00874 for(certRefPos = pkcReferenceList->begin(); certRefPos != certRefEnd; ++certRefPos)
00875 {
00876 if(NULL == curCertRef)
00877 {
00878 NEW_NODE(curCertRef)
00879 }
00880 else
00881 {
00882 NEW_NEXT_AND_ADVANCE(curCertRef)
00883 }
00884
00885 PKCReference* tmpCertRef = new PKCReference;
00886 memset(tmpCertRef, 0, sizeof(PKCReference));
00887
00888 PopulatePKCReference(tmpCertRef, (*certRefPos), ctxt);
00889
00890 curCertRef->data = tmpCertRef;
00891
00892 SET_HEAD_TAIL_INCREMENT((*queryOut->queriedCerts.u.pkcRefs), curCertRef)
00893 }
00894 }
00895 else if(acReferenceList != (CPKIFACReferenceList*)NULL)
00896 {
00897 queryOut->queriedCerts.t = T_CertReferences_acRefs;
00898 queryOut->queriedCerts.u.acRefs = new CertReferences_acRefs;
00899 memset(queryOut->queriedCerts.u.acRefs, 0, sizeof(CertReferences_acRefs));
00900
00901 DListNode* curCertRef = NULL;
00902 CPKIFACReferenceList::iterator acRefPos;
00903 CPKIFACReferenceList::iterator acRefEnd = acReferenceList->end();
00904 for(acRefPos = acReferenceList->begin(); acRefEnd != acRefEnd; ++acRefPos)
00905 {
00906 if(NULL == curCertRef)
00907 {
00908 NEW_NODE(curCertRef)
00909 }
00910 else
00911 {
00912 NEW_NEXT_AND_ADVANCE(curCertRef)
00913 }
00914
00915 ACReference* tmpACRef = new ACReference;
00916 memset(tmpACRef, 0, sizeof(ACReference));
00917
00918 PopulateACReference(tmpACRef, (*acRefPos), ctxt);
00919
00920 curCertRef->data = tmpACRef;
00921
00922 SET_HEAD_TAIL_INCREMENT((*queryOut->queriedCerts.u.acRefs), curCertRef)
00923 }
00924 }
00925
00926 }
00927
00928
00929
00930 CPKIFOIDListPtr checksList;
00931 query->GetChecks(checksList);
00932 if(checksList == (CPKIFQuery*)NULL || checksList->empty())
00933 {
00934 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "checks value not specified.");
00935 }
00936 else
00937 {
00938 PopulateDListWithASN1OBJID(&queryOut->checks, checksList);
00939 }
00940
00941
00942 CPKIFOIDListPtr wantBackList;
00943 query->GetWantBack(wantBackList);
00944 PopulateDListWithASN1OBJID(&queryOut->wantBack, wantBackList);
00945 if(wantBackList != (CPKIFOIDList*)NULL && !wantBackList->empty())
00946 {
00947
00948 queryOut->m.wantBackPresent = 1;
00949 }
00950
00951
00952 CPKIFResponseFlagsPtr resFlags = query->GetResponseFlags();
00953 if(resFlags != (CPKIFResponseFlags*)NULL)
00954 {
00955 if(!(resFlags->DefaultsSet()))
00956 {
00957 queryOut->responseFlags.cachedResponse = resFlags->GetCachedResponse();
00958 queryOut->responseFlags.fullRequestInResponse = resFlags->GetFullRequestInResponse();
00959 queryOut->responseFlags.protectResponse = resFlags->GetProtectResponse();
00960 queryOut->responseFlags.responseValidationPolByRef = resFlags->GetResponseValidationPolByRef();
00961 }
00962
00963 queryOut->m.responseFlagsPresent = 1;
00964 }
00965
00966
00967 CPKIFBufferPtr serverContextInfo = query->GetServerContextInfo();
00968 if(serverContextInfo != (CPKIFBuffer*)NULL)
00969 {
00970 queryOut->serverContextInfo.data = serverContextInfo->GetBuffer();
00971 queryOut->serverContextInfo.numocts = serverContextInfo->GetLength();
00972 queryOut->m.serverContextInfoPresent = 1;
00973 }
00974
00975
00976
00977 CPKIFTimePtr valTime = query->GetValidationTime();
00978 if(valTime != (CPKIFTime*)NULL)
00979 {
00980 queryOut->validationTime = valTime->GetTime();
00981
00982 queryOut->m.validationTimePresent = 1;
00983 }
00984
00985
00986 CPKIFTimePtr producedAtTime = query->GetProducedAt();
00987 if(producedAtTime != (CPKIFTime*)NULL)
00988 {
00989 queryOut->producedAt = producedAtTime->GetTime();
00990
00991 queryOut->m.producedAtPresent = 1;
00992 }
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002 CPKIFCertificateListPtr certList;
01003 query->GetCertBundle(certList);
01004
01005 if(certList != (CPKIFCertificateList*)NULL && !certList->empty())
01006 {
01007 DListNode* curCert = NULL;
01008 CPKIFCertificateList::iterator certPos;
01009 CPKIFCertificateList::iterator certEnd = certList->end();
01010 for(certPos = certList->begin(); certPos != certEnd; ++certPos)
01011 {
01012 if(NULL == curCert)
01013 {
01014 NEW_NODE(curCert)
01015 }
01016 else
01017 {
01018 NEW_NEXT_AND_ADVANCE(curCert)
01019 }
01020
01021 ASN1OpenType* tmpCert = new ASN1OpenType;
01022 memset(tmpCert, 0, sizeof(ASN1OpenType));
01023
01024
01025 tmpCert->data = (*certPos)->Encoded()->GetBuffer();
01026 tmpCert->numocts = (*certPos)->Encoded()->GetLength();
01027
01028 curCert->data = tmpCert;
01029
01030 SET_HEAD_TAIL_INCREMENT(queryOut->intermediateCerts, curCert)
01031 }
01032
01033 queryOut->m.intermediateCertsPresent = 1;
01034 }
01035
01036
01037 CPKIFRevocationInfoListPtr revInfoList;
01038 query->GetRevInfos(revInfoList);
01039
01040 if(revInfoList != (CPKIFRevocationInfoList*)NULL && !revInfoList->empty())
01041 {
01042 DListNode* curRevInfo = NULL;
01043 CPKIFRevocationInfoList::iterator revInfoPos;
01044 CPKIFRevocationInfoList::iterator revInfoEnd = revInfoList->end();
01045 for(revInfoPos = revInfoList->begin(); revInfoPos != revInfoEnd; ++revInfoPos)
01046 {
01047 if(NULL == curRevInfo)
01048 {
01049 NEW_NODE(curRevInfo)
01050 }
01051 else
01052 {
01053 NEW_NEXT_AND_ADVANCE(curRevInfo)
01054 }
01055
01056 if((*revInfoPos)->GetCRL() != (CPKIFCRL*)NULL)
01057 {
01058 RevocationInfo* tmpCRL = new RevocationInfo;
01059 memset(tmpCRL, 0, sizeof(RevocationInfo));
01060
01061 tmpCRL->t = T_RevocationInfo_crl;
01062
01063
01064 tmpCRL->u.crl = new CACX509V3CertificateList;
01065 memset(tmpCRL->u.crl, 0, sizeof(CACX509V3CertificateList));
01066
01067 setBERDecBufPtr(&ctxt, (unsigned char*)(*revInfoPos)->GetCRL()->Encoded()->GetBuffer(), (*revInfoPos)->GetCRL()->Encoded()->GetLength(), NULL, NULL);
01068 BERDecCACX509V3CertificateList(&ctxt, tmpCRL->u.crl, ASN1EXPL, NULL);
01069
01070 curRevInfo->data = tmpCRL;
01071 }
01072 else if((*revInfoPos)->GetDeltaCRL() != (CPKIFCRL*)NULL)
01073 {
01074 RevocationInfo* tmpDeltaCRL = new RevocationInfo;
01075 memset(tmpDeltaCRL, 0, sizeof(RevocationInfo));
01076
01077 tmpDeltaCRL->t = T_RevocationInfo_delta_crl;
01078
01079 tmpDeltaCRL->u.delta_crl = new CACX509V3CertificateList;
01080 memset(tmpDeltaCRL->u.delta_crl, 0, sizeof(CACX509V3CertificateList));
01081
01082 setBERDecBufPtr(&ctxt, (unsigned char*)(*revInfoPos)->GetDeltaCRL()->Encoded()->GetBuffer(), (*revInfoPos)->GetDeltaCRL()->Encoded()->GetLength(), NULL, NULL);
01083 BERDecCACX509V3CertificateList(&ctxt, tmpDeltaCRL->u.delta_crl, ASN1EXPL, NULL);
01084
01085 curRevInfo->data = tmpDeltaCRL;
01086 }
01087 else if((*revInfoPos)->GetOCSPResp() != (CPKIFBuffer*)NULL)
01088 {
01089 RevocationInfo* tmpOCSPResp = new RevocationInfo;
01090 memset(tmpOCSPResp, 0, sizeof(RevocationInfo));
01091
01092 tmpOCSPResp->t = T_RevocationInfo_ocsp;
01093
01094 tmpOCSPResp->u.ocsp = new OCSPResponse;
01095 memset(tmpOCSPResp->u.ocsp, 0, sizeof(OCSPResponse));
01096
01097 setBERDecBufPtr(&ctxt, (unsigned char*)(*revInfoPos)->GetOCSPResp()->GetBuffer(), (*revInfoPos)->GetOCSPResp()->GetLength(), NULL, NULL);
01098 BERDecOCSPResponse(&ctxt, tmpOCSPResp->u.ocsp, ASN1EXPL, NULL);
01099
01100
01101 curRevInfo->data = tmpOCSPResp;
01102 }
01103 else
01104 {
01105 RevocationInfo* tmpOther = new RevocationInfo;
01106 memset(tmpOther, 0, sizeof(RevocationInfo));
01107
01108 tmpOther->t = T_RevocationInfo_other;
01109 tmpOther->u.other = new OtherRevInfo;
01110
01111 CPKIFOIDPtr oid;
01112 CPKIFBufferPtr buf;
01113 (*revInfoPos)->GetOtherRevInfo(oid, buf);
01114
01115 CPKIFStringPtr str(new std::string(oid->ToString()));
01116 ASN1OBJID* tmpOid2 = ConvertStringToASN1OBJID(str);
01117 CopyOID(&tmpOther->u.other->riType, tmpOid2);
01118
01119 if(NULL != tmpOid2)
01120 delete tmpOid2;
01121
01122 tmpOther->u.other->riValue.data = (*revInfoPos)->GetOCSPResp()->GetBuffer();
01123 tmpOther->u.other->riValue.numocts = (*revInfoPos)->GetOCSPResp()->GetLength();
01124
01125 curRevInfo->data = tmpOther;
01126
01127 }
01128
01129
01130 SET_HEAD_TAIL_INCREMENT(queryOut->revInfos, curRevInfo)
01131 }
01132
01133 queryOut->m.revInfosPresent = 1;
01134 }
01135
01136
01137 }
01138
01146 void PopulateReplyObjects(
01148 ReplyObjects* list,
01150 CPKIFCertReplyListPtr& replyObjects,
01151 OOCTXT &ctxt)
01152 {
01153 if(replyObjects != (CPKIFCertReplyList*)NULL && !replyObjects->empty())
01154 {
01155 DListNode* curReply = NULL;
01156 CPKIFCertReplyList::iterator replyPos;
01157 CPKIFCertReplyList::iterator replyEnd = replyObjects->end();
01158 for(replyPos = replyObjects->begin(); replyPos != replyEnd; ++replyPos)
01159 {
01160 if(NULL == curReply)
01161 {
01162 NEW_NODE(curReply)
01163 }
01164 else
01165 {
01166 NEW_NEXT_AND_ADVANCE(curReply)
01167 }
01168
01169 CertReply* tmpReply= new CertReply;
01170 memset(tmpReply, 0, sizeof(CertReply));
01171
01172
01173
01174
01175 CPKIFCertReferencePtr certRef = (*replyPos)->GetCertRef();
01176
01177 if(certRef == (CPKIFCertReference*)NULL)
01178 {
01179 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "CertReference value not specified.");
01180 }
01181
01182 if(certRef->GetPKC() != (CPKIFPKCReference*)NULL)
01183 {
01184 tmpReply->cert.t = T_CertReference_pkc;
01185 tmpReply->cert.u.pkc = new PKCReference;
01186 memset(tmpReply->cert.u.pkc, 0, sizeof(PKCReference));
01187
01188 CPKIFPKCReferencePtr pkcRef = certRef->GetPKC();
01189 if(pkcRef->GetCert() != (CPKIFCertificate*)NULL)
01190 {
01191 tmpReply->cert.u.pkc->t = T_PKCReference_cert;
01192
01193 tmpReply->cert.u.pkc->u.cert = new CACX509V3Certificate;
01194 memset(tmpReply->cert.u.pkc->u.cert, 0, sizeof(CACX509V3Certificate));
01195
01196 setBERDecBufPtr(&ctxt, (unsigned char*)pkcRef->GetCert()->Encoded()->GetBuffer(), pkcRef->GetCert()->Encoded()->GetLength(), NULL, NULL);
01197 BERDecCACX509V3Certificate(&ctxt, tmpReply->cert.u.pkc->u.cert, ASN1EXPL, NULL);
01198
01199 }
01200 else
01201 {
01202 CPKIFSCVPCertIDPtr sCVPCertID = pkcRef->GetSCVPCertID();
01203
01204 if(sCVPCertID != (CPKIFSCVPCertID*)NULL)
01205 {
01206 tmpReply->cert.u.pkc->t = T_PKCReference_pkcRef;
01207
01208 tmpReply->cert.u.pkc->u.pkcRef = new SCVPCertID;
01209 memset(tmpReply->cert.u.pkc->u.pkcRef, 0, sizeof(SCVPCertID));
01210
01211
01212 tmpReply->cert.u.pkc->u.pkcRef->certHash.data = sCVPCertID->GetCertHash()->GetBuffer();
01213 tmpReply->cert.u.pkc->u.pkcRef->certHash.numocts = sCVPCertID->GetCertHash()->GetLength();
01214
01215 tmpReply->cert.u.pkc->u.pkcRef->issuerSerial.serialNumber = new char[strlen(sCVPCertID->GetSerialNumber())];
01216 memcpy((void*)tmpReply->cert.u.pkc->u.pkcRef->issuerSerial.serialNumber, sCVPCertID->GetSerialNumber(),
01217 strlen(sCVPCertID->GetSerialNumber()));
01218
01219 CPKIFGeneralNameListPtr nameList;
01220 sCVPCertID->GetIssuerName(nameList);
01221 if(nameList == (CPKIFGeneralNameList*)NULL)
01222 {
01223 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "Issuer Names value not specified.");
01224 }
01225 DListNode* curName = NULL;
01226 CPKIFGeneralNameList::iterator namePos;
01227 CPKIFGeneralNameList::iterator nameEnd = nameList->end();
01228 for(namePos = nameList->begin(); namePos != nameEnd; ++namePos)
01229 {
01230
01231 if(NULL == curName)
01232 {
01233 NEW_NODE(curName)
01234 }
01235 else
01236 {
01237 NEW_NEXT_AND_ADVANCE(curName)
01238 }
01239
01240 CACX509V3GeneralName *name = new CACX509V3GeneralName;
01241 memset(name, 0, sizeof(CACX509V3GeneralName));
01242
01243 CopyGeneralName((*name), (*namePos));
01244
01245 curName->data = name;
01246
01247 SET_HEAD_TAIL_INCREMENT(tmpReply->cert.u.pkc->u.pkcRef->issuerSerial.issuer, curName)
01248 }
01249
01250 CPKIFAlgorithmIdentifierPtr algID = sCVPCertID->GetHashAlgorithm();
01251 if(algID != (CPKIFAlgorithmIdentifier*)NULL)
01252 {
01253 CPKIFStringPtr str(new std::string(algID->oid()->ToString()));
01254 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
01255 CopyOID(&tmpReply->cert.u.pkc->u.pkcRef->hashAlgorithm.algorithm, tmpOid);
01256
01257 if(NULL != tmpOid)
01258 delete tmpOid;
01259
01260 if(algID->hasParameters())
01261 {
01262 tmpReply->cert.u.pkc->u.pkcRef->hashAlgorithm.m.parametersPresent = 1;
01263
01264 tmpReply->cert.u.pkc->u.pkcRef->hashAlgorithm.parameters.data = algID->parameters()->GetBuffer();
01265 tmpReply->cert.u.pkc->u.pkcRef->hashAlgorithm.parameters.numocts = algID->parameters()->GetLength();
01266 }
01267 tmpReply->cert.u.pkc->u.pkcRef->m.hashAlgorithmPresent = 1;
01268 }
01269
01270
01271 }
01272 }
01273 }
01274 else if(certRef->GetAC() != (CPKIFPKCReference*)NULL)
01275 {
01276 tmpReply->cert.t = T_CertReference_ac;
01277 tmpReply->cert.u.ac = new ACReference;
01278 memset(tmpReply->cert.u.ac, 0, sizeof(ACReference));
01279
01280 CPKIFACReferencePtr acRef = certRef->GetAC();
01281 if(acRef->GetACCert() != (CPKIFBuffer*)NULL)
01282 {
01283 tmpReply->cert.u.ac->t = T_CertReference_ac;
01284
01285
01286 tmpReply->cert.u.ac->u.attrCert = new AttributeCertificate;
01287 memset(tmpReply->cert.u.ac->u.attrCert, 0, sizeof(AttributeCertificate));
01288
01289 setBERDecBufPtr(&ctxt, (unsigned char*)acRef->GetACCert()->GetBuffer(), acRef->GetACCert()->GetLength(), NULL, NULL);
01290 BERDecAttributeCertificate(&ctxt, tmpReply->cert.u.ac->u.attrCert, ASN1EXPL, NULL);
01291
01292 }
01293 else
01294 {
01295 CPKIFSCVPCertIDPtr sCVPCertID = acRef->GetSCVPCertID();
01296
01297 if(sCVPCertID != (CPKIFSCVPCertID*)NULL)
01298 {
01299 tmpReply->cert.u.ac->t = T_CertReference_ac;
01300
01301 tmpReply->cert.u.ac->u.acRef = new SCVPCertID;
01302 memset(tmpReply->cert.u.ac->u.acRef , 0, sizeof(SCVPCertID));
01303
01304
01305 tmpReply->cert.u.ac->u.acRef->certHash.data = sCVPCertID->GetCertHash()->GetBuffer();
01306 tmpReply->cert.u.ac->u.acRef->certHash.numocts = sCVPCertID->GetCertHash()->GetLength();
01307
01308 tmpReply->cert.u.ac->u.acRef->issuerSerial.serialNumber = new char[strlen(sCVPCertID->GetSerialNumber())];
01309 memcpy((void*)tmpReply->cert.u.ac->u.acRef->issuerSerial.serialNumber, sCVPCertID->GetSerialNumber(),
01310 strlen(sCVPCertID->GetSerialNumber()));
01311
01312 CPKIFGeneralNameListPtr nameList;
01313 sCVPCertID->GetIssuerName(nameList);
01314 if(nameList == (CPKIFGeneralNameList*)NULL)
01315 {
01316 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "Issuer Names value not specified.");
01317 }
01318 DListNode* curName = NULL;
01319 CPKIFGeneralNameList::iterator namePos;
01320 CPKIFGeneralNameList::iterator nameEnd = nameList->end();
01321 for(namePos = nameList->begin(); namePos != nameEnd; ++namePos)
01322 {
01323
01324 if(NULL == curName)
01325 {
01326 NEW_NODE(curName)
01327 }
01328 else
01329 {
01330 NEW_NEXT_AND_ADVANCE(curName)
01331 }
01332
01333 CACX509V3GeneralName *name = new CACX509V3GeneralName;
01334 memset(name, 0, sizeof(CACX509V3GeneralName));
01335
01336 CopyGeneralName((*name), (*namePos));
01337
01338 curName->data = name;
01339
01340 SET_HEAD_TAIL_INCREMENT(tmpReply->cert.u.ac->u.acRef->issuerSerial.issuer, curName)
01341 }
01342
01343 CPKIFAlgorithmIdentifierPtr algID = sCVPCertID->GetHashAlgorithm();
01344 if(algID != (CPKIFAlgorithmIdentifier*)NULL)
01345 {
01346 CPKIFStringPtr str(new std::string(algID->oid()->ToString()));
01347 ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
01348 CopyOID(&tmpReply->cert.u.ac->u.acRef->hashAlgorithm.algorithm, tmpOid);
01349
01350 if(NULL != tmpOid)
01351 delete tmpOid;
01352
01353 if(algID->hasParameters())
01354 {
01355 tmpReply->cert.u.ac->u.acRef->hashAlgorithm.m.parametersPresent = 1;
01356
01357 tmpReply->cert.u.ac->u.acRef->hashAlgorithm.parameters.data = algID->parameters()->GetBuffer();
01358 tmpReply->cert.u.ac->u.acRef->hashAlgorithm.parameters.numocts = algID->parameters()->GetLength();
01359 }
01360 tmpReply->cert.u.pkc->u.pkcRef->m.hashAlgorithmPresent = 1;
01361 }
01362
01363
01364 }
01365 }
01366 }
01367 else
01368 {
01369 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "CertReference value not specified.");
01370 }
01371
01372
01373 int replyStatus = (*replyPos)->GetReplyStatus();
01374
01375 if(-1 != replyStatus)
01376 {
01377 tmpReply->replyStatus = replyStatus;
01378 tmpReply->m.replyStatusPresent = 1;
01379 }
01380
01381
01382 CPKIFTimePtr replyValTime = (*replyPos)->GetReplyValTime();
01383 if(replyValTime != (CPKIFTime*)NULL)
01384 {
01385 tmpReply->replyValTime = replyValTime->GetTime();
01386 }
01387 else
01388 {
01389 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "replyValTime value not specified.");
01390 }
01391
01392
01393 CPKIFReplyCheckListPtr replyChecks;
01394 (*replyPos)->GetReplyChecks(replyChecks);
01395
01396 if(replyChecks != (CPKIFReplyCheckList*)NULL && !replyChecks->empty())
01397 {
01398 DListNode* curReplyCheck = NULL;
01399 CPKIFReplyCheckList::iterator replyCheckPos;
01400 CPKIFReplyCheckList::iterator replyCheckEnd = replyChecks->end();
01401 for(replyCheckPos = replyChecks->begin(); replyCheckPos != replyCheckEnd; ++replyCheckPos)
01402 {
01403 if(NULL == curReplyCheck)
01404 {
01405 NEW_NODE(curReplyCheck)
01406 }
01407 else
01408 {
01409 NEW_NEXT_AND_ADVANCE(curReplyCheck)
01410 }
01411
01412 ReplyCheck* tmpReplyCheck = new ReplyCheck;
01413 memset(tmpReplyCheck, 0, sizeof(ReplyCheck));
01414
01415 CPKIFStringPtr str(new std::string((*replyCheckPos)->GetCheck()->ToString()));
01416 ASN1OBJID* tmpOid2 = ConvertStringToASN1OBJID(str);
01417 CopyOID(&tmpReplyCheck->check, tmpOid2);
01418
01419 if(NULL != tmpOid2)
01420 delete tmpOid2;
01421
01422 tmpReplyCheck->status = (*replyCheckPos)->GetStatus();
01423
01424 curReplyCheck->data = tmpReplyCheck;
01425
01426 SET_HEAD_TAIL_INCREMENT(tmpReply->replyChecks, curReplyCheck)
01427 }
01428 }
01429 else
01430 {
01431 throw CPKIFSCVPException(TOOLKIT_SCVP, SCVP_MISSING_REQUIRED_FIELD, "ReplyChecks value not specified.");
01432 }
01433
01434
01435 CPKIFReplyWantBackListPtr replyWantBacks;
01436 (*replyPos)->GetReplyWantBacks(replyWantBacks);
01437
01438 if(replyWantBacks != (CPKIFReplyWantBackList*)NULL && !replyWantBacks->empty())
01439 {
01440 DListNode* curReplyWantBack = NULL;
01441 CPKIFReplyWantBackList::iterator replyWantBackPos;
01442 CPKIFReplyWantBackList::iterator replyWantBackEnd = replyWantBacks->end();
01443 for(replyWantBackPos = replyWantBacks->begin(); replyWantBackPos != replyWantBackEnd; ++replyWantBackPos)
01444 {
01445 if(NULL == curReplyWantBack)
01446 {
01447 NEW_NODE(curReplyWantBack)
01448 }
01449 else
01450 {
01451 NEW_NEXT_AND_ADVANCE(curReplyWantBack)
01452 }
01453
01454 ReplyWantBack* tmpReplyWantBack = new ReplyWantBack;
01455 memset(tmpReplyWantBack, 0, sizeof(ReplyWantBack));
01456
01457 CPKIFStringPtr str(new std::string((*replyWantBackPos)->GetWB()->ToString()));
01458 ASN1OBJID* tmpOid2 = ConvertStringToASN1OBJID(str);
01459 CopyOID(&tmpReplyWantBack->wb, tmpOid2);
01460
01461 if(NULL != tmpOid2)
01462 delete tmpOid2;
01463
01464 tmpReplyWantBack->value.data = (*replyWantBackPos)->GetValue()->GetBuffer();
01465 tmpReplyWantBack->value.numocts = (*replyWantBackPos)->GetValue()->GetLength();
01466
01467 curReplyWantBack->data = tmpReplyWantBack;
01468
01469 SET_HEAD_TAIL_INCREMENT(tmpReply->replyWantBacks, curReplyWantBack)
01470 }
01471 }
01472
01473
01474
01475
01476
01477
01478
01479 CPKIFOIDListPtr errorList;
01480 (*replyPos)->GetValErrors(errorList);
01481 PopulateDListWithASN1OBJID(&tmpReply->validationErrors, errorList);
01482 if(errorList != (CPKIFOIDList*)NULL && !errorList->empty())
01483 {
01484 tmpReply->m.validationErrorsPresent = 1;
01485 }
01486
01487
01488 CPKIFTimePtr nextUpdate = (*replyPos)->GetNextUpdate();
01489 if(nextUpdate != (CPKIFTime*)NULL)
01490 {
01491 tmpReply->nextUpdate = nextUpdate->GetTime();
01492
01493 tmpReply->m.nextUpdatePresent = 1;
01494 }
01495
01496
01497 curReply->data = tmpReply;
01498
01499 SET_HEAD_TAIL_INCREMENT((*list), curReply)
01500 }
01501 }
01502 }
01511 bool ValPolAndPathSettingsMatch(
01512 CPKIFValPolResponsePtr& vpr,
01513 CPKIFPathSettingsPtr& ps)
01514 {
01515 if(!vpr || !ps) return false;
01516
01517 CPKIFValidationPolicyPtr vp = vpr->GetRespValidationPolicy();
01518 if(!vp) return false;
01519
01520
01521 if(vp->GetInitialExplicitPolicyIndicator() == ps->GetInitialExplicitPolicyIndicator() &&
01522 vp->GetInitialPolicyMappingInhibitIndicator() == ps->GetInitialPolicyMappingInhibitIndicator() &&
01523 vp->GetInitialPolicyMappingInhibitIndicator() == ps->GetInitialPolicyMappingInhibitIndicator())
01524 {
01525
01526 CPKIFPolicyInformationListPtr vpPolSet, psPolSet;
01527 vp->GetInitialPolicySet(vpPolSet);
01528 ps->GetInitialPolicySet(psPolSet);
01529
01530 if(!vpPolSet && !psPolSet)
01531 return true;
01532 else if(!vpPolSet)
01533 return false;
01534 else if(!psPolSet)
01535 return false;
01536
01537 CPKIFPolicyInformationList::iterator vpPos;
01538 CPKIFPolicyInformationList::iterator vpEnd = vpPolSet->end();
01539 for(vpPos = vpPolSet->begin(); vpPos != vpEnd; ++vpPos)
01540 {
01541 bool bFoundMatch = false;
01542 CPKIFPolicyInformationPtr curPol = *vpPos;
01543
01544 CPKIFPolicyInformationList::iterator psPos;
01545 CPKIFPolicyInformationList::iterator psEnd = psPolSet->end();
01546 for(psPos = psPolSet->begin(); psPos != psEnd; ++psPos)
01547 {
01548 if(*(*psPos) == *curPol)
01549 {
01550 bFoundMatch = true;
01551 break;
01552 }
01553 }
01554
01555 if(!bFoundMatch)
01556 return false;
01557 }
01558
01559
01560 return true;
01561 }
01562
01563 return false;
01564 }
01565
01594 CPKIFValidationPolicyPtr PrepareCustomValidationPolicyIfNecessary(
01595 CPKIFPathSettingsPtr& ps,
01596 IPKIFScvpClient* scvpClient)
01597 {
01598
01599 CPKIFValidationPolicyPtr defaultIsFine;
01600
01601
01602 if(!ps) return defaultIsFine;
01603
01604
01605 CPKIFValPolResponsePtr vpr;
01606 CPKIFContentInfoPtr ci = scvpClient->GetValPol();
01607 if(ci)
01608 {
01609 try
01610 {
01611 vpr = scvpClient->VerifyValPol();
01612 }
01613 catch(...)
01614 {
01615 }
01616 }
01617
01618
01619 if(vpr && ValPolAndPathSettingsMatch(vpr, ps))
01620 return defaultIsFine;
01621 else
01622 {
01623
01624 CPKIFValidationPolicyPtr newVP(new CPKIFValidationPolicy);
01625
01626 CPKIFValidationPolRefPtr defVPR(new CPKIFValidationPolRef(g_id_svp_defaultValPolicy));
01627 newVP->SetValidationPolRef(defVPR);
01628
01629
01630 if(ps->GetInitialExplicitPolicyIndicator())
01631 newVP->SetInitialExplicitPolicyIndicator();
01632 if(ps->GetInitialInhibitAnyPolicyIndicator())
01633 newVP->SetInitialInhibitAnyPolicyIndicator();
01634 if(ps->GetInitialPolicyMappingInhibitIndicator())
01635 newVP->SetInitialPolicyMappingInhibitIndicator();
01636
01637
01638 CPKIFPolicyInformationListPtr initPolSet;
01639 ps->GetInitialPolicySet(initPolSet);
01640 if(initPolSet)
01641 newVP->SetInitialPolicySet(initPolSet);
01642
01643 return newVP;
01644 }
01645 }
01646
01670 CPKIFQueryPtr MakeQueryForPath(
01672 CPKIFCertificatePath& path,
01674 CPKIFOIDPtr& certCheck,
01676 IPKIFScvpClient* scvpClient)
01677 {
01678
01679 CPKIFQueryPtr query(new CPKIFQuery);
01680
01681
01682
01683
01684
01685 CPKIFCertificatePtr targetCert;
01686 path.GetTarget(targetCert);
01687
01688
01689 CPKIFCertReferencesPtr certRefs(new CPKIFCertReferences);
01690 CPKIFPKCReferenceListPtr pkcRefs(new CPKIFPKCReferenceList);
01691 CPKIFPKCReferencePtr pkcRef(new CPKIFPKCReference);
01692
01693
01694 pkcRef->SetCert(targetCert);
01695 pkcRefs->push_back(pkcRef);
01696 certRefs->SetPKCList(pkcRefs);
01697
01698
01699 query->SetCertRef(certRefs);
01700
01701
01702
01703
01704
01705 CPKIFOIDListPtr checks(new CPKIFOIDList);
01706 checks->push_back(certCheck);
01707
01708
01709 query->SetChecks(checks);
01710
01711
01712
01713
01714 CPKIFOIDListPtr wantBacks = scvpClient->GetWantBacks();
01715 if(wantBacks)
01716 {
01717 query->SetWantBack(wantBacks);
01718 }
01719
01720
01721
01722
01723 CPKIFPathSettingsPtr ps;
01724 path.GetPathSettings(ps);
01725
01726 if(ps)
01727 {
01728 CPKIFValidationPolicyPtr vp = PrepareCustomValidationPolicyIfNecessary(ps, scvpClient);
01729 if(vp)
01730 query->SetValidationPolicy(vp);
01731 }
01732
01733
01734
01735
01736 CPKIFResponseFlagsPtr rf;
01737
01738
01739
01740 if(*g_id_stc_build_pkc_path == *certCheck && false == scvpClient->GetRequireSignedDPD())
01741 {
01742 if(!rf)
01743 {
01744 CPKIFResponseFlagsPtr tmpRF(new CPKIFResponseFlags);
01745 rf = tmpRF;
01746 }
01747 rf->SetProtectResponse(false);
01748 }
01749
01750
01751
01752 if(scvpClient->GetGenerateNonce() && scvpClient->GetRequireNonceMatch())
01753 {
01754 if(!rf)
01755 {
01756 CPKIFResponseFlagsPtr tmpRF(new CPKIFResponseFlags);
01757 rf = tmpRF;
01758 }
01759 rf->SetcachedResponse(false);
01760 }
01761
01762
01763 if(rf)
01764 query->SetResponseFlags(rf);
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774 if(ps)
01775 {
01776 CPKIFTimePtr timeOfInterest = ps->GetValidationTime();
01777 if(timeOfInterest)
01778 {
01779
01780
01781 CPKIFDurationPtr d(new CPKIFDuration);
01782 d->setSeconds(300);
01783
01784 CPKIFTimePtr curTime = CPKIFTime::CurrentTime();
01785
01786
01787 *curTime -= *d;
01788 d->setSeconds(600);
01789
01790
01791 CPKIFPeriod p(curTime, d);
01792 bool b = p.contains(timeOfInterest);
01793 if(!b)
01794 query->SetValidationTime(timeOfInterest);
01795 }
01796 }
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806 return query;
01807 }
01808
01829 SCVP_SignatureState VerifyResponseSignature(
01831 CPKIFBufferPtr& encResp,
01833 IPKIFScvpClient* scvpClient,
01835 CPKIFCVRequestPtr& req,
01837 bool reqIsDpd,
01839 CPKIFCVResponsePtr& parsedCvResponse)
01840 {
01841
01842 if(!encResp || !scvpClient || !req)
01843 return SS_OTHER_ERROR;
01844
01845
01846 CPKIFContentInfo ci;
01847 ci.Decode(encResp);
01848
01849
01850
01851
01852 CPKIFSignedDataPtr sd;
01853 CPKIFOIDPtr innerContentType;
01854 CPKIFBufferPtr innerContent;
01855
01856 CPKIFOIDPtr outerContentType = ci.GetContentType();
01857 CPKIFBufferPtr outerContent = ci.GetContent();
01858
01859
01860 if(*g_signedData == *outerContentType)
01861 {
01862
01863 CPKIFSignedDataPtr tmpSD(new CPKIFSignedData);
01864 tmpSD->Decode(outerContent);
01865 sd = tmpSD;
01866
01867 CPKIFEncapsulatedContentInfoPtr ecip = sd->GetEncapsulatedContent();
01868 innerContentType = ecip->GetOID();
01869 innerContent = ecip->GetContent();
01870 }
01871 else
01872 {
01873 if(false == reqIsDpd || scvpClient->GetRequireSignedDPD())
01874 return SS_UNPROTECTED_PAYLOAD;
01875
01876
01877 innerContentType = outerContentType;
01878 innerContent = outerContent;
01879 }
01880
01881
01882 if(*g_id_ct_scvp_certValResponse != *innerContentType)
01883 return SS_UNSUPPORTED_PAYLOAD;
01884 else
01885 {
01886 CPKIFCVResponsePtr tmpCVR(new CPKIFCVResponse);
01887 tmpCVR->Decode(innerContent);
01888 parsedCvResponse = tmpCVR;
01889
01890
01891 CPKIFResponseStatusPtr responseStatus = parsedCvResponse->GetResponseStatus();
01892 int statusCode = responseStatus->GetStatusCode();
01893 if(0 != statusCode && 1 != statusCode)
01894 return SS_BAD_RESPONSE_STATUS;
01895
01896
01897 CPKIFQueryPtr query = req->GetQuery();
01898 CPKIFResponseFlagsPtr responseFlags = query->GetResponseFlags();
01899 CPKIFBufferPtr reqNonce = req->GetNonce();
01900 if(reqNonce && responseFlags && false == responseFlags->GetCachedResponse())
01901 {
01902
01903 CPKIFBufferPtr respNonce = parsedCvResponse->GetNonce();
01904 if(respNonce)
01905 {
01906 if(*respNonce != *reqNonce)
01907 return SS_NONCE_MISMATCH;
01908 }
01909 else
01910 return SS_MISSING_NONCE;
01911 }
01912
01913
01914 }
01915
01916 if(*g_signedData == *outerContentType)
01917 {
01918 IPKIFMediatorPtr m = scvpClient->GetMediator();
01919 sd->AddMediator(m);
01920
01921 CMSVerificationStatus status = NOT_VERIFIED;
01922 if(!sd->Verify(0, status))
01923 return SS_SIGNATURE_NOT_VERIFIED;
01924 else
01925 return SS_OK;
01926 }
01927 else
01928 {
01929
01930
01931 return SS_OK;
01932 }
01933 }
01941 bool NameMatchesSCVPCertId(CPKIFSCVPCertIDPtr& certId, CPKIFNamePtr& issName)
01942 {
01943 CPKIFGeneralNameListPtr gns;
01944 certId->GetIssuerName(gns);
01945
01946 CPKIFGeneralNameList::iterator pos;
01947 CPKIFGeneralNameList::iterator end = gns->end();
01948 for(pos = gns->begin(); pos != end; ++pos)
01949 {
01950 if(CPKIFGeneralName::DIRECTORYNAME == (*pos)->GetType())
01951 {
01952 CPKIFNamePtr fromGN = (*pos)->directoryName();
01953 if(*fromGN == *issName)
01954 return true;
01955 }
01956 }
01957
01958 return false;
01959 }
01968 bool CertReferenceMatchesCertificate(CPKIFCertReferencePtr& cr, CPKIFCertificatePtr& targetCert)
01969 {
01970 CPKIFPKCReferencePtr pkcRef = cr->GetPKC();
01971 if(!pkcRef)
01972 return false;
01973
01974 CPKIFCertificatePtr certFromPkcRef = pkcRef->GetCert();
01975 if(certFromPkcRef)
01976 {
01977
01978 return *certFromPkcRef == *targetCert;
01979 }
01980 else
01981 {
01982
01983 CPKIFSCVPCertIDPtr certId = pkcRef->GetSCVPCertID();
01984
01985 CPKIFBufferPtr hashFromId = certId->GetCertHash();
01986
01987 CPKIFAlgorithmIdentifierPtr ai = certId->GetHashAlgorithm();
01988 CPKIFOIDPtr oid = ai->oid();
01989
01990 CPKIFAlgorithm* a = CPKIFAlgorithm::GetAlg(oid);
01991 if(a)
01992 {
01993 IPKIFCryptoMisc* cryptoMisc = GetPlatformCryptoMisc();
01994
01995 IPKIFHashContext* hc = NULL;
01996 try
01997 {
01998 hc = cryptoMisc->HashInit(a->HashAlg());
01999 CPKIFBufferPtr certBuf = targetCert->Encoded();
02000 cryptoMisc->HashUpdate(hc, (unsigned char*)certBuf->GetBuffer(), certBuf->GetLength());
02001
02002 CPKIFBufferPtr targetHash(new CPKIFBuffer);
02003 int outLen = a->DigestSize();
02004 unsigned char* outBuf = targetHash->AllocateBuffer(outLen);
02005 cryptoMisc->HashFinal(hc, outBuf, &outLen);
02006
02007 return *targetHash == *hashFromId;
02008 }
02009 catch(...)
02010 {
02011 if(hc)
02012 delete hc;
02013 return false;
02014 }
02015 }
02016 else
02017 return false;
02018
02019
02020 const char* serialNumFromId = certId->GetSerialNumber();
02021 if(serialNumFromId)
02022 {
02023
02024 const char* targetSerialNum = targetCert->SerialNumber();
02025 size_t targetSerialNumLen = strlen(targetSerialNum);
02026 if(strlen(serialNumFromId) == targetSerialNumLen &&
02027 0 == memcmp(serialNumFromId, targetSerialNum, targetSerialNumLen))
02028 {
02029
02030 CPKIFNamePtr targetIssName = targetCert->Issuer();
02031 return NameMatchesSCVPCertId(certId, targetIssName);
02032 }
02033 else
02034 return false;
02035 }
02036 else
02037 return false;
02038 }
02039 }
02047 CPKIFCertReplyPtr GetReplyObject(
02049 CPKIFCertReplyListPtr& replyObjects,
02051 CPKIFCertificatePtr& targetCert)
02052 {
02053 CPKIFCertReplyPtr noMatch;
02054 if(!replyObjects || !targetCert)
02055 return noMatch;
02056
02057 CPKIFCertReplyList::iterator pos;
02058 CPKIFCertReplyList::iterator end = replyObjects->end();
02059 for(pos = replyObjects->begin(); pos != end; ++pos)
02060 {
02061 CPKIFCertReferencePtr certRef = (*pos)->GetCertRef();
02062 if(CertReferenceMatchesCertificate(certRef, targetCert))
02063 return *pos;
02064 }
02065
02066 return noMatch;
02067 }
02068
02076 bool MakeSureReplyChecksAreSuccessfulAndValErrorsAreAbsent(
02078 CPKIFCertReplyPtr& replyObject)
02079 {
02080 if(!replyObject)
02081 return false;
02082
02083 CPKIFOIDListPtr valErrors;
02084 replyObject->GetValErrors(valErrors);
02085
02086 if(valErrors && !valErrors->empty())
02087 return false;
02088
02089 CPKIFReplyCheckListPtr replyChecks;
02090 replyObject->GetReplyChecks(replyChecks);
02091 if(replyChecks)
02092 {
02093 CPKIFReplyCheckList::iterator pos;
02094 CPKIFReplyCheckList::iterator end = replyChecks->end();
02095 for(pos = replyChecks->begin(); pos != end; ++pos)
02096 {
02097 if(0 != (*pos)->GetStatus())
02098 return false;
02099 }
02100 }
02101
02102 return true;
02103 }