ExtendedKeyUsage.cpp

Go to the documentation of this file.
00001 
00009 #include "ExtendedKeyUsage.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 <iostream>
00018 
00019 using namespace std;
00020 
00022 
00023 struct CPKIFExtendedKeyUsageImpl
00024 {
00025     vector<CPKIFOIDPtr> m_keyPurposeIDs;
00026     CPKIFBufferPtr m_value;
00027     bool m_extModified;
00028 };
00029 
00031 
00032 char CPKIFExtendedKeyUsage::extOID[] =          "2.5.29.37";
00033 
00041 CPKIFExtendedKeyUsage::CPKIFExtendedKeyUsage()
00042   :m_impl (new CPKIFExtendedKeyUsageImpl)
00043 {
00044 }
00055 //CPKIFExtendedKeyUsage::CPKIFExtendedKeyUsage(
00056 //  //! [in] Reference to an internal structure representation of the extension containing 
00057 //  // information used to construct the object
00058 //  const CACX509V3Extension& ext)
00059 //  : CPKIFX509Extension(ext), m_impl (new CPKIFExtendedKeyUsageImpl)
00060 //{
00061 //  CACASNWRAPPER_CREATE(CACX509V3ExtKeyUsageSyntax, objPDU);
00062 //  CACX509V3ExtKeyUsageSyntax* eku = objPDU.Decode(ext.extnValue.data, ext.extnValue.numocts);
00063 //  
00064 //  DListNode* cur = eku->head;
00065 //  for(unsigned int ii = 0; ii < eku->count; ++ii)
00066 //  {
00067 //      CPKIFOIDPtr tmpGN(new CPKIFOID((*(ASN1OBJID*)cur->data).subid, (*(ASN1OBJID*)cur->data).numids));
00068 //      m_impl->m_keyPurposeIDs.push_back(tmpGN);
00069 //
00070 //      cur = cur->next;
00071 //  }
00072 //}
00073 
00084 CPKIFExtendedKeyUsage::CPKIFExtendedKeyUsage(const bool& criticality, const CPKIFBufferPtr& ext)
00085   : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFExtendedKeyUsageImpl)
00086 {
00087     CACASNWRAPPER_CREATE(CACX509V3ExtKeyUsageSyntax, objPDU);
00088     CACX509V3ExtKeyUsageSyntax* eku = objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00089     
00090     DListNode* cur = eku->head;
00091     for(unsigned int ii = 0; ii < eku->count; ++ii)
00092     {
00093         CPKIFOIDPtr tmpGN(new CPKIFOID((*(ASN1OBJID*)cur->data).subid, (*(ASN1OBJID*)cur->data).numids));
00094         m_impl->m_keyPurposeIDs.push_back(tmpGN);
00095 
00096         cur = cur->next;
00097     }
00098 
00099     m_impl->m_value = ext;
00100     m_impl->m_extModified = false;
00101 }
00102 
00110 CPKIFExtendedKeyUsage::~CPKIFExtendedKeyUsage()
00111 {
00112     if(m_impl)
00113     {
00114         delete m_impl;
00115         m_impl = 0;
00116     }
00117 }
00126 const CPKIFOIDPtr CPKIFExtendedKeyUsage::oid() const
00127 {
00128     //added static variable for copying instead of string creation each call
00129     static CPKIFOID staticOID(extOID);
00130     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00131     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00132     return tmp;
00133 }
00134 
00150 void CPKIFExtendedKeyUsage::KeyPurposeIDs(
00153     vector<CPKIFOIDPtr>& keyPurposeIDs)
00154 {
00155     keyPurposeIDs.clear();
00156 
00157     vector<CPKIFOIDPtr>::const_iterator pos;
00158     vector<CPKIFOIDPtr>::const_iterator end = m_impl->m_keyPurposeIDs.end();
00159     for(pos = m_impl->m_keyPurposeIDs.begin(); pos != end; ++pos)
00160     {
00161         keyPurposeIDs.push_back(*pos);
00162     }
00163 }
00171 CPKIFBufferPtr CPKIFExtendedKeyUsage::value() const 
00172 {
00173     CPKIFBufferPtr rv = m_impl->m_value;
00174     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00175     {
00176         //XXX ENCODE HERE and set rv if necessary 
00177     }
00178 
00179     return rv;
00180 }
00181 
00182 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFExtendedKeyUsagePtr & extension)
00183 {
00184     return operator<<(os,*extension);
00185 }
00186 
00187 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFExtendedKeyUsage & extension)
00188 {
00189     bool output = false;
00190     vector<CPKIFOIDPtr> ekus;
00191     // cast off const-ness for this getter
00192     const_cast<CPKIFExtendedKeyUsage &>(extension).KeyPurposeIDs(ekus);
00193 
00194     vector<CPKIFOIDPtr>::iterator pos;
00195     vector<CPKIFOIDPtr>::iterator end = ekus.end();
00196     for(pos = ekus.begin(); pos != end; ++pos)
00197     {
00198         if(output) os << endl;
00199         output = true;
00200         if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.1"))
00201         {
00202             os << "Web server authentication ";
00203         }
00204         else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.2"))
00205         {
00206             os << "Web client authentication ";
00207         }
00208         else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.3"))
00209         {
00210             os << "Code signing ";
00211         }
00212         else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.4"))
00213         {
00214             os << "E-mail protection ";
00215         }
00216         else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.8"))
00217         {
00218             os << "Timestamp Signing ";
00219         }
00220         else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.9"))
00221         {
00222             os << "OCSP Signing ";
00223         }
00224         else
00225         {
00226             os << (*pos)->ToString();
00227         }
00228     }
00229     return os;
00230 }
00231 

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