CRLEntry.cpp
Go to the documentation of this file.00001
00009 #include "CRLEntry.h"
00010 #include "OID.h"
00011 #include "Buffer.h"
00012
00013 #include "ASN1Helper.h"
00014 #include "PKIX1Implicit88.h"
00015 #include "PKIX1Explicit88.h"
00016
00017 #include "PKIFTime.h"
00018 #include "X509Extension.h"
00019 #include "PKIFX509Extensions2.h"
00020 #include "ExtensionsMatch.h"
00021
00022 using namespace std;
00023
00025
00026 struct CPKIFCRLEntryImpl
00027 {
00028 CPKIFCRLEntryImpl();
00029 void populateExtensionsVector();
00030
00031
00032 CPKIFASNWrapper<CACX509V3RevokedCerts> m_crlEntry;
00033
00034 CPKIFStringPtr m_serialNum;
00035 CPKIFTimePtr m_revDate;
00036 std::vector<CPKIFX509ExtensionPtr> m_exts;
00037 CPKIFBufferPtr m_encodedExt;
00038 CPKIFBufferPtr m_encodedEntry;
00039
00040 CPKIFCRLEntry * m_this;
00041 };
00049 CPKIFCRLEntryImpl::CPKIFCRLEntryImpl()
00050 :m_crlEntry(BEREncCACX509V3RevokedCerts, BERDecCACX509V3RevokedCerts)
00051 {
00052 }
00053
00064 void CPKIFCRLEntryImpl::populateExtensionsVector()
00065 {
00066
00067 if(!m_exts.empty())
00068 return;
00069
00070
00071 if(!m_crlEntry->m.crlEntryExtensionsPresent)
00072 {
00073 m_exts.clear();
00074 return;
00075 }
00076
00077
00078
00079 CPKIFX509ExtensionMediator2 * mediator = CPKIFX509ExtensionMediator2::GetInstance();
00080 m_this->IPKIFHasExtensions::GetExtensions (mediator, m_exts);
00081 }
00082
00084
00093 void CPKIFCRLEntry::GetEncodedExtensions (
00095 CPKIFBufferPtr& buf)
00096 {
00097 if(m_impl->m_encodedExt) {
00098 buf = m_impl->m_encodedExt;
00099 return;
00100 } else {
00101 if(!m_impl->m_crlEntry->m.crlEntryExtensionsPresent) {
00102 buf = CPKIFBufferPtr();
00103 } else {
00104 try {
00105 CACASNWRAPPER_CREATE(CACX509V3Extensions,objPDU);
00106 ASN1OpenType *data = objPDU.Encode(&m_impl->m_crlEntry->crlEntryExtensions);
00107 CPKIFBufferPtr tmp(new CPKIFBuffer(data->data,data->numocts));
00108 m_impl->m_encodedExt = tmp;
00109 buf = tmp;
00110 delete data;
00111 } catch( ... ) {
00112
00113 buf = CPKIFBufferPtr();
00114 throw;
00115 }
00116 }
00117 }
00118
00119 }
00120
00128 const char* CPKIFCRLEntry::SerialNumber() const
00129 {
00130 if(m_impl->m_serialNum != NULL)
00131 return m_impl->m_serialNum->c_str();
00132 else
00133 return NULL;
00134 }
00142 const CPKIFTimePtr CPKIFCRLEntry::RevocationDate() const
00143 {
00144 return m_impl->m_revDate;
00145 }
00154 CPKIFCRLEntry::CPKIFCRLEntry(
00156 const CPKIFBufferPtr & buf)
00157 :m_impl(new CPKIFCRLEntryImpl)
00158 {
00159 try {
00160 m_impl->m_crlEntry.Decode(buf->GetBuffer(),buf->GetLength());
00161 m_impl->m_this = this;
00162 CACX509V3RevokedCerts * ext = m_impl->m_crlEntry.data();
00163
00164 CPKIFStringPtr tmpBuf(new std::string(ext->userCertificate));
00165 m_impl->m_serialNum = tmpBuf;
00166
00167 CPKIFTimePtr tmpTime;
00168 if(ext->revocationDate.t == T_CACX509V3Time_utcTime)
00169 {
00170 tmpTime = CPKIFTimePtr(new CPKIFTime(ext->revocationDate.u.utcTime, UTCTIME));
00171 }
00172 else
00173 {
00174 tmpTime = CPKIFTimePtr(new CPKIFTime(ext->revocationDate.u.generalTime, GENERALIZEDTIME));
00175 }
00176 m_impl->m_revDate = tmpTime;
00177 m_impl->m_encodedEntry = buf;
00178 }catch(...){
00179
00180 throw;
00181 }
00182
00183
00184 }
00192 CPKIFCRLEntry::CPKIFCRLEntry()
00193 :m_impl(new CPKIFCRLEntryImpl)
00194 {
00195 m_impl->m_this = this;
00196 }
00204 CPKIFCRLEntry::~CPKIFCRLEntry()
00205 {
00206 if(m_impl) {
00207 delete m_impl;
00208 m_impl = 0;
00209 }
00210 }
00211
00212
00221 bool CPKIFCRLEntry::AreThereAnyUnprocessedCriticalExtensions(
00223 std::vector<CPKIFX509ExtensionPtr>& processedExts)
00224 {
00225
00226
00227
00228
00229
00230
00231 std::vector<CPKIFX509ExtensionPtr>::iterator pos;
00232 std::vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00233 std::vector<CPKIFX509ExtensionPtr>::iterator processedEnd = processedExts.end();
00234 ExtensionsMatch em;
00235 size_t count = processedExts.size();
00236 for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00237 {
00238 em.SetRHS(*pos);
00239 if((*pos)->isCritical() && processedEnd == find_if(processedExts.begin(), processedExts.end(), em))
00240 return true;
00241 }
00242
00243 return false;
00244 }
00253 void CPKIFCRLEntry::GetExtensionByOID(
00255 const CPKIFOID& oid,
00257 CPKIFX509ExtensionPtr& ref)
00258 {
00259 if(m_impl->m_exts.empty() && m_impl->m_crlEntry->m.crlEntryExtensionsPresent)
00260 m_impl->populateExtensionsVector();
00261
00262 vector<CPKIFX509ExtensionPtr>::iterator pos;
00263 vector<CPKIFX509ExtensionPtr>::iterator end = m_impl->m_exts.end();
00264 for(pos = m_impl->m_exts.begin(); pos != end; ++pos)
00265 {
00266 if(oid == (*pos)->oid())
00267 {
00268 ref = *pos;
00269 return;
00270 }
00271 }
00272 }
00273