SingleResponse.cpp

Go to the documentation of this file.
00001 
00009 #include "SingleResponse.h"
00010 #include "CertID.h"
00011 #include "OCSPCertStatus.h"
00012 #include "PKIFTime.h"
00013 #include "X509Extension.h"
00014 #include "ASN1Helper.h"
00015 #include "OID.h"
00016 #include "Buffer.h"
00017 
00018 #include "OCSP.h"
00019 
00020 #include "ToolkitUtils.h"
00021 #include "PKIFX509Extensions2.h"
00022 #include "ExtensionsMatch.h"
00023 using namespace std;
00024 
00026 struct CPKIFSingleResponseImpl
00027 {
00035     CPKIFSingleResponseImpl();
00036     void populateExtensionsVector(CPKIFASNWrapper<SingleResponse>& sr);
00037     std::vector<CPKIFX509ExtensionPtr> m_exts;
00038     CPKIFASNWrapper<SingleResponse> m_singleResponse;
00039 
00040     CPKIFCertIDPtr m_certID;
00041     CPKIFOCSPCertStatusPtr m_certStatus;
00042     CPKIFTimePtr m_thisUpdate;
00043     CPKIFTimePtr m_nextUpdate;
00044 
00045     CPKIFSingleResponse * m_this;
00046 };
00048 
00049 
00057 CPKIFSingleResponseImpl::CPKIFSingleResponseImpl ()
00058 : m_singleResponse(BEREncSingleResponse, BERDecSingleResponse)
00059 {
00060 }
00061 
00069 CPKIFSingleResponse::CPKIFSingleResponse(void)
00070     :m_impl (new CPKIFSingleResponseImpl)
00071 {
00072     LOG_STRING_DEBUG("CPKIFSingleResponse::CPKIFSingleResponse(void)", TOOLKIT_OCSP_ASN, 0, this);
00073 
00074     m_impl->m_this = this;
00075 }
00084 CPKIFSingleResponse::CPKIFSingleResponse(
00086     const CPKIFBufferPtr& singleResponse)
00087     :m_impl (new CPKIFSingleResponseImpl)
00088 {
00089     LOG_STRING_DEBUG("CPKIFSingleResponse::CPKIFSingleResponse(SingleResponse& sr)", TOOLKIT_OCSP_ASN, 0, this);
00090 
00091     m_impl->m_this = this;
00092     m_impl->m_singleResponse.Decode(singleResponse->GetBuffer(), singleResponse->GetLength());
00093 
00094     CACASNWRAPPER_CREATE(CertID, objPDU);
00095     ASN1OpenType* data1 = objPDU.Encode(&(m_impl->m_singleResponse->certID));
00096     CPKIFBufferPtr buffPtr;
00097     if(NULL != data1)
00098     {
00099         buffPtr = CPKIFBufferPtr(new CPKIFBuffer(data1->data, data1->numocts));
00100         delete data1;
00101     }
00102 
00103     //CPKIFCertIDPtr tmpCID(new CPKIFCertID(m_impl->m_singleResponse->certID));
00104     CPKIFCertIDPtr tmpCID(new CPKIFCertID(buffPtr));
00105     m_impl->m_certID = tmpCID;
00106 
00107     CACASNWRAPPER_CREATE(CertStatus, objPDU2);
00108     data1 = objPDU2.Encode(&(m_impl->m_singleResponse->certStatus));
00109     CPKIFBufferPtr buffPtr2;
00110     if(NULL != data1)
00111     {
00112         buffPtr2 = CPKIFBufferPtr(new CPKIFBuffer(data1->data, data1->numocts));
00113         delete data1;
00114     }
00115     //CPKIFOCSPCertStatusPtr tmpCS(new CPKIFOCSPCertStatus(m_impl->m_singleResponse->certStatus));
00116     CPKIFOCSPCertStatusPtr tmpCS(new CPKIFOCSPCertStatus(buffPtr2));
00117     m_impl->m_certStatus = tmpCS;
00118 
00119     CPKIFTimePtr tmpTU(new CPKIFTime(m_impl->m_singleResponse->thisUpdate));
00120     m_impl->m_thisUpdate = tmpTU;
00121 
00122     if(m_impl->m_singleResponse->m.nextUpdatePresent)
00123     {
00124         CPKIFTimePtr tmpNU(new CPKIFTime(m_impl->m_singleResponse->nextUpdate));
00125         m_impl->m_nextUpdate = tmpNU;
00126     }
00127     
00128     if(m_impl->m_singleResponse->m.singleExtensionsPresent)
00129     {
00130         m_impl->populateExtensionsVector(m_impl->m_singleResponse);
00131     }
00132 
00133     
00134 }
00142 CPKIFSingleResponse::~CPKIFSingleResponse(void)
00143 {
00144     LOG_STRING_DEBUG("CPKIFSingleResponse::~CPKIFSingleResponse(void)", TOOLKIT_OCSP_ASN, 0, this);
00145 
00146     delete m_impl;
00147     m_impl = NULL;
00148 }
00159 void CPKIFSingleResponseImpl::populateExtensionsVector(
00161     CPKIFASNWrapper<SingleResponse>& sr)
00162 {
00163     LOG_STRING_DEBUG("CPKIFSingleResponse::populateExtensionsVector(SingleResponse& sr)", TOOLKIT_OCSP_ASN, 0, this);
00164 
00165     m_exts.clear();
00166 
00167     if(0 == sr->m.singleExtensionsPresent)
00168         return;
00169 
00170     // get the one and only extension mediator, with any additions an app might
00171     // have made
00172     CPKIFX509ExtensionMediator2 * mediator = CPKIFX509ExtensionMediator2::GetInstance();
00173     m_this->IPKIFHasExtensions::GetExtensions (mediator, m_exts);
00174 }
00175 
00183 bool CPKIFSingleResponse::AreThereAnyUnprocessedCriticalExtensions(
00186     std::vector<CPKIFX509ExtensionPtr>& processedExts)
00187 {
00188     LOG_STRING_DEBUG("CPKIFSingleResponse::AreThereAnyUnprocessedCriticalExtensions(std::vector<CPKIFX509ExtensionPtr>& processedExts)", TOOLKIT_OCSP_ASN, 0, this);
00189 
00190     std::vector<CPKIFX509ExtensionPtr>::iterator pos;
00191     std::vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00192     std::vector<CPKIFX509ExtensionPtr>::iterator processedEnd = processedExts.end();
00193     ExtensionsMatch em;
00194 //  int count = processedExts.size();
00195     for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00196     {
00197         em.SetRHS(*pos);
00198         if((*pos)->isCritical() && processedEnd == find_if(processedExts.begin(), processedExts.end(), em))
00199             return true;
00200     }
00201 
00202     return false;
00203 }
00204 
00205 //certID
00213 CPKIFCertIDPtr CPKIFSingleResponse::GetCertID() const
00214 {
00215     return m_impl->m_certID;
00216 }
00224 void CPKIFSingleResponse::SetCertID(
00226     CPKIFCertIDPtr& ci)
00227 {
00228     m_impl->m_certID = ci;
00229 }
00230 
00231 //certStatus
00239 CPKIFOCSPCertStatusPtr CPKIFSingleResponse::GetCertStatus() const
00240 {
00241     return m_impl->m_certStatus;
00242 }
00250 void CPKIFSingleResponse::SetCertStatus(
00252     CPKIFOCSPCertStatusPtr& cs)
00253 {
00254     m_impl->m_certStatus = cs;
00255 }
00256 
00257 //thisUpdate
00265 CPKIFTimePtr CPKIFSingleResponse::GetThisUpdate() const
00266 {
00267     return m_impl->m_thisUpdate;
00268 }
00276 void CPKIFSingleResponse::SetThisUpdate(
00278     CPKIFTimePtr& str)
00279 {
00280     m_impl->m_thisUpdate = str;
00281 }
00282 
00283 //nextUpdate
00291 CPKIFTimePtr CPKIFSingleResponse::GetNextUpdate() const
00292 {
00293     return m_impl->m_nextUpdate;
00294 }
00302 void CPKIFSingleResponse::SetNextUpdate(
00304     CPKIFTimePtr& str)
00305 {
00306     m_impl->m_nextUpdate = str;
00307 }
00308 
00316 void CPKIFSingleResponse::GetEncodedExtensions (
00318     CPKIFBufferPtr& buf) 
00319 {
00320     try 
00321     {
00322         if (m_impl->m_singleResponse->m.singleExtensionsPresent)
00323         {
00324             CACASNWRAPPER_CREATE(CACX509V3Extensions, extsWrapper);
00325             ASN1OpenType *data = extsWrapper.Encode (&m_impl->m_singleResponse->singleExtensions);
00326             CPKIFBufferPtr tmp(new CPKIFBuffer(data->data, data->numocts));
00327             buf = tmp;
00328             delete data;
00329             return;
00330         }
00331     }
00332     catch (... /*CPKIFException& e*/)
00333     {
00334         // How do we want to handle the exception?
00335     }
00336 
00337     CPKIFBufferPtr nullExt;
00338     buf = nullExt;
00339 }
00340 
00341 //this function is for use when retrieving an extension for which no proper class exists
00352 void CPKIFSingleResponse::GetExtensionByOID(
00354     const CPKIFOID& oid,
00356     CPKIFX509ExtensionPtr& ref)
00357 {
00358     if(m_impl->m_exts.empty() && 0 != m_impl->m_singleResponse->singleExtensions.count)
00359         m_impl->populateExtensionsVector(m_impl->m_singleResponse);
00360 
00361     vector<CPKIFX509ExtensionPtr>::iterator pos;
00362     vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00363     for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00364     {
00365         if(oid == (*pos)->oid())
00366         {
00367             ref = *pos;
00368             return;
00369         }
00370     }       
00371 }
00372 

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