CertReply.cpp
Go to the documentation of this file.00001
00010 #include "PKIFSCVP.h"
00011
00012 #include "ASN1Helper.h"
00013 #include "ToolkitUtils.h"
00014 #include "SCVP.h"
00015 #include "Buffer.h"
00016 #include "PKIFTime.h"
00017 #include "PKIFX509Extensions2.h"
00018 #include "Certificate.h"
00019
00021
00022 struct CPKIFCertReplyImpl
00023 {
00024 CPKIFCertReplyImpl()
00025 {
00026 m_this = NULL;
00027 m_certReply = NULL;
00028 m_scvpCertReply = NULL;
00029 }
00030
00031
00032 void populateExtensionsVector();
00033
00034 CPKIFTimePtr m_replyValTime;
00035 CPKIFTimePtr m_nextUpdate;
00036 CPKIFCertReferencePtr m_certRef;
00037 int m_replyStatus;
00038 CPKIFReplyCheckListPtr m_replyChecks;
00039 CPKIFReplyWantBackListPtr m_replyWantBacks;
00040 CPKIFOIDListPtr m_validationErros;
00041
00042 CPKIFASNWrapper<CertReply>* m_certReply;
00043 std::vector<CPKIFX509ExtensionPtr> m_exts;
00044
00045
00046 CPKIFASNWrapper<CertReply>* m_scvpCertReply;
00047
00048 void ClearAllMembers();
00049 void MakeSCVPCertReply();
00050 void FreeSCVPCertReply();
00051
00052
00053 void CallingAllGets();
00054
00055 CPKIFCertReply * m_this;
00056 };
00057
00058
00066 void CPKIFCertReplyImpl::CallingAllGets()
00067 {
00068 LOG_STRING_DEBUG("CPKIFCVRequestImpl::CallingAllGets()", TOOLKIT_SCVP_ASN, 0, this);
00069
00070 populateExtensionsVector();
00071 FreeSCVPCertReply();
00072 }
00073
00081 void CPKIFCertReplyImpl::MakeSCVPCertReply()
00082 {
00083 LOG_STRING_DEBUG("CPKIFCVRequest::MakeSCVPR()", TOOLKIT_SCVP_ASN, 0, this);
00084
00085 FreeSCVPCertReply();
00086 m_certReply = new CPKIFASNWrapper<CertReply>( BEREncCertReply, BERDecCertReply);
00087 }
00095 void CPKIFCertReplyImpl::FreeSCVPCertReply()
00096 {
00097 LOG_STRING_DEBUG("CPKIFCertReplyImpl::MakeSCVPR()", TOOLKIT_SCVP_ASN, 0, this);
00098 if(NULL != m_certReply)
00099 delete m_certReply;
00100 if(NULL != m_scvpCertReply)
00101 delete m_scvpCertReply;
00102 m_certReply = NULL;
00103 }
00104
00113 void CPKIFCertReplyImpl::ClearAllMembers()
00114 {
00115 LOG_STRING_DEBUG("CPKIFCertReplyImpl::ClearAllMembers()", TOOLKIT_SCVP_ASN, 0, this);
00116
00117 FreeSCVPCertReply();
00118 }
00119
00130 void CPKIFCertReplyImpl::populateExtensionsVector()
00131 {
00132 LOG_STRING_DEBUG("CPKIFCertReplyImpl::populateExtensionsVector()", TOOLKIT_SCVP_ASN, 0, this);
00133
00134 if(NULL == m_certReply || NULL == m_certReply->data())
00135 return;
00136
00137
00138 if(!m_exts.empty())
00139 return;
00140
00141
00142 if(0 == (*m_scvpCertReply)->m.certReplyExtensionsPresent)
00143 {
00144 m_exts.clear();
00145 return;
00146 }
00147
00148
00149
00150 CPKIFX509ExtensionMediator2 * mediator = CPKIFX509ExtensionMediator2::GetInstance();
00151
00152 m_this->IPKIFHasExtensions::GetExtensions (mediator, m_exts);
00153 }
00154
00156
00157
00165 CPKIFCertReply::CPKIFCertReply() :m_impl(new CPKIFCertReplyImpl)
00166 {
00167 LOG_STRING_DEBUG("CPKIFCertReply::CPKIFCertReply()", TOOLKIT_SCVP_ASN, 0, this);
00168
00169 m_impl->m_certReply = NULL;
00170 m_impl->m_scvpCertReply = NULL;
00171 m_impl->m_replyStatus = -1;
00172 }
00183 CPKIFCertReply::CPKIFCertReply(
00185 const CPKIFBufferPtr& hashValue)
00186 :m_impl (new CPKIFCertReplyImpl)
00187 {
00188 if(hashValue == (CPKIFBuffer*)NULL || 0 == hashValue->GetLength())
00189 {
00190 throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00191 }
00192
00193 CACASNWRAPPER_CREATE(CertReply, objPDU);
00194 objPDU.Decode(hashValue->GetBuffer(), hashValue->GetLength());
00195
00196
00197 CACASNWRAPPER_CREATE(CertReference, objPDU2);
00198 ASN1OpenType* data1 = objPDU2.Encode(&objPDU->cert);
00199 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00200 CPKIFCertReferencePtr tmpCertReference(new CPKIFCertReference(tmpBuf));
00201 m_impl->m_certRef = tmpCertReference;
00202
00203
00204
00205 CPKIFTimePtr tmpTime(new CPKIFTime(objPDU->replyValTime));
00206 m_impl->m_replyValTime = tmpTime;
00207
00208
00209 CPKIFReplyCheckListPtr tmpReplyChecks(new CPKIFReplyCheckList());
00210 DListNode* cur = objPDU->replyChecks.head;
00211 while(NULL != cur)
00212 {
00213 ReplyCheck* tmp = (ReplyCheck*)cur->data;
00214 CACASNWRAPPER_CREATE(ReplyCheck, objPDU);
00215 ASN1OpenType* data1 = objPDU.Encode(tmp);
00216 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00217 CPKIFReplyCheckPtr tmpReplyCheck(new CPKIFReplyCheck(tmpBuf));
00218
00219 tmpReplyChecks->push_back(tmpReplyCheck);
00220
00221 cur = cur->next;
00222 }
00223 m_impl->m_replyChecks = tmpReplyChecks;
00224
00225
00226 CPKIFReplyWantBackListPtr tmpReplyWantBacks(new CPKIFReplyWantBackList());
00227 DListNode* cur2 = objPDU->replyWantBacks.head;
00228 while(NULL != cur2)
00229 {
00230 ReplyWantBack* tmp = (ReplyWantBack*)cur2->data;
00231 CACASNWRAPPER_CREATE(ReplyWantBack, objPDU);
00232 ASN1OpenType* data1 = objPDU.Encode(tmp);
00233 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00234 CPKIFReplyWantBackPtr tmpReplyWantBack(new CPKIFReplyWantBack(tmpBuf));
00235
00236 tmpReplyWantBacks->push_back(tmpReplyWantBack);
00237
00238 cur2 = cur2->next;
00239 }
00240 m_impl->m_replyWantBacks = tmpReplyWantBacks;
00241
00242 if(0 < objPDU->m.nextUpdatePresent)
00243 {
00244 CPKIFTimePtr tmpTime(new CPKIFTime(objPDU->nextUpdate));
00245 m_impl->m_nextUpdate = tmpTime;
00246 }
00247 if(0 < objPDU->m.replyStatusPresent)
00248 {
00249 m_impl->m_replyStatus = objPDU->replyStatus;
00250 }
00251 if(0 < objPDU->m.validationErrorsPresent)
00252 {
00253 CPKIFOIDListPtr tmpErrors(new CPKIFOIDList());
00254 DListNode* cur = objPDU->validationErrors.head;
00255 while(NULL != cur)
00256 {
00257 ASN1OBJID* tmp = (ASN1OBJID*)cur->data;
00258 CPKIFOIDPtr tmpOID(new CPKIFOID(tmp->subid, tmp->numids));
00259
00260 tmpErrors->push_back(tmpOID);
00261
00262 cur = cur->next;
00263 }
00264 m_impl->m_validationErros = tmpErrors;
00265 }
00266
00267 }
00275 CPKIFCertReply::~CPKIFCertReply()
00276 {
00277 LOG_STRING_DEBUG("CPKIFCertReply::~CPKIFCertReply()", TOOLKIT_SCVP_ASN, 0, this);
00278
00279 m_impl->FreeSCVPCertReply();
00280 if (m_impl) {
00281 delete m_impl;
00282 }
00283 }
00284
00292 void CPKIFCertReply::GetEncodedExtensions (
00294 CPKIFBufferPtr& buf)
00295 {
00296 try
00297 {
00298 if ((*m_impl->m_certReply)->m.certReplyExtensionsPresent)
00299 {
00300 CACASNWRAPPER_CREATE(CACX509V3Extensions, extsWrapper);
00301 ASN1OpenType *data = extsWrapper.Encode (&(*m_impl->m_certReply)->certReplyExtensions);
00302 CPKIFBufferPtr tmp(new CPKIFBuffer(data->data, data->numocts));
00303 buf = tmp;
00304 delete data;
00305 return;
00306 }
00307 }
00308 catch (... )
00309 {
00310
00311 }
00312
00313 CPKIFBufferPtr nullExt;
00314 buf = nullExt;
00315 }
00316
00317
00326 void CPKIFCertReply::GetExtensionByOID(
00328 const CPKIFOID& oid,
00330 CPKIFX509ExtensionPtr& ref)
00331 {
00332 if(m_impl->m_exts.empty() && 0 != (*m_impl->m_certReply)->m.certReplyExtensionsPresent)
00333 m_impl->populateExtensionsVector();
00334
00335 std::vector<CPKIFX509ExtensionPtr>::iterator pos;
00336 std::vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00337 for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00338 {
00339 if(oid == (*pos)->oid())
00340 {
00341 ref = *pos;
00342 return;
00343 }
00344 }
00345 }
00346
00355 bool CPKIFCertReply::ExtensionsPresent() const
00356 {
00357 LOG_STRING_DEBUG("CPKIFCertReply::ExtensionsPresent()", TOOLKIT_SCVP_ASN, 0, this);
00358
00359 if(NULL != m_impl->m_certReply && (*m_impl->m_certReply)->m.certReplyExtensionsPresent)
00360 return true;
00361 else
00362 return false;
00363 }
00364
00372 void CPKIFCertReply::SetReplyValTime(
00374 CPKIFTimePtr& validationTime)
00375 {
00376 m_impl->m_replyValTime = validationTime;
00377 }
00385 const CPKIFTimePtr CPKIFCertReply::GetReplyValTime() const
00386 {
00387 return m_impl->m_replyValTime;
00388 }
00389
00397 void CPKIFCertReply::SetNextUpdate(
00399 CPKIFTimePtr& nextUpdate)
00400 {
00401 m_impl->m_nextUpdate = nextUpdate;
00402 }
00410 const CPKIFTimePtr CPKIFCertReply::GetNextUpdate() const
00411 {
00412 return m_impl->m_nextUpdate;
00413 }
00414
00422 void CPKIFCertReply::SetValErrors(
00424 CPKIFOIDListPtr& errors)
00425 {
00426 m_impl->m_validationErros = errors;
00427 }
00428
00436 void CPKIFCertReply::GetValErrors(
00438 CPKIFOIDListPtr& errors) const
00439 {
00440 errors = m_impl->m_validationErros;
00441 }
00442
00463 void CPKIFCertReply::SetReplyStatus(
00465 int replyStatus)
00466 {
00467 m_impl->m_replyStatus = replyStatus;
00468 }
00469
00470 const int CPKIFCertReply::GetReplyStatus() const
00471 {
00472 return m_impl->m_replyStatus;
00473 }
00474
00482 void CPKIFCertReply::SetReplyChecks(
00484 CPKIFReplyCheckListPtr& replyChecks)
00485 {
00486 m_impl->m_replyChecks = replyChecks;
00487 }
00488
00496 void CPKIFCertReply::GetReplyChecks(
00498 CPKIFReplyCheckListPtr& replyChecks) const
00499 {
00500 replyChecks = m_impl->m_replyChecks;
00501 }
00502
00503
00511 void CPKIFCertReply::SetReplyWantBacks(
00513 CPKIFReplyWantBackListPtr& replyWantBacks)
00514 {
00515 m_impl->m_replyWantBacks = replyWantBacks;
00516 }
00517
00525 void CPKIFCertReply::GetReplyWantBacks(
00527 CPKIFReplyWantBackListPtr& replyWantBacks) const
00528 {
00529 replyWantBacks = m_impl->m_replyWantBacks;
00530 }
00538 void CPKIFCertReply::SetCertRef(
00540 CPKIFCertReferencePtr& certRef)
00541 {
00542 m_impl->m_certRef = certRef;
00543 }
00551 const CPKIFCertReferencePtr CPKIFCertReply::GetCertRef() const
00552 {
00553 return m_impl->m_certRef;
00554 }