00001 00009 #ifndef __ENCRYPTEDDATA_H__ 00010 #define __ENCRYPTEDDATA_H__ 00011 00012 #include "PKIFCMSDLL.h" 00013 #include "IPKIFHasAttributes.h" 00014 #include "PKIFMediators.h" 00015 #include "components.h" 00016 #include "OID.h" 00017 #include "ContentType.h" 00018 00019 FD_LIST_PTR(CPKIFAttribute); 00020 FD_SMART_PTR(CPKIFKeyMaterial); 00021 FD_SMART_PTR(CPKIFBuffer); 00022 FD_SMART_PTR(CPKIFEncryptedContentInfo); 00023 00033 class PKIFCMS_API CPKIFEncryptedData : public IPKIFHasAttributes, public CPKIFContentType 00034 { 00035 friend struct CPKIFEncryptedDataImpl; 00036 public: 00037 //this enum matches the contents of the underlying 00038 //objective enum and must continue to do so 00039 typedef enum { 00040 CMSv0 = 0, 00041 CMSv2 = 2, 00042 } CMSVersion; 00043 00044 //***************************************************************************** 00045 // constructors and destructors 00046 //***************************************************************************** 00047 CPKIFEncryptedData(); 00048 virtual ~CPKIFEncryptedData(); 00049 00050 //***************************************************************************** 00051 // field manipulation functions 00052 // EncryptedData ::= SEQUENCE 00053 // { 00054 // version CMSVersion, 00055 // encryptedContentInfo EncryptedContentInfo, 00056 // unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL 00057 // } 00058 // EncryptedContentInfo ::= SEQUENCE 00059 // { 00060 // contentType ContentType, 00061 // contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier, 00062 // encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL 00063 // } 00064 // EncryptedContent ::= OCTET STRING 00065 // UnprotectedAttributes ::= SET SIZE (1..MAX) OF Attribute 00066 00067 //***************************************************************************** 00068 //version (required) - automatically set based on message contents 00069 // (see private CalculateAndSetVersion function) 00070 CMSVersion GetVersion() const; 00071 00072 //encryptedContentInfo (required) 00073 void SetDataToEncrypt(CPKIFEncryptedContentInfoPtr& buf); 00074 CPKIFEncryptedContentInfoPtr GetEncryptedData() const; 00075 00076 //unprotectedAttrs (optional) 00077 void AddUnprotectedAttribute(CPKIFAttributePtr& attr); 00078 00079 void GetUnprotectedAttributes(CPKIFAttributeList& ual); 00080 00081 // Implementation of virtual IPKIFHasAttributes::GetEncodedUnprotectedAttributes 00082 void GetEncodedUnprotectedAttributes (CPKIFBufferPtr& buf); 00083 00084 // The following function is a workaround bc it's not wise to use 00085 // static members inside of template functions. This should be revisited 00086 // after a more "correct" approach has been decided. 00087 void _GetUnprotectedAttributes(std::vector<CPKIFAttributePtr> attrVector); 00088 00089 template <class T> boost::shared_ptr<T> GetUnprotectedAttribute(); 00090 00091 void ClearContent(bool removeMediatorAssociations = true); 00092 00093 void SetKeyMaterial(CPKIFKeyMaterialPtr& key); 00094 00095 //***************************************************************************** 00096 // encode and decode functions 00097 //***************************************************************************** 00098 CPKIFBufferPtr Encode(); //also performs encryption 00099 void Decode(CPKIFBufferPtr& buf); //does not perform decryption 00100 00101 //***************************************************************************** 00102 // miscellaneous functions 00103 //***************************************************************************** 00104 CPKIFBufferPtr Decrypt(); 00105 void GetAddedUnprotectedAttributes(std::vector<CPKIFAttributePtr>& attr); 00106 00107 void AddMediator(IPKIFMediatorPtr& m); 00108 IPKIFMediatorPtr GetMediator(); 00109 00110 private: 00111 00113 CPKIFEncryptedData(const CPKIFEncryptedData& ext);//added 8/21/2004 00115 CPKIFEncryptedData& operator=(const CPKIFEncryptedData& rhs); //added 8/21/2004 00116 00117 enum {thisComponent=TOOLKIT_MESSAGE_ENVELOPED_DATA}; 00118 00119 struct CPKIFEncryptedDataImpl *m_impl; 00120 }; 00121 DECLARE_SMART_POINTERS(CPKIFEncryptedData); 00122 00131 template <class T> boost::shared_ptr<T> CPKIFEncryptedData::GetUnprotectedAttribute() 00132 00133 { 00134 //XXX*** Read the comments below and fix this please 00135 00136 std::vector<CPKIFAttributePtr> attrVector; 00137 // The following function is a workaround bc it's not wise to use 00138 // static members inside of template functions. This should be revisited 00139 // after a more "correct" approach has been decided. 00140 _GetUnprotectedAttributes(attrVector); 00141 00142 //GetUnprotectedAttributes (IPKIFParseAttributes* m, attrVector); 00143 00144 CPKIFStringPtr oidStr(new std::string(T::extOID)); 00145 CPKIFOID oid(oidStr); 00146 00147 CPKIFAttribute* p = NULL; 00148 CPKIFAttributeList::iterator pos; 00149 CPKIFAttributeList::iterator end = attrVector.end(); 00150 for(pos = attrVector.begin(); pos != end; ++pos) 00151 { 00152 p = &(*(*pos)); 00153 if(oid == (*pos)->GetOID() && NULL != dynamic_cast<T*>(p)) 00154 { 00155 return *((boost::shared_ptr<T>*)&(*pos)); 00156 } 00157 } 00158 00159 boost::shared_ptr<T> nullExt; 00160 return nullExt; 00161 } 00162 00163 #endif //__ENCRYPTEDDATA_H__ 00164