OCSPResponse.cpp

Go to the documentation of this file.
00001 
00009 #include "OCSPResponse.h"
00010 #include "ResponseBytes.h"
00011 #include "Buffer.h"
00012 #include "OID.h"
00013 
00014 #include "OCSPException.h"
00015 #include "ToolkitUtils.h"
00016 //#include "PKIFCMS.h" //for NEW_NODE, etc. macros
00017 #include "PKIFX509Extensions2.h"
00018 #include "PKIFCommonErrors.h"
00019 #include "ASN1Helper.h"
00020 #include "OCSP.h"
00021 using namespace std;
00022 
00024 struct CPKIFOCSPResponseImpl
00025 {
00026 
00027     OCSPResponseStatus m_status;
00028     CPKIFResponseBytesPtr m_responseBytes;
00029 
00030     CPKIFBufferPtr m_encOCSPResponse;
00031 
00032     CPKIFASNWrapper<OCSPResponse>* m_ocspResp;
00033 
00034     void ClearAllMembers();
00035     void MakeOCSPResponse();
00036     void FreeOCSPResponse();
00037 };
00039 
00047 CPKIFOCSPResponse::CPKIFOCSPResponse(void)
00048     :m_impl (new CPKIFOCSPResponseImpl)
00049 {
00050     LOG_STRING_DEBUG("CPKIFOCSPResponse::CPKIFOCSPResponse(void)", TOOLKIT_OCSP_ASN, 0, this);
00051 
00052     m_impl->m_ocspResp = NULL;
00053 }
00061 CPKIFOCSPResponse::~CPKIFOCSPResponse(void)
00062 {
00063     LOG_STRING_DEBUG("CPKIFOCSPResponse::~CPKIFOCSPResponse(void)", TOOLKIT_OCSP_ASN, 0, this);
00064 
00065     if(NULL != m_impl->m_ocspResp)
00066         delete m_impl->m_ocspResp;
00067 
00068     delete m_impl;
00069     m_impl = NULL;
00070 }
00071 
00072 //responseStatus
00090 int CPKIFOCSPResponse::GetResponseStatus() const
00091 {
00092     return m_impl->m_status;
00093 }
00104 void CPKIFOCSPResponse::SetResponseStatus(
00107     int status)
00108 {
00109     m_impl->m_status = status;
00110 }
00111 
00112 //responseBytes
00120 CPKIFResponseBytesPtr CPKIFOCSPResponse::GetResponseBytes() const
00121 {
00122     if(m_impl->m_responseBytes == (CPKIFOID*)NULL && NULL != m_impl->m_ocspResp && NULL != (*m_impl->m_ocspResp).data() && (*m_impl->m_ocspResp)->m.responseBytesPresent)
00123     {
00124         LOG_STRING_DEBUG("CPKIFOCSPResponse::GetResponseBytes()", TOOLKIT_OCSP_ASN, 0, this);
00125 
00126         CPKIFOID tmpOID((*m_impl->m_ocspResp)->responseBytes.responseType.subid, (*m_impl->m_ocspResp)->responseBytes.responseType.numids);
00127         CPKIFBuffer tmpBuffer((*m_impl->m_ocspResp)->responseBytes.response.data, (*m_impl->m_ocspResp)->responseBytes.response.numocts);
00128         //CPKIFResponseBytes* tmp = new CPKIFResponseBytes((*m_impl->m_ocspResp)->responseBytes);
00129         CPKIFResponseBytes* tmp = new CPKIFResponseBytes(tmpOID, tmpBuffer);
00130         CPKIFResponseBytesPtr tmpRef(tmp); 
00131 
00132         CPKIFOCSPResponse* nonConst = const_cast<CPKIFOCSPResponse*>(this);
00133         nonConst->m_impl->m_responseBytes = tmpRef;
00134     }
00135 
00136     return m_impl->m_responseBytes;
00137 }
00145 void CPKIFOCSPResponse::SetResponseBytes(
00148     CPKIFResponseBytesPtr& respBytes)
00149 {
00150     m_impl->m_responseBytes = respBytes;
00151 }
00160 CPKIFBufferPtr CPKIFOCSPResponse::Encoded() const 
00161 {
00162     return m_impl->m_encOCSPResponse;
00163 }
00174 void CPKIFOCSPResponse::Decode(
00176     CPKIFBufferPtr& msg)
00177 {
00178     LOG_STRING_DEBUG("CPKIFOCSPResponse::Decode(CPKIFBufferPtr& msg)", TOOLKIT_OCSP_ASN, 0, this);
00179 
00180     m_impl->ClearAllMembers();
00181 
00182     //if the input is empty - fail now
00183     if(msg == (CPKIFBuffer*)NULL || 0 == msg->GetLength())
00184     {
00185         throw CPKIFOCSPException(TOOLKIT_OCSP_ASN, COMMON_INVALID_INPUT);
00186     }
00187 
00188     m_impl->MakeOCSPResponse();
00189 
00190     try
00191     {
00192         m_impl->m_encOCSPResponse = msg;
00193 
00194         //otherwise try to parse it into the m_tsr member
00195         (*m_impl->m_ocspResp).Decode(msg->GetBuffer(), msg->GetLength());
00196         m_impl->m_status = (*m_impl->m_ocspResp)->responseStatus;
00197     }
00198     catch(CPKIFException&)
00199     {
00200         //delete e;
00201         //changed error code 3/2/2004
00202         throw CPKIFOCSPException(TOOLKIT_OCSP_ASN, ASN1_DECODE_ERROR);
00203     }
00204 }
00212 void CPKIFOCSPResponseImpl::ClearAllMembers()
00213 {
00214     LOG_STRING_DEBUG("PKIFOCSPMemoryHelper::PKIFOCSPMemoryHelper()", TOOLKIT_OCSP_ASN, 0, this);
00215 }
00223 void CPKIFOCSPResponseImpl::MakeOCSPResponse()
00224 {
00225     LOG_STRING_DEBUG("PKIFOCSPMemoryHelper::PKIFOCSPMemoryHelper()", TOOLKIT_OCSP_ASN, 0, this);
00226 
00227     FreeOCSPResponse();
00228     m_ocspResp = new CPKIFASNWrapper<OCSPResponse>( BEREncOCSPResponse, BERDecOCSPResponse );
00229 }
00237 void CPKIFOCSPResponseImpl::FreeOCSPResponse()
00238 {
00239     LOG_STRING_DEBUG("PKIFOCSPMemoryHelper::PKIFOCSPMemoryHelper()", TOOLKIT_OCSP_ASN, 0, this);
00240 
00241     if(NULL != m_ocspResp)
00242         delete m_ocspResp;
00243     m_ocspResp = NULL;
00244 }

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