ResponseData.cpp

Go to the documentation of this file.
00001 
00009 #include "ResponseData.h"
00010 #include "ResponderID.h"
00011 #include "PKIFTime.h"
00012 #include "SingleResponse.h"
00013 #include "X509Extension.h"
00014 #include "Buffer.h"
00015 #include "OID.h"
00016 
00017 #include "ASN1Helper.h"
00018 #include "OCSP.h"
00019 
00020 #include "PKIFX509Extensions2.h"
00021 #include "ToolkitUtils.h"
00022 #include "components.h"
00023 #include "ExtensionsMatch.h"
00024 #include "ASN1Helper.h"
00025 
00026 #include <iterator>
00027 using namespace std;
00028 
00030 struct CPKIFResponseDataImpl
00031 {
00039     CPKIFResponseDataImpl ();
00040     int m_version;
00041     CPKIFResponderIDPtr m_responderID;
00042     CPKIFTimePtr m_producedAt;
00043     CPKIFSingleResponseList m_responses;
00044 
00045     CPKIFASNWrapper<ResponseData> m_responseData;
00046     std::vector<CPKIFX509ExtensionPtr> m_exts;
00047     void populateExtensionsVector(CPKIFASNWrapper<ResponseData>& rd);
00048 
00049     CPKIFBufferPtr m_thatWhichWasSigned;
00050 
00051     CPKIFResponseData * m_this;
00052 };
00054 
00055 
00063 CPKIFResponseDataImpl::CPKIFResponseDataImpl ()
00064 : m_responseData(BEREncResponseData, BERDecResponseData)
00065 {
00066 }
00067 
00075 CPKIFResponseData::CPKIFResponseData(void)
00076     :m_impl (new CPKIFResponseDataImpl)
00077 {
00078     LOG_STRING_DEBUG("CPKIFResponseData::CPKIFResponseData(void)", TOOLKIT_OCSP_ASN, 0, this);
00079 
00080     //added 7/25/2004
00081     m_impl->m_version = 0;
00082     m_impl->m_this = this;
00083 }
00092 CPKIFResponseData::CPKIFResponseData(
00094     const CPKIFBufferPtr& responseData)
00095     :m_impl (new CPKIFResponseDataImpl)
00096 {
00097     LOG_STRING_DEBUG("CPKIFResponseData::CPKIFResponseData(const CPKIFBufferPtr& responseData)", TOOLKIT_OCSP_ASN, 0, this);
00098 
00099     CPKIFBufferPtr bp(new CPKIFBuffer(*responseData));
00100     m_impl->m_this = this;
00101     m_impl->m_thatWhichWasSigned = bp;
00102 
00103     m_impl->m_responseData.Decode(responseData->GetBuffer(), responseData->GetLength());
00104 
00105     m_impl->m_version = m_impl->m_responseData->version;
00106 
00107     CACASNWRAPPER_CREATE(ResponderID, objPDU);
00108     ASN1OpenType* data1 = objPDU.Encode(&(m_impl->m_responseData->responderID));
00109     CPKIFBufferPtr buffPtr;
00110     if(NULL != data1)
00111     {
00112         buffPtr = CPKIFBufferPtr(new CPKIFBuffer(data1->data, data1->numocts));
00113         delete data1;
00114     }
00115     CPKIFResponderIDPtr tmpRID(new CPKIFResponderID(buffPtr));
00116     m_impl->m_responderID = tmpRID;
00117 
00118     CPKIFTimePtr tmpStr(new CPKIFTime(m_impl->m_responseData->producedAt));
00119     m_impl->m_producedAt = tmpStr;
00120 
00121     m_impl->populateExtensionsVector(m_impl->m_responseData);
00122 
00123     if(m_impl->m_responseData->responses.count > 0)
00124     {
00125         DListNode* cur = m_impl->m_responseData->responses.head; 
00126         while(NULL != cur)
00127         {
00128             ASN1OpenType* openType = (ASN1OpenType*)cur->data;
00129 
00130             CPKIFBufferPtr tmpBuffer(new CPKIFBuffer(openType->data, openType->numocts));
00131 
00132             CPKIFSingleResponsePtr tmpReq(new CPKIFSingleResponse(tmpBuffer));
00133 
00134             m_impl->m_responses.push_back(tmpReq);
00135     
00136             cur = cur->next;
00137         }
00138     }
00139 }
00147 CPKIFResponseData::~CPKIFResponseData(void)
00148 {
00149     LOG_STRING_DEBUG("CPKIFResponseData::~CPKIFResponseData(void)", TOOLKIT_OCSP_ASN, 0, this);
00150 
00151     delete m_impl;
00152     m_impl = NULL;
00153 }
00164 void CPKIFResponseDataImpl::populateExtensionsVector(
00166     CPKIFASNWrapper<ResponseData>& rd)
00167 {
00168     LOG_STRING_DEBUG("CPKIFResponseData::populateExtensionsVector(CPKIFASNWrapper<ResponseData>& rd)", TOOLKIT_OCSP_ASN, 0, this);
00169 
00170     m_exts.clear();
00171     if(NULL == rd.data() || 0 == rd->m.responseExtensionsPresent)
00172         return;
00173 
00174     // get the one and only extension mediator, with any additions an app might
00175     // have made
00176     CPKIFX509ExtensionMediator2 * mediator = CPKIFX509ExtensionMediator2::GetInstance();
00177     m_this->IPKIFHasExtensions::GetExtensions (mediator, m_exts);
00178 }
00186 bool CPKIFResponseData::AreThereAnyUnprocessedCriticalExtensions(
00189     std::vector<CPKIFX509ExtensionPtr>& processedExts)
00190 {
00191     LOG_STRING_DEBUG("CPKIFResponseData::AreThereAnyUnprocessedCriticalExtensions(std::vector<CPKIFX509ExtensionPtr>& processedExts)", TOOLKIT_OCSP_ASN, 0, this);
00192 
00193     std::vector<CPKIFX509ExtensionPtr>::iterator pos;
00194     std::vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00195     std::vector<CPKIFX509ExtensionPtr>::iterator processedEnd = processedExts.end();
00196     ExtensionsMatch em;
00197     size_t count = processedExts.size();
00198     for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00199     {
00200         em.SetRHS(*pos);
00201         if((*pos)->isCritical() && processedEnd == find_if(processedExts.begin(), processedExts.end(), em))
00202             return true;
00203     }
00204 
00205     return false;
00206 }
00207 
00210 //@b Interface: External
00211 //
00212 //This function is used to get an extension contained by a ResponseData object.
00213 //
00214 //@return None
00215 //*/
00216 //void CPKIFResponseData::GetExtension(
00217 //  //![in] Reference to a CPKIFOID containing the object identifier for the type of extension to retrieve
00218 //  const CPKIFOID& oid, 
00219 //  //![out] Reference to a smart pointer to a CPKIFX509Extension object to receive a pointer to the requested
00220 //  //!extension object (or NULL if the requested extension is not present)
00221 //  CPKIFX509ExtensionPtr& ref)
00222 //{
00223 //  LOG_STRING_DEBUG("CPKIFResponseData::GetExtension(const CPKIFOID& oid, CPKIFX509ExtensionPtr& ref)", TOOLKIT_OCSP_ASN, 0, this);
00224 //
00225 //  vector<CPKIFX509ExtensionPtr>::iterator pos;
00226 //  vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00227 //  for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00228 //  {
00229 //      if(oid == (*pos)->oid())
00230 //      {
00231 //          ref = *pos;
00232 //          return;
00233 //      }
00234 //  }       
00235 //}
00236 
00237 //version
00245 int CPKIFResponseData::GetVersion() const
00246 {
00247     return m_impl->m_version;
00248 }
00249 
00250 //responderID
00251 
00259 CPKIFResponderIDPtr CPKIFResponseData::GetResponderID() const
00260 {
00261     return m_impl->m_responderID;
00262 }
00270 void CPKIFResponseData::SetResponderID(
00272     CPKIFResponderIDPtr& rid)
00273 {
00274     m_impl->m_responderID = rid;
00275 }
00276 
00277 //producedAt
00285 CPKIFTimePtr CPKIFResponseData::GetProducedAt() const
00286 {
00287     return m_impl->m_producedAt;
00288 }
00296 void CPKIFResponseData::SetProducedAt(
00298     CPKIFTimePtr& pa)
00299 {
00300     m_impl->m_producedAt = pa;
00301 }
00302 
00303 //responses
00311 void CPKIFResponseData::GetResponses(
00314     CPKIFSingleResponseList& srs)
00315 {
00316     copy(m_impl->m_responses.begin(), m_impl->m_responses.end(), back_inserter(srs));
00317 }
00325 void CPKIFResponseData::AddResponse(
00328     CPKIFSingleResponsePtr& sr)
00329 {
00330     m_impl->m_responses.push_back(sr);
00331 }
00339 CPKIFBufferPtr CPKIFResponseData::toBeSigned()
00340 {
00341     return m_impl->m_thatWhichWasSigned;
00342 }
00343 
00351 void CPKIFResponseData::GetEncodedExtensions (
00353     CPKIFBufferPtr& buf) 
00354 {
00355     try 
00356     {
00357         if (m_impl->m_responseData->m.responseExtensionsPresent)
00358         {
00359             CACASNWRAPPER_CREATE(CACX509V3Extensions, extsWrapper);
00360             ASN1OpenType *data = extsWrapper.Encode (&m_impl->m_responseData->responseExtensions);
00361             CPKIFBufferPtr tmp(new CPKIFBuffer(data->data, data->numocts));
00362             buf = tmp;
00363             delete data;
00364             return;
00365         }
00366     }
00367     catch (... /*CPKIFException& e*/)
00368     {
00369         // How do we want to handle the exception?
00370     }
00371 
00372     CPKIFBufferPtr nullExt;
00373     buf = nullExt;
00374 }
00375 
00376 //this function is for use when retrieving an extension for which no proper class exists
00387 void CPKIFResponseData::GetExtensionByOID(
00389     const CPKIFOID& oid,
00391     CPKIFX509ExtensionPtr& ref)
00392 {
00393     if(m_impl->m_exts.empty() && 0 != m_impl->m_responseData->responseExtensions.count)
00394         m_impl->populateExtensionsVector(m_impl->m_responseData);
00395 
00396     vector<CPKIFX509ExtensionPtr>::iterator pos;
00397     vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00398     for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00399     {
00400         if(oid == (*pos)->oid())
00401         {
00402             ref = *pos;
00403             return;
00404         }
00405     }       
00406 }
00407 

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