RevInfoWantBack.cpp

Go to the documentation of this file.
00001 
00010 #include "RevInfoWantBack.h"
00011 #include "components.h"
00012 #include "ToolkitUtils.h"
00013 #include "Buffer.h"
00014 #include "PKIFSCVPErrors.h"
00015 #include "SCVPException.h"
00016 #include "ASN1Helper.h"
00017 #include "SCVP.h"
00018 #include "CertBundle.h"
00019 #include "RevocationInfo.h"
00020 #include "Certificate.h"
00021 #include "CRL.h"
00022 
00024 
00025 struct CPKIFRevInfoWantBackImpl 
00026 {
00027 
00028     void FreeRevInfoWantBack(RevInfoWantBack* revInfoWantBack);
00029 
00030     CPKIFRevocationInfoListPtr m_RevInfos;
00031     CPKIFCertBundlePtr m_certBundle;
00032 };
00033 
00035 
00044 CPKIFRevInfoWantBack::CPKIFRevInfoWantBack() :m_impl(new CPKIFRevInfoWantBackImpl)
00045 {
00046     LOG_STRING_DEBUG("CPKIFRevInfoWantBack::CPKIFRevInfoWantBack()", TOOLKIT_SCVP_ASN, 0, this);
00047 
00048 }
00059 CPKIFRevInfoWantBack::CPKIFRevInfoWantBack(
00061     const CPKIFBufferPtr& revInfoWantBack)
00062   :m_impl (new CPKIFRevInfoWantBackImpl)
00063 {
00064     if(revInfoWantBack == (CPKIFBuffer*)NULL || 0 == revInfoWantBack->GetLength())
00065     {
00066         throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00067     }
00068 
00069     CACASNWRAPPER_CREATE(RevInfoWantBack, objPDU);
00070     objPDU.Decode(revInfoWantBack->GetBuffer(), revInfoWantBack->GetLength());
00071 
00072     if(objPDU->m.extraCertsPresent == 1) {
00073         CACASNWRAPPER_CREATE(CertBundle, objPDU2);  
00074         ASN1OpenType* data1 = objPDU2.Encode(&objPDU->extraCerts);  
00075 
00076         CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00077         CPKIFCertBundlePtr tmpBundle(new CPKIFCertBundle());
00078         tmpBundle->Decode(tmpBuf);
00079         if(NULL != data1)
00080             delete data1;
00081 
00082 
00083         m_impl->m_certBundle = tmpBundle;
00084     }
00085 
00086     CPKIFRevocationInfoListPtr revInfoList(new CPKIFRevocationInfoList());
00087     DListNode* cur = objPDU->revocationInfo.head;
00088     while(NULL != cur)
00089     {
00090         RevocationInfo* tmp = (RevocationInfo*)cur->data;
00091         CACASNWRAPPER_CREATE(RevocationInfo, objPDU3);
00092         ASN1OpenType* data2 = objPDU3.Encode(tmp);          
00093         CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data2->data, data2->numocts));
00094         CPKIFRevocationInfoPtr tmpRevocationInfo(new CPKIFRevocationInfo(tmpBuf));
00095 
00096         if(NULL != data2)
00097             delete data2;
00098 
00099 
00100         revInfoList->push_back(tmpRevocationInfo);
00101 
00102         cur = cur->next;
00103     }
00104     m_impl->m_RevInfos = revInfoList;
00105 }
00113 CPKIFBufferPtr CPKIFRevInfoWantBack::Encode()
00114 {
00115     RevInfoWantBack revInfoWantBack;
00116     memset(&revInfoWantBack,0x00,sizeof(RevInfoWantBack));
00117 
00118     OOCTXT ctxt;
00119     initContext (&ctxt);
00120 
00121     CACASNWRAPPER_CREATE(RevInfoWantBack, objPDU);  
00122 
00123     if(m_impl->m_certBundle != (CPKIFCertBundle*)NULL)
00124     {
00125         revInfoWantBack.m.extraCertsPresent = 1;
00126 
00127         CPKIFCertificateListPtr certList;
00128         m_impl->m_certBundle->GetCertList(certList);
00129 
00130         DListNode* curCert = NULL;
00131         CPKIFCertificateList::iterator certPos; 
00132         CPKIFCertificateList::iterator certEnd = certList->end();
00133         for(certPos = certList->begin(); certPos != certEnd; ++certPos)
00134         {
00135             if(NULL == curCert)
00136             {
00137                 NEW_NODE(curCert)
00138             }
00139             else
00140             {
00141                 NEW_NEXT_AND_ADVANCE(curCert)
00142             }
00143 
00144             ASN1OpenType* tmpCert = new ASN1OpenType;
00145             memset(tmpCert, 0, sizeof(ASN1OpenType));
00146             
00147             //certs were screened when added to make sure the encoded buffer existed
00148             tmpCert->data = (*certPos)->Encoded()->GetBuffer();
00149             tmpCert->numocts = (*certPos)->Encoded()->GetLength();
00150             
00151             curCert->data = tmpCert;
00152 
00153             SET_HEAD_TAIL_INCREMENT(revInfoWantBack.extraCerts, curCert)
00154         }
00155     }
00156 
00157     if(m_impl->m_RevInfos != (CPKIFRevocationInfoList*)NULL && !m_impl->m_RevInfos->empty())
00158     {
00159         DListNode* curRevInfo = NULL;
00160         CPKIFRevocationInfoList::iterator revInfoPos;   
00161         CPKIFRevocationInfoList::iterator revInfoEnd = m_impl->m_RevInfos->end();
00162         for(revInfoPos = m_impl->m_RevInfos->begin(); revInfoPos != revInfoEnd; ++revInfoPos)
00163         {
00164             if(NULL == curRevInfo)
00165             {
00166                 NEW_NODE(curRevInfo)
00167             }
00168             else
00169             {
00170                 NEW_NEXT_AND_ADVANCE(curRevInfo)
00171             }
00172 
00173             if((*revInfoPos)->GetCRL() != (CPKIFCRL*)NULL)
00174             {
00175                 RevocationInfo* tmpCRL = new RevocationInfo;
00176                 memset(tmpCRL, 0, sizeof(RevocationInfo));
00177 
00178                 tmpCRL->t = T_RevocationInfo_crl;
00179 
00180                 tmpCRL->u.crl = new CACX509V3CertificateList;
00181                 memset(tmpCRL->u.crl, 0, sizeof(CACX509V3CertificateList));
00182 
00183                 setBERDecBufPtr(&ctxt, (unsigned char*)(*revInfoPos)->GetCRL()->Encoded()->GetBuffer(), (*revInfoPos)->GetCRL()->Encoded()->GetLength(), NULL, NULL);
00184                 BERDecCACX509V3CertificateList(&ctxt, tmpCRL->u.crl, ASN1EXPL, NULL);
00185             
00186                 curRevInfo->data = tmpCRL;
00187             }
00188             else if((*revInfoPos)->GetDeltaCRL() != (CPKIFCRL*)NULL)
00189             {
00190                 RevocationInfo* tmpDeltaCRL = new RevocationInfo;
00191                 memset(tmpDeltaCRL, 0, sizeof(RevocationInfo));
00192 
00193                 tmpDeltaCRL->t = T_RevocationInfo_delta_crl;
00194 
00195                 tmpDeltaCRL->u.delta_crl = new CACX509V3CertificateList;
00196                 memset(tmpDeltaCRL->u.delta_crl, 0, sizeof(CACX509V3CertificateList));
00197 
00198                 setBERDecBufPtr(&ctxt, (unsigned char*)(*revInfoPos)->GetDeltaCRL()->Encoded()->GetBuffer(), (*revInfoPos)->GetDeltaCRL()->Encoded()->GetLength(), NULL, NULL);
00199                 BERDecCACX509V3CertificateList(&ctxt, tmpDeltaCRL->u.delta_crl, ASN1EXPL, NULL);
00200                         
00201                 curRevInfo->data = tmpDeltaCRL;
00202             }
00203             else if((*revInfoPos)->GetOCSPResp() != (CPKIFBuffer*)NULL)
00204             {
00205                 RevocationInfo* tmpOCSPResp = new RevocationInfo;
00206                 memset(tmpOCSPResp, 0, sizeof(RevocationInfo));
00207 
00208                 tmpOCSPResp->t = T_RevocationInfo_ocsp;
00209 
00210                 tmpOCSPResp->u.ocsp = new OCSPResponse;
00211                 memset(tmpOCSPResp->u.ocsp, 0, sizeof(OCSPResponse));
00212                 
00213                 setBERDecBufPtr(&ctxt, (unsigned char*)(*revInfoPos)->GetOCSPResp()->GetBuffer(), (*revInfoPos)->GetOCSPResp()->GetLength(), NULL, NULL);
00214                 BERDecOCSPResponse(&ctxt, tmpOCSPResp->u.ocsp, ASN1EXPL, NULL);
00215                 
00216                 curRevInfo->data = tmpOCSPResp;
00217             }
00218             else
00219             {
00220                 RevocationInfo* tmpOther = new RevocationInfo;
00221                 memset(tmpOther, 0, sizeof(RevocationInfo));
00222 
00223                 tmpOther->t = T_RevocationInfo_other;
00224                 tmpOther->u.other = new OtherRevInfo;
00225 
00226                 CPKIFOIDPtr oid;
00227                 CPKIFBufferPtr buf;
00228                 (*revInfoPos)->GetOtherRevInfo(oid, buf);
00229 
00230                 CPKIFStringPtr str(new std::string(oid->ToString())); 
00231                 ASN1OBJID* tmpOid2 = ConvertStringToASN1OBJID(str);
00232                 CopyOID(&tmpOther->u.other->riType, tmpOid2);
00233 
00234                 if(NULL != tmpOid2)
00235                     delete tmpOid2;
00236 
00237                 tmpOther->u.other->riValue.data = buf->GetBuffer();
00238                 tmpOther->u.other->riValue.numocts = buf->GetLength();
00239 
00240                 curRevInfo->data = tmpOther;
00241                 
00242             }
00243 
00244 
00245             SET_HEAD_TAIL_INCREMENT(revInfoWantBack.revocationInfo, curRevInfo)
00246         }
00247 
00248     }
00249     ASN1OpenType* data1 = objPDU.Encode(&revInfoWantBack);
00250 
00251     CPKIFBufferPtr rv(new CPKIFBuffer(data1->data, data1->numocts));
00252 
00253     m_impl->FreeRevInfoWantBack(&revInfoWantBack);
00254 
00255     if(NULL != data1)
00256         delete data1;
00257 
00258     freeEncodeBuffer(&ctxt);
00259     memFreeAll(&ctxt);
00260 
00261 
00262     return rv;
00263 }
00271 CPKIFRevInfoWantBack::~CPKIFRevInfoWantBack()
00272 {
00273     LOG_STRING_DEBUG("CPKIFRevInfoWantBack::~CPKIFRevInfoWantBack()", TOOLKIT_SCVP_ASN, 0, this);
00274 
00275     if (m_impl) {
00276       delete m_impl;
00277     }   
00278 }
00286 void CPKIFRevInfoWantBack::SetRevInfos(
00288     CPKIFRevocationInfoListPtr& revInfoList)
00289 {
00290     m_impl->m_RevInfos = revInfoList;
00291 }
00299 void CPKIFRevInfoWantBack::GetRevInfos(
00301     CPKIFRevocationInfoListPtr& revInfoList) const
00302 {
00303     revInfoList = m_impl->m_RevInfos;
00304 }
00305 
00313 void CPKIFRevInfoWantBack::SetExtraCerts(
00315     CPKIFCertBundlePtr& bundle)
00316 {
00317     m_impl->m_certBundle = bundle;
00318 }
00326 const CPKIFCertBundlePtr CPKIFRevInfoWantBack::GetExtraCerts() const{
00327     return m_impl->m_certBundle;
00328 }
00329 
00330 
00337 void CPKIFRevInfoWantBackImpl::FreeRevInfoWantBack(RevInfoWantBack* revInfoWantBack) 
00338 {
00339     
00340     DListNode* cur = NULL, *tmp = NULL;
00341     if(revInfoWantBack->m.extraCertsPresent)
00342     {
00343         cur = revInfoWantBack->extraCerts.head;
00344         while(NULL != cur)
00345         {
00346             tmp = cur->next;
00347 
00348             delete cur;
00349             cur = tmp;
00350         }
00351     }
00352 
00353 
00354     cur = NULL;
00355     tmp = NULL;
00356     cur = revInfoWantBack->revocationInfo.head;
00357     while(NULL != cur)
00358     {
00359         tmp = cur->next;
00360 
00361         RevocationInfo* tmpOther = (RevocationInfo*)cur->data;
00362 
00363         if(tmpOther->t == T_RevocationInfo_crl)
00364         {
00365             if(tmpOther->u.crl != NULL)
00366                 delete tmpOther->u.crl;
00367         }
00368         else if(tmpOther->t == T_RevocationInfo_delta_crl)
00369         {
00370             if(tmpOther->u.delta_crl != NULL)
00371                 delete tmpOther->u.delta_crl;
00372         }
00373         else if(tmpOther->t == T_RevocationInfo_ocsp)
00374         {
00375             if(tmpOther->u.ocsp != NULL)
00376                 delete tmpOther->u.ocsp;
00377         }
00378         else if(tmpOther->t == T_RevocationInfo_other)
00379         {
00380         }
00381 
00382         if(NULL != cur && NULL != cur->data)
00383             delete cur->data;
00384         delete cur;
00385         cur = tmp;
00386     }
00387 }

Generated on Mon Nov 15 11:15:56 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6